示例#1
1
func initPage(title string, uri string, size_x int, size_y int) {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle(title)
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)

	webview := webkit.NewWebView()
	webview.LoadUri(uri)
	swin.Add(webview)

	vbox.Add(swin)

	window.Add(vbox)
	window.SetSizeRequest(size_x, size_y)
	window.ShowAll()

	proxy := os.Getenv("HTTP_PROXY")
	if len(proxy) > 0 {
		soup_uri := webkit.SoupUri(proxy)
		webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
		soup_uri.Free()
	}
	gtk.Main()
}
示例#2
0
文件: arrow.go 项目: mattn/go-gtk
func main() {
	gtk.Init(&os.Args)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Arrow Buttons")
	window.Connect("destroy", gtk.MainQuit)

	box := gtk.NewHBox(false, 0)
	box.Show()
	window.Add(box)

	up := createArrowButton(gtk.ARROW_UP, gtk.SHADOW_IN)
	down := createArrowButton(gtk.ARROW_DOWN, gtk.SHADOW_OUT)
	left := createArrowButton(gtk.ARROW_LEFT, gtk.SHADOW_ETCHED_IN)
	right := createArrowButton(gtk.ARROW_RIGHT, gtk.SHADOW_ETCHED_OUT)

	box.PackStart(up, false, false, 3)
	box.PackStart(down, false, false, 3)
	box.PackStart(left, false, false, 3)
	box.PackStart(right, false, false, 3)

	up.Clicked(func() { println("↑") })
	down.Clicked(func() { println("↓") })
	left.Clicked(func() { println("←") })
	right.Clicked(func() { println("→") })

	window.Show()
	gtk.Main()
}
示例#3
0
文件: main.go 项目: kch42/biomed
func (g *GUI) Init() {
	g.biomes = ReadDefaultBiomes()

	g.window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	g.window.SetTitle("biomed")

	g.accel = gtk.NewAccelGroup()
	g.window.AddAccelGroup(g.accel)

	menubar := g.mkMenuBar()
	vbox := gtk.NewVBox(false, 0)
	vbox.PackStart(menubar, false, false, 0)

	hbox := gtk.NewHBox(false, 0)

	g.mapw = NewMapWidget(GUICallbacks{g.reportError, g.updateInfo, g.setBusy}, MkBiomeLookup(g.biomes))
	hbox.PackStart(g.mapw.DArea(), true, true, 3)

	sidebar := g.mkSidebar()
	hbox.PackEnd(sidebar, false, false, 3)

	vbox.PackStart(hbox, true, true, 0)

	g.statusbar = gtk.NewStatusbar()
	g.statusContext = g.statusbar.GetContextId("mapinfo")
	vbox.PackEnd(g.statusbar, false, false, 0)

	g.window.Add(vbox)
	g.window.SetDefaultSize(800, 600)

	g.window.Connect("destroy", g.exitApp)

	g.setTool(NewFillTool())
}
示例#4
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("Hello GTK+Go world!")
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		gtk.MainQuit()
	}, "foo")
	vbox := gtk.NewVBox(false, 1)
	button := gtk.NewButtonWithLabel("Hello world!")
	button.SetTooltipMarkup("Say Hello World to everybody!")
	button.Clicked(func() {
		messagedialog := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			"Hello!")
		messagedialog.Response(func() {
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	vbox.PackStart(button, false, false, 0)
	window.Add(vbox)
	window.SetSizeRequest(300, 50)
	window.ShowAll()
	gtk.Main()
}
示例#5
0
文件: iconview.go 项目: pocke/go-gtk
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK Icon View")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.NewScrolledWindow(nil, nil)

	store := gtk.NewListStore(gdkpixbuf.GetType(), glib.G_TYPE_STRING)
	iconview := gtk.NewIconViewWithModel(store)
	iconview.SetPixbufColumn(0)
	iconview.SetTextColumn(1)
	swin.Add(iconview)

	gtk.StockListIDs().ForEach(func(d unsafe.Pointer, v interface{}) {
		id := glib.GPtrToString(d)
		var iter gtk.TreeIter
		store.Append(&iter)
		store.Set(&iter,
			gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").GPixbuf,
			id)
	})

	window.Add(swin)
	window.SetSizeRequest(500, 200)
	window.ShowAll()

	gtk.Main()
}
示例#6
0
文件: display.go 项目: Khady/gomoku
func board_display() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("Gomoku")
	window.SetResizable(false)
	window.Connect("destroy", gtk.MainQuit)

	player = 1
	game = Gomoku{make([]int, 361), true, false, false, 1, [2]int{10, 10}, 0}

	vbox := gtk.NewVBox(false, 1)

	menu_bar(vbox)
	configure_board(vbox)
	status_bar(vbox)

	hintx, hinty, lastx, lasty = -1, -1, -1, -1

	go calc_hint()

	window.Add(vbox)
	window.SetSizeRequest(WIDTH+40, HEIGHT+50)
	window.ShowAll()
	gtk.Main()
}
示例#7
0
文件: gui.go 项目: zchee/gouv
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Clock")
	vbox := gtk.NewVBox(false, 1)
	label := gtk.NewLabel("")
	vbox.Add(label)
	window.Add(vbox)
	window.SetDefaultSize(300, 20)
	window.ShowAll()

	timer, _ := uv.TimerInit(nil)
	timer.Start(func(h *uv.Handle, status int) {
		label.SetLabel(fmt.Sprintf("%v", time.Now()))
	}, 1000, 1000)

	idle, _ := uv.IdleInit(nil)
	idle.Start(func(h *uv.Handle, status int) {
		gtk.MainIterationDo(false)
	})

	window.Connect("destroy", func() {
		timer.Close(nil)
		idle.Close(nil)
	})

	uv.DefaultLoop().Run()
}
示例#8
0
文件: dmxd.go 项目: uvgroovy/dmx
func CreateGuiController() *GuiController {
	guiController := &GuiController{}
	guiController.buttons = make([]*gtk.Button, 0)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.SetIconName("gtk-dialog-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		fmt.Println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	buttonsBox := gtk.NewHBox(false, 1)

	black := gdk.NewColorRGB(0, 0, 0)

	for i := 0; i < 8; i++ {
		button := gtk.NewButtonWithLabel(fmt.Sprint(i))

		button.ModifyBG(gtk.STATE_NORMAL, black)
		guiController.buttons = append(guiController.buttons, button)
		buttonsBox.Add(button)
	}

	window.Add(buttonsBox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()

	return guiController
}
示例#9
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK Notebook")
	window.Connect("destroy", gtk.MainQuit)

	notebook := gtk.NewNotebook()
	for n := 1; n <= 10; n++ {
		page := gtk.NewFrame("demo" + strconv.Itoa(n))
		notebook.AppendPage(page, gtk.NewLabel("demo"+strconv.Itoa(n)))

		vbox := gtk.NewHBox(false, 1)

		prev := gtk.NewButtonWithLabel("go prev")
		prev.Clicked(func() {
			notebook.PrevPage()
		})
		vbox.Add(prev)

		next := gtk.NewButtonWithLabel("go next")
		next.Clicked(func() {
			notebook.NextPage()
		})
		vbox.Add(next)

		page.Add(vbox)
	}

	window.Add(notebook)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
示例#10
0
文件: listview.go 项目: arip33/go-gtk
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK Stock Icons")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.NewScrolledWindow(nil, nil)

	store := gtk.NewListStore(glib.G_TYPE_STRING, glib.G_TYPE_BOOL, gdkpixbuf.GetGdkPixbufType())
	treeview := gtk.NewTreeView()
	swin.Add(treeview)

	treeview.SetModel(store)
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("name", gtk.NewCellRendererText(), "text", 0))
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("check", gtk.NewCellRendererToggle(), "active", 1))
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("icon", gtk.NewCellRendererPixbuf(), "pixbuf", 2))
	n := 0
	gtk.StockListIDs().ForEach(func(d interface{}, v interface{}) {
		id := glib.GPtrToString(d)
		var iter gtk.TreeIter
		store.Append(&iter)
		store.Set(&iter, id, (n == 1), gtk.NewImage().RenderIcon(id, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf)
		n = 1 - n
	})

	window.Add(swin)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
示例#11
0
func main() {
	mc := memcache.New("127.0.0.1:11211")

	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("memcachedclient")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	swin := gtk.NewScrolledWindow(nil, nil)
	textview := gtk.NewTextView()
	textview.SetEditable(false)
	textview.SetCursorVisible(false)
	textview.ModifyFontEasy("monospace 12")
	swin.Add(textview)
	vbox.Add(swin)

	buffer := textview.GetBuffer()

	input := gtk.NewEntry()
	input.SetEditable(true)
	vbox.PackEnd(input, false, false, 0)

	tag := buffer.CreateTag("red", map[string]string{"foreground": "#FF0000"})
	input.Connect("activate", func() {
		var iter gtk.TextIter
		tokens := strings.SplitN(input.GetText(), " ", 3)
		if len(tokens) == 2 && strings.ToUpper(tokens[0]) == "GET" {
			if t, err := mc.Get(tokens[1]); err == nil {
				buffer.GetEndIter(&iter)
				buffer.Insert(&iter, string(t.Value)+"\n")
			} else {
				buffer.InsertWithTag(&iter, err.Error()+"\n", tag)
			}
			input.SetText("")
		} else if len(tokens) == 3 && strings.ToUpper(tokens[0]) == "SET" {
			if err := mc.Set(
				&memcache.Item{
					Key:   tokens[1],
					Value: []byte(tokens[2]),
				}); err == nil {
				buffer.GetEndIter(&iter)
				buffer.InsertWithTag(&iter, "OK\n", tag)
			} else {
				buffer.InsertWithTag(&iter, err.Error()+"\n", tag)
			}
			input.SetText("")
		}
	})
	input.GrabFocus()

	window.Add(vbox)
	window.SetSizeRequest(300, 500)
	window.ShowAll()
	gtk.Main()
}
示例#12
0
文件: app.go 项目: kisom/socialgopher
func accountWindow() {
	// window settings
	window_account := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window_account.SetPosition(gtk.WIN_POS_CENTER)
	window_account.SetTitle("Add Account")

	// main container
	container_main := gtk.NewVBox(false, 10)
	container_user := gtk.NewHBox(false, 0)
	container_pass := gtk.NewHBox(false, 0)
	container_buttons := gtk.NewHBox(false, 5)
	container_main.SetBorderWidth(10)

	// username
	user_label := gtk.NewLabel("Username")
	user_entry := gtk.NewEntry()

	// password
	pass_label := gtk.NewLabel("Password")
	pass_entry := gtk.NewEntry()
	pass_entry.SetVisibility(false)

	// login and cancel buttons
	button_login := gtk.NewButtonWithLabel("Add")
	button_cancel := gtk.NewButtonWithLabel("Cancel")

	// login
	button_login.Clicked(func() {
		username := user_entry.GetText()
		password := pass_entry.GetText()
		profile, err := CreateProfile(username, password)
		if err == nil && profile != nil {
			println("[*] Login successful")
			window_account.Destroy()
		}
	})

	// cancel
	button_cancel.Clicked(func() {
		window_account.Destroy()
	})

	// add elements to containers
	container_buttons.Add(button_login)
	container_buttons.Add(button_cancel)
	container_user.PackStart(user_label, false, false, 20)
	container_user.PackEnd(user_entry, true, true, 1)
	container_pass.PackStart(pass_label, false, false, 20)
	container_pass.PackEnd(pass_entry, true, true, 1)
	container_main.PackStart(container_user, false, false, 1)
	container_main.PackStart(container_pass, false, false, 1)
	container_main.PackStart(container_buttons, false, false, 1)

	window_account.Add(container_main)
	window_account.SetSizeRequest(350, 150)
	window_account.SetResizable(false)
	window_account.ShowAll()
}
示例#13
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("webkit")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	entry := gtk.NewEntry()
	entry.SetText("http://golang.org/")
	vbox.PackStart(entry, false, false, 0)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)

	webview := webkit.NewWebView()
	webview.Connect("load-committed", func() {
		entry.SetText(webview.GetUri())
	})
	swin.Add(webview)

	vbox.Add(swin)

	entry.Connect("activate", func() {
		webview.LoadUri(entry.GetText())
	})
	button := gtk.NewButtonWithLabel("load String")
	button.Clicked(func() {
		webview.LoadString("hello Go GTK!", "text/plain", "utf-8", ".")
	})
	vbox.PackStart(button, false, false, 0)

	button = gtk.NewButtonWithLabel("load HTML String")
	button.Clicked(func() {
		webview.LoadHtmlString(HTML_STRING, ".")
	})
	vbox.PackStart(button, false, false, 0)

	button = gtk.NewButtonWithLabel("Google Maps")
	button.Clicked(func() {
		webview.LoadHtmlString(MAP_EMBED, ".")
	})
	vbox.PackStart(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()

	proxy := os.Getenv("HTTP_PROXY")
	if len(proxy) > 0 {
		soup_uri := webkit.SoupUri(proxy)
		webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
		soup_uri.Free()
	}
	entry.Emit("activate")
	gtk.Main()
}
示例#14
0
文件: action.go 项目: hauke96/go-gtk
func CreateWindow() *gtk.Window {
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetDefaultSize(700, 300)
	vbox := gtk.NewVBox(false, 1)
	CreateMenuAndToolbar(window, vbox)
	CreateActivatableDemo(vbox)
	window.Add(vbox)
	return window
}
示例#15
0
文件: window.go 项目: davidamin/VanGo
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("Hello world!")
	window.SetIconName("Hello go!")
	window.Connect("destroy", gtk.MainQuit)
	window.SetSizeRequest(800, 800)
	window.ShowAll()
	gtk.Main()
}
示例#16
0
文件: main.go 项目: vsannikov/mgc
func main() {

	FreeConsole()

	gtk.Init(nil)

	screenHeight := gdk.ScreenHeight()
	screenWidth := gdk.ScreenWidth()

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("mgc")
	window.SetIconName("gtk-about")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})

	vbox := gtk.NewVBox(false, 0)

	menubar := gtk.NewMenuBar()
	vbox.PackStart(menubar, false, false, 0)

	menu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(menu)
	submenu := gtk.NewMenu()
	menu.SetSubmenu(submenu)

	menuitem := gtk.NewMenuItemWithMnemonic("E_xit")
	menuitem.Connect("activate", func() {
		gtk.MainQuit()
	})
	submenu.Append(menuitem)

	hpaned := gtk.NewHPaned()

	leftFrame := gtk.NewFrame("")
	rightFrame := gtk.NewFrame("")

	leftLabel := gtk.NewLabel("Left")
	rightLabel := gtk.NewLabel("Right")

	leftFrame.Add(leftLabel)
	rightFrame.Add(rightLabel)

	hpaned.Pack1(leftFrame, true, false)
	hpaned.Pack2(rightFrame, true, false)
	vbox.Add(hpaned)

	window.Add(vbox)

	window.SetSizeRequest(screenWidth/4*3, screenHeight/4*3)
	window.ShowAll()

	gtk.Main()
}
func main() {
	gtk.Init(nil)
	win := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	win.SetTitle("Goodbye, World!")
	win.SetSizeRequest(300, 200)
	win.Connect("destroy", gtk.MainQuit)
	button := gtk.NewButtonWithLabel("Goodbye, World!")
	win.Add(button)
	button.Connect("clicked", gtk.MainQuit)
	win.ShowAll()
	gtk.Main()
}
示例#18
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("SourceView")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)
	sourcebuffer := gsv.NewSourceBufferWithLanguage(gsv.SourceLanguageManagerGetDefault().GetLanguage("cpp"))
	sourceview := gsv.NewSourceViewWithBuffer(sourcebuffer)

	var start gtk.TextIter
	sourcebuffer.GetStartIter(&start)
	sourcebuffer.BeginNotUndoableAction()
	sourcebuffer.Insert(&start, `#include <iostream>
template<class T>
struct foo_base {
  T operator+(T const &rhs) const {
    T tmp(static_cast<T const &>(*this));
    tmp += rhs;
    return tmp;
  }
};

class foo : public foo_base<foo> {
private:
  int v;
public:
  foo(int v) : v(v) {}
  foo &operator+=(foo const &rhs){
    this->v += rhs.v;
    return *this;
  }
  operator int() { return v; }
};

int main(void) {
  foo a(1), b(2);
  a += b;
  std::cout << (int)a << std::endl;
}
`)
	sourcebuffer.EndNotUndoableAction()

	swin.Add(sourceview)

	window.Add(swin)
	window.SetSizeRequest(400, 300)
	window.ShowAll()

	gtk.Main()
}
示例#19
0
文件: dnd.go 项目: JessonChan/go-gtk
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK DrawingArea")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(true, 0)
	vbox.SetBorderWidth(5)

	targets := []gtk.TargetEntry{
		{"text/uri-list", 0, 0},
		{"STRING", 0, 1},
		{"text/plain", 0, 2},
	}
	dest := gtk.NewLabel("drop me file")
	dest.DragDestSet(
		gtk.DEST_DEFAULT_MOTION|
			gtk.DEST_DEFAULT_HIGHLIGHT|
			gtk.DEST_DEFAULT_DROP,
		targets,
		gdk.ACTION_COPY)
	dest.DragDestAddUriTargets()
	dest.Connect("drag-data-received", func(ctx *glib.CallbackContext) {
		sdata := gtk.SelectionDataFromNative(unsafe.Pointer(ctx.Args(3)))
		if sdata != nil {
			a := (*[2000]uint8)(sdata.GetData())
			files := strings.Split(string(a[0:sdata.GetLength()-1]), "\n")
			for i := range files {
				filename, _, _ := glib.FilenameFromUri(files[i])
				files[i] = filename
			}
			dialog := gtk.NewMessageDialog(
				window,
				gtk.DIALOG_MODAL,
				gtk.MESSAGE_INFO,
				gtk.BUTTONS_OK,
				strings.Join(files, "\n"))
			dialog.SetTitle("D&D")
			dialog.Response(func() {
				dialog.Destroy()
			})
			dialog.Run()
		}
	})
	vbox.Add(dest)

	window.Add(vbox)

	window.SetSizeRequest(300, 100)
	window.ShowAll()
	gtk.Main()
}
示例#20
0
文件: treeview.go 项目: arip33/go-gtk
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK Folder View")
	window.Connect("destroy", gtk.MainQuit)

	swin := gtk.NewScrolledWindow(nil, nil)

	store := gtk.NewTreeStore(gdkpixbuf.GetGdkPixbufType(), glib.G_TYPE_STRING)
	treeview := gtk.NewTreeView()
	swin.Add(treeview)

	treeview.SetModel(store.ToTreeModel())
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("pixbuf", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("text", gtk.NewCellRendererText(), "text", 1))

	for n := 1; n <= 10; n++ {
		var iter1, iter2, iter3 gtk.TreeIter
		store.Append(&iter1, nil)
		store.Set(&iter1, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "Folder"+strconv.Itoa(n))
		store.Append(&iter2, &iter1)
		store.Set(&iter2, gtk.NewImage().RenderIcon(gtk.STOCK_DIRECTORY, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "SubFolder"+strconv.Itoa(n))
		store.Append(&iter3, &iter2)
		store.Set(&iter3, gtk.NewImage().RenderIcon(gtk.STOCK_FILE, gtk.ICON_SIZE_SMALL_TOOLBAR, "").Pixbuf, "File"+strconv.Itoa(n))
	}

	treeview.Connect("row_activated", func() {
		var path *gtk.TreePath
		var column *gtk.TreeViewColumn
		treeview.GetCursor(&path, &column)
		mes := "TreePath is: " + path.String()
		dialog := gtk.NewMessageDialog(
			treeview.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			mes)
		dialog.SetTitle("TreePath")
		dialog.Response(func() {
			dialog.Destroy()
		})
		dialog.Run()
	})

	window.Add(swin)
	window.SetSizeRequest(400, 200)
	window.ShowAll()

	gtk.Main()
}
示例#21
0
func (g *Gui) buildGUI() {
	g.MainWindow = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	g.MainWindow.SetPosition(gtk.WIN_POS_CENTER)
	g.MainWindow.SetTitle("Gunnify")
	g.MainWindow.SetIconName("gtk-dialog-info")
	g.MainWindow.Connect("destroy", func(ctx *glib.CallbackContext) {
		println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")
	g.MainWindow.SetSizeRequest(600, 300)
	vbox := gtk.NewVBox(false, 0)
	g.buildList(vbox)
	g.MainWindow.Add(vbox)
}
示例#22
0
func main() {
	gtk.Init(&os.Args)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetSizeRequest(150, 50)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		gtk.MainQuit()
	}, nil)

	label := gtk.NewLabel("hello world")
	window.Add(label)

	window.ShowAll()
	gtk.Main()
}
示例#23
0
文件: web.go 项目: jnb666/gogp
// StartBrowser launches a web browser with given url and size
func StartBrowser(url string, width, height int) {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("gogp")
	window.Connect("destroy", gtk.MainQuit)
	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)
	webview := webkit.NewWebView()
	swin.Add(webview)
	window.Add(swin)
	window.SetSizeRequest(width, height)
	webview.LoadUri(url)
	window.ShowAll()
	gtk.Main()
}
示例#24
0
func main() {
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		fmt.Println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	//--------------------------------------------------------
	// GtkHBox
	//--------------------------------------------------------
	fixed := gtk.NewFixed()

	//--------------------------------------------------------
	// GtkSpinButton
	//--------------------------------------------------------
	spinbutton1 := gtk.NewSpinButtonWithRange(1.0, 10.0, 1.0)
	spinbutton1.SetDigits(3)
	spinbutton1.Spin(gtk.SPIN_STEP_FORWARD, 7.0)
	fixed.Put(spinbutton1, 40, 50)

	spinbutton1.OnValueChanged(func() {
		val := spinbutton1.GetValueAsInt()
		fval := spinbutton1.GetValue()
		fmt.Println("SpinButton changed, new value: " + strconv.Itoa(val) + " | " + strconv.FormatFloat(fval, 'f', 2, 64))
		min, max := spinbutton1.GetRange()
		fmt.Println("Range: " + strconv.FormatFloat(min, 'f', 2, 64) + " " + strconv.FormatFloat(max, 'f', 2, 64))
		fmt.Println("Digits: " + strconv.Itoa(int(spinbutton1.GetDigits())))
	})

	adjustment := gtk.NewAdjustment(2.0, 1.0, 8.0, 2.0, 0.0, 0.0)
	spinbutton2 := gtk.NewSpinButton(adjustment, 1.0, 1)
	spinbutton2.SetRange(0.0, 20.0)
	spinbutton2.SetValue(18.0)
	spinbutton2.SetIncrements(2.0, 4.0)
	fixed.Put(spinbutton2, 150, 50)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(fixed)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
示例#25
0
文件: mert.go 项目: nlamirault/mert
func runGUI(argv []string) {
	conf, err := config.Load(getConfigurationFile())
	if err != nil {
		log.Printf("[WARN] No configuration file or invalid configuration. Use default settings")
		conf = config.New()
	}

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle(getApplicationTitle())
	terminal := vte3.NewTerminal()
	widget := terminal.VteToGtk()

	keyboardEventsChan := make(chan *events.KeyPressEvent)

	// Events
	window.Connect("destroy", gtk.MainQuit)
	widget.Connect("child-exited", gtk.MainQuit)
	window.Connect("key-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		kpe := events.KeyPressEvent{int(kev.Keyval), 0}
		if (gdk.ModifierType(kev.State) & gdk.CONTROL_MASK) != 0 {
			kpe.Modifier = gdk.CONTROL_MASK
		}
		keyboardEventsChan <- &kpe
	})
	widget.Connect("decrease-font-size", func() {
		log.Printf("[DEBUG] Font -------")
	})
	widget.Connect("increase-font-size", func() {
		log.Printf("[DEBUG] Font +++++++")
	})

	window.Add(widget)
	window.SetSizeRequest(defaultWinWidth, defaultWinHeight)
	window.ShowAll()

	configure(terminal, conf)

	terminal.Fork(argv)

	// Handlers
	go events.KeyboardHandler(keyboardEventsChan, terminal)

	gtk.Main()
}
示例#26
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("We love Expander")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(true, 0)
	vbox.SetBorderWidth(5)
	expander := gtk.NewExpander("dan the ...")
	expander.Add(gtk.NewLabel("404 contents not found"))
	vbox.PackStart(expander, false, false, 0)

	window.Add(vbox)
	window.ShowAll()

	gtk.Main()
}
示例#27
0
文件: dsp.go 项目: ntwyman/go-dsp
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("DSP Playground")

	window.Connect("delete-event", deleteEvent)
	window.Connect("destroy", destroyEvent)
	vbox := gtk.NewVBox(true, 0)
	vbox.SetBorderWidth(5)

	vbox.Add(dsp_gtk.NewGraph())
	window.Add(vbox)
	window.SetSizeRequest(1010, 300)
	window.ShowAll()

	gtk.Main()
}
示例#28
0
// ShortTime creates a GTK fullscreen window for the shorttime clients.
// No username/password required, only click 'start' button to log in
func ShortTime(client string, minutes int) (user string) {
	// Inital window configuration
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	defer window.Destroy()
	window.Fullscreen()
	window.SetKeepAbove(true)
	window.SetTitle("Mycel Login")

	// Build GUI
	frame := gtk.NewFrame("Logg deg på " + client)
	frame.SetLabelAlign(0.5, 0.5)
	var imageLoader *gdkpixbuf.Loader
	imageLoader, _ = gdkpixbuf.NewLoaderWithMimeType("image/png")
	imageLoader.Write(logo_png())
	imageLoader.Close()
	logo := gtk.NewImageFromPixbuf(imageLoader.GetPixbuf())
	info := gtk.NewLabel("")
	info.SetMarkup("<span foreground='red'>Dette er en korttidsmaskin\nMaks " +
		strconv.Itoa(minutes) + " minutter!</span>")
	button := gtk.NewButtonWithLabel("\nStart\n")

	vbox := gtk.NewVBox(false, 20)
	vbox.SetBorderWidth(20)
	vbox.Add(logo)
	vbox.Add(info)
	vbox.Add(button)

	frame.Add(vbox)

	center := gtk.NewAlignment(0.5, 0.5, 0, 0)
	center.Add(frame)
	window.Add(center)

	// Connect GUI event signals to function callbacks
	button.Connect("clicked", func() {
		gtk.MainQuit()
	})
	window.Connect("delete-event", func() bool {
		return true
	})

	window.ShowAll()
	gtk.Main()
	return "Anonym"
}
示例#29
0
func main() {
	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GTK Go!")
	window.SetIconName("textview")
	window.Connect("destroy", gtk.MainQuit)

	textview := gtk.NewTextView()
	textview.SetEditable(true)
	textview.SetCursorVisible(true)
	var iter gtk.TextIter
	buffer := textview.GetBuffer()

	buffer.GetStartIter(&iter)
	buffer.Insert(&iter, "Hello ")

	tag := buffer.CreateTag("bold", map[string]string{"background": "#FF0000", "weight": "700"})
	buffer.InsertWithTag(&iter, "Google!", tag)

	u := "http://www.google.com"
	tag.SetData("tag-name", unsafe.Pointer(&u))
	textview.Connect("event-after", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		if ev := *(**gdk.EventAny)(unsafe.Pointer(&arg)); ev.Type != gdk.BUTTON_RELEASE {
			return
		}
		ev := *(**gdk.EventButton)(unsafe.Pointer(&arg))
		var iter gtk.TextIter
		textview.GetIterAtLocation(&iter, int(ev.X), int(ev.Y))
		tags := iter.GetTags()
		for n := uint(0); n < tags.Length(); n++ {
			vv := tags.NthData(n)
			tag := gtk.NewTextTagFromPointer(vv)
			u := *(*string)(tag.GetData("tag-name"))
			fmt.Println(u)
		}
	})

	window.Add(textview)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
示例#30
0
文件: gui.go 项目: pocke/password
func guiMain(ch <-chan Accounts) {
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(&os.Args)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("password")
	window.Connect("destroy", gtk.MainQuit)

	entry := gtk.NewEntry()

	store := gtk.NewListStore(glib.G_TYPE_STRING)
	treeview := gtk.NewTreeView()
	treeview.SetModel(store)
	// treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("icon", gtk.NewCellRendererPixbuf(), "pixbuf", 0))
	treeview.AppendColumn(gtk.NewTreeViewColumnWithAttributes("name", gtk.NewCellRendererText(), "text", 0))

	go func() {
		for accounts := range ch {
			gthread(func() {
				store.Clear()
				for _, a := range accounts {
					var iter gtk.TreeIter
					store.Append(&iter)
					store.Set(&iter, 0, a.Name)
				}
			})
		}
	}()

	swin := gtk.NewScrolledWindow(nil, nil)
	swin.Add(treeview)

	vbox := gtk.NewVBox(false, 0)
	vbox.PackStart(entry, false, false, 1)
	vbox.PackStart(swin, true, true, 0)

	window.Add(vbox)

	window.SetSizeRequest(460, 640)
	window.SetResizable(false)
	window.ShowAll()
}