本文整理汇总了Golang中github.com/agl/go-gtk/gtk.GtkWidget类的典型用法代码示例。如果您正苦于以下问题:Golang GtkWidget类的具体用法?Golang GtkWidget怎么用?Golang GtkWidget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GtkWidget类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: configureWidget
func configureWidget(w *gtk.GtkWidget, b widgetBase) {
width := -1
if b.width != 0 {
width = b.width
}
height := -1
if b.height != 0 {
height = b.height
}
if width != -1 || height != -1 {
w.SetSizeRequest(width, height)
}
w.SetSensitive(!b.insensitive)
if color := b.Foreground(); color != 0 {
w.ModifyFG(gtk.GTK_STATE_NORMAL, toColor(color))
}
if color := b.Background(); color != 0 {
w.ModifyBG(gtk.GTK_STATE_NORMAL, toColor(color))
}
if len(b.font) != 0 {
w.ModifyFontEasy(b.font)
}
}
示例2: handle
func (ui *GTKUI) handle(action interface{}) {
switch action := action.(type) {
case Reset:
ui.widgets = make(map[string]gtk.WidgetLike)
ui.entries = make(map[string]*gtk.GtkEntry)
ui.textViews = make(map[string]*gtk.GtkTextView)
ui.combos = make(map[string]*gtk.GtkComboBoxText)
ui.radioGroups = make(map[string]int)
ui.checks = make(map[string]*gtk.GtkCheckButton)
ui.radioGroups = make(map[string]int)
ui.calendars = make(map[string]*gtk.GtkCalendar)
ui.spinButtons = make(map[string]*gtk.GtkSpinButton)
if ui.topWidget != nil {
ui.window.Remove(ui.topWidget)
ui.topWidget = nil
}
ui.topWidget = ui.newWidget(action.root)
ui.window.Add(ui.topWidget)
ui.window.ShowAll()
case Append:
box := ui.getWidget(action.name).(gtk.BoxLike)
for _, child := range action.children {
widget := ui.newWidget(child)
box.PackStart(widget, child.Expand(), child.Fill(), child.Padding())
}
ui.window.ShowAll()
case AddToBox:
box := ui.getWidget(action.box).(gtk.BoxLike)
widget := ui.newWidget(action.child)
box.PackStart(widget, action.child.Expand(), action.child.Fill(), action.child.Padding())
box.ReorderChild(widget, action.pos)
ui.window.ShowAll()
case SetChild:
bin := gtk.GtkBin{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
for _, child := range bin.GetChildren() {
child.Destroy()
}
bin.Add(ui.newWidget(action.child))
ui.window.ShowAll()
case SetBoxContents:
box := gtk.GtkBox{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
for _, child := range box.GetChildren() {
child.Destroy()
}
child := action.child
widget := ui.newWidget(child)
box.PackStart(widget, child.Expand(), child.Fill(), child.Padding())
ui.window.ShowAll()
case SetBackground:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.OverrideBackgroundColor(gtk.GTK_STATE_FLAG_NORMAL, toColor(action.color))
case Sensitive:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.SetSensitive(action.sensitive)
case StartSpinner:
widget := gtk.GtkSpinner{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.Start()
case StopSpinner:
widget := gtk.GtkSpinner{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.Stop()
case SetText:
widget := gtk.GtkLabel{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.SetText(action.text)
case SetButtonText:
widget := gtk.GtkButton{gtk.GtkBin{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}}
widget.SetLabel(action.text)
case SetEntry:
widget := ui.getWidget(action.name).(gtk.TextInputLike)
widget.SetText(action.text)
case SetTextView:
widget := gtk.GtkTextView{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
buffer := gtk.TextBuffer(gtk.TextTagTable())
buffer.SetText(action.text)
widget.SetBuffer(buffer)
case ScrollTextViewToEnd:
widget := gtk.GtkTextView{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
mark := widget.GetBuffer().GetMark("insert")
widget.ScrollToMark(mark, 0.0, true, 0, 1)
case SetImage:
widget := gtk.GtkImage{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.SetFromPixbuf(action.image.Image())
case SetFocus:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.GrabFocus()
case Destroy:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.Destroy()
delete(ui.widgets, action.name)
case FileOpen:
fileAction := gtk.GTK_FILE_CHOOSER_ACTION_OPEN
button := gtk.GTK_STOCK_OPEN
if action.save {
fileAction = gtk.GTK_FILE_CHOOSER_ACTION_SAVE
button = gtk.GTK_STOCK_SAVE
}
dialog := gtk.FileChooserDialog(action.title, ui.window, fileAction, gtk.GTK_STOCK_CANCEL, int(gtk.GTK_RESPONSE_CANCEL), button, int(gtk.GTK_RESPONSE_ACCEPT))
if action.save {
if len(action.filename) > 0 {
dialog.SetCurrentName(action.filename)
//.........这里部分代码省略.........
示例3: configureWidget
func configureWidget(w *gtk.GtkWidget, b widgetBase) {
width := -1
if b.width != 0 {
width = b.width
}
height := -1
if b.height != 0 {
height = b.height
}
if width != -1 || height != -1 {
w.SetSizeRequest(width, height)
}
w.SetSensitive(!b.insensitive)
if color := b.Foreground(); color != 0 {
w.OverrideColor(gtk.GTK_STATE_FLAG_NORMAL, toColor(color))
}
if color := b.Background(); color != 0 {
w.OverrideBackgroundColor(gtk.GTK_STATE_FLAG_NORMAL, toColor(color))
}
if len(b.font) != 0 {
w.OverrideFont(b.font)
}
if b.hExpand {
w.SetHExpand(true)
}
if b.vExpand {
w.SetVExpand(true)
}
if b.margin > 0 {
w.SetMargin(b.margin)
}
if b.marginTop > 0 {
w.SetMarginTop(b.marginTop)
}
if b.marginBottom > 0 {
w.SetMarginBottom(b.marginBottom)
}
if b.marginLeft > 0 {
w.SetMarginLeft(b.marginLeft)
}
if b.vAlign != AlignNone {
w.SetVAlign(alignToGTK(b.vAlign))
}
if b.hAlign != AlignNone {
w.SetHAlign(alignToGTK(b.hAlign))
}
}
示例4: handle
func (ui *GTKUI) handle(action interface{}) {
switch action := action.(type) {
case Reset:
ui.widgets = make(map[string]gtk.WidgetLike)
ui.entries = make(map[string]*gtk.GtkEntry)
ui.textViews = make(map[string]*gtk.GtkTextView)
ui.combos = make(map[string]*gtk.GtkComboBox)
if ui.topWidget != nil {
ui.window.Remove(ui.topWidget)
ui.topWidget = nil
}
ui.topWidget = ui.newWidget(action.root)
ui.window.Add(ui.topWidget)
ui.window.ShowAll()
case Append:
box := ui.getWidget(action.name).(gtk.BoxLike)
for _, child := range action.children {
widget := ui.newWidget(child)
box.PackStart(widget, child.Expand(), child.Fill(), child.Padding())
}
ui.window.ShowAll()
case AddToBox:
box := ui.getWidget(action.box).(gtk.BoxLike)
widget := ui.newWidget(action.child)
box.PackStart(widget, action.child.Expand(), action.child.Fill(), action.child.Padding())
box.ReorderChild(widget, action.pos)
ui.window.ShowAll()
case SetChild:
bin := gtk.GtkBin{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
for _, child := range bin.GetChildren() {
child.Destroy()
}
bin.Add(ui.newWidget(action.child))
ui.window.ShowAll()
case SetBoxContents:
box := gtk.GtkBox{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
for _, child := range box.GetChildren() {
child.Destroy()
}
child := action.child
widget := ui.newWidget(child)
box.PackStart(widget, child.Expand(), child.Fill(), child.Padding())
ui.window.ShowAll()
case SetBackground:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.ModifyBG(gtk.GTK_STATE_NORMAL, toColor(action.color))
case Sensitive:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.SetSensitive(action.sensitive)
case StartSpinner:
widget := gtk.GtkSpinner{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.Start()
case StopSpinner:
widget := gtk.GtkSpinner{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.Stop()
case SetText:
widget := gtk.GtkLabel{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.SetText(action.text)
case SetTextView:
widget := gtk.GtkTextView{gtk.GtkContainer{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}}
buffer := gtk.TextBuffer(gtk.TextTagTable())
buffer.SetText(action.text)
widget.SetBuffer(buffer)
case SetImage:
widget := gtk.GtkImage{gtk.GtkWidget{ui.getWidget(action.name).ToNative()}}
widget.SetFromPixbuf(action.image.Image())
case SetFocus:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.GrabFocus()
case Destroy:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.Destroy()
case FileOpen:
fileAction := gtk.GTK_FILE_CHOOSER_ACTION_OPEN
but := gtk.GTK_STOCK_OPEN
if action.save {
fileAction = gtk.GTK_FILE_CHOOSER_ACTION_SAVE
but = gtk.GTK_STOCK_SAVE
}
dialog := gtk.FileChooserDialog(action.title, ui.window, fileAction, gtk.GTK_STOCK_CANCEL, int(gtk.GTK_RESPONSE_CANCEL), but, int(gtk.GTK_RESPONSE_ACCEPT))
switch gtk.GtkResponseType(dialog.Run()) {
case gtk.GTK_RESPONSE_ACCEPT:
ui.events <- OpenResult{
ok: true,
path: dialog.GetFilename(),
arg: action.arg,
}
default:
ui.events <- OpenResult{arg: action.arg}
}
dialog.Destroy()
case SetForeground:
widget := gtk.GtkWidget{ui.getWidget(action.name).ToNative()}
widget.ModifyFG(gtk.GTK_STATE_NORMAL, toColor(action.foreground))
case UIError:
case UIState:
// for testing.
default:
panic("unknown action")
}
//.........这里部分代码省略.........