当前位置: 首页>>代码示例>>Golang>>正文


Golang gtk.GtkBin类代码示例

本文整理汇总了Golang中github.com/agl/go-gtk/gtk.GtkBin的典型用法代码示例。如果您正苦于以下问题:Golang GtkBin类的具体用法?Golang GtkBin怎么用?Golang GtkBin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GtkBin类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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)
//.........这里部分代码省略.........
开发者ID:jwilkins,项目名称:pond,代码行数:101,代码来源:gtk.go

示例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.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")
	}
//.........这里部分代码省略.........
开发者ID:shpedoikal,项目名称:pond,代码行数:101,代码来源:gtk.go


注:本文中的github.com/agl/go-gtk/gtk.GtkBin类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。