Beispiel #1
0
// Locate frames on the window
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
func (this *UI) put_frames() {
	box_win := gtk.NewVBox(Homogeneous, Default_Spacing)
	if box_win == nil {
		panic("UI::put_frames() : VBox allocation Failed")
	}

	vpan1 := gtk.NewVPaned()
	if vpan1 == nil {
		panic("UI::put_frames() : VPaned allocation failed")
	}

	vpan1.Pack1(this.Calc_Frame, No_Resize, No_Shrink) // Calc : Top half
	hpan1 := gtk.NewHPaned()
	if hpan1 == nil {
		panic("UI::put_frames() : HPaned allocation failed")
	}

	hpan1.Pack1(this.Nums_Frame, No_Resize, No_Shrink) // Nums : Bottom-Left
	hpan1.Pack2(this.Oper_Frame, No_Resize, No_Shrink) // Oper : Bottom-Right

	vpan1.Pack2(hpan1, No_Resize, No_Shrink)
	box_win.Add(vpan1)

	if this.Win == nil {
		panic("UI::put_frames() : nil Window received")
	}
	// Place all Layout
	this.Win.Add(box_win)
	fmt.Println("UI::put_frames() done.")
}
Beispiel #2
0
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()
}
Beispiel #3
0
func main() {
	flag.Parse()

	common.SetDefaultGtkTheme()

	runtime.GOMAXPROCS(runtime.NumCPU())

	rclient = &remoton.Client{Prefix: "/remoton", TLSConfig: &tls.Config{}}
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL, syscall.SIGTERM)
	go func() {
		<-sigs
		chatSrv.Terminate()
		tunnelSrv.Terminate()
	}()
	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("REMOTON SUPPORT")
	window.Connect("destroy", func() {
		gtk.MainQuit()
		chatSrv.Terminate()
		tunnelSrv.Terminate()
	})
	window.SetIcon(common.GetIconGdkPixbuf())

	appLayout := gtk.NewVBox(false, 1)
	menu := gtk.NewMenuBar()
	appLayout.Add(menu)

	cascademenu := gtk.NewMenuItemWithMnemonic("_Help")
	menu.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	menuitem := gtk.NewMenuItemWithMnemonic("_About")
	menuitem.Connect("activate", func() {
		dialog := common.GtkAboutDialog()
		dialog.SetProgramName("Support Desktop")
		dialog.Run()
		dialog.Destroy()
	})
	submenu.Append(menuitem)

	hpaned := gtk.NewHPaned()
	appLayout.Add(hpaned)

	//---
	//CHAT
	//---
	frameChat := gtk.NewFrame("Chat")
	chatBox := gtk.NewVBox(false, 1)
	frameChat.Add(chatBox)

	swinChat := gtk.NewScrolledWindow(nil, nil)
	chatHistory := gtk.NewTextView()

	swinChat.Add(chatHistory)

	chatEntry := gtk.NewEntry()
	chatEntry.Connect("key-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		event := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		if event.Keyval == gdk.KEY_Return {
			msgToSend := chatEntry.GetText()
			chatSrv.Send(msgToSend)
			chatHistorySend(chatHistory, msgToSend)
			chatEntry.SetText("")
		}

	})
	chatSrv.OnRecv(func(msg string) {
		log.Println(msg)
		chatHistoryRecv(chatHistory, msg)
	})
	chatBox.Add(chatEntry)
	chatBox.Add(swinChat)

	//---
	//CONTROL
	//---
	frameControl := gtk.NewFrame("Control")
	controlBox := gtk.NewVBox(false, 1)
	frameControl.Add(controlBox)

	controlBox.Add(gtk.NewLabel("Machine ID"))
	machineIDEntry := gtk.NewEntry()
	controlBox.Add(machineIDEntry)

	controlBox.Add(gtk.NewLabel("Machine AUTH"))
	machineAuthEntry := gtk.NewEntry()
	controlBox.Add(machineAuthEntry)

	controlBox.Add(gtk.NewLabel("Server"))
	serverEntry := gtk.NewEntry()
	serverEntry.SetText("localhost:9934")
	if os.Getenv("REMOTON_SERVER") != "" {
		serverEntry.SetText(os.Getenv("REMOTON_SERVER"))
		serverEntry.SetEditable(false)
	}
	controlBox.Add(serverEntry)

	btnCert := gtk.NewFileChooserButton("Cert", gtk.FILE_CHOOSER_ACTION_OPEN)
	controlBox.Add(btnCert)
	btn := gtk.NewButtonWithLabel("Connect")
	started := false
	btn.Clicked(func() {
		if *insecure {
			rclient.TLSConfig.InsecureSkipVerify = true
		} else {
			certPool, err := common.GetRootCAFromFile(btnCert.GetFilename())
			if err != nil {
				dialogError(window, err)
				return
			}
			rclient.TLSConfig.RootCAs = certPool
		}

		session := &remoton.SessionClient{Client: rclient,
			ID:     machineIDEntry.GetText(),
			APIURL: "https://" + serverEntry.GetText()}

		if !started {
			err := chatSrv.Start(session)
			if err != nil {
				dialogError(btn.GetTopLevelAsWindow(), err)
				return
			}

			err = tunnelSrv.Start(session, machineAuthEntry.GetText())

			if err != nil {
				dialogError(btn.GetTopLevelAsWindow(), err)
				return
			}

			btn.SetLabel("Disconnect")
			started = true
		} else {
			chatSrv.Terminate()
			tunnelSrv.Terminate()
			btn.SetLabel("Connect")
			started = false
		}

	})
	controlBox.Add(btn)

	hpaned.Pack1(frameControl, false, false)
	hpaned.Pack2(frameChat, false, false)
	window.Add(appLayout)
	window.ShowAll()
	gtk.Main()

}
Beispiel #4
0
func init_tabby() {
	init_navigation()
	init_inotify()

	search_view.Init()

	source_buf = gtksourceview.NewSourceBuffer()
	source_buf.Connect("paste-done", paste_done_cb, nil)
	source_buf.Connect("mark-set", mark_set_cb, nil)
	source_buf.Connect("modified-changed", buf_changed_cb, nil)

	init_lang()

	source_buf.CreateTag("instance", map[string]string{"background": "#FF8080"})

	tree_store = gtk.NewTreeStore(glib.G_TYPE_STRING)
	tree_view = file_tree.NewFileTree()
	tree_view.ModifyFontEasy("Regular 8")
	tree_model = tree_store.ToTreeModel()
	tree_view.SetModel(tree_model)
	tree_view.SetHeadersVisible(false)
	tree_view.Connect("cursor-changed", tree_view_select_cb, nil)

	error_view = gtk.NewTextView()
	error_view.ModifyFontEasy("Monospace Regular 8")
	error_view.SetEditable(false)
	error_buf = error_view.GetBuffer()

	source_view = gtksourceview.NewSourceViewWithBuffer(source_buf)
	source_view.ModifyFontEasy("Monospace Regular 10")
	source_view.SetAutoIndent(true)
	source_view.SetHighlightCurrentLine(true)
	source_view.SetShowLineNumbers(true)
	source_view.SetRightMarginPosition(80)
	source_view.SetShowRightMargin(true)
	source_view.SetIndentWidth(2)
	source_view.SetTabWidth(2)
	source_view.SetInsertSpacesInsteadOfTabs(opt.space_not_tab)
	source_view.SetDrawSpaces(gtksourceview.SOURCE_DRAW_SPACES_TAB)
	source_view.SetSmartHomeEnd(gtksourceview.SOURCE_SMART_HOME_END_ALWAYS)
	source_view.SetWrapMode(gtk.WRAP_WORD)

	vbox := gtk.NewVBox(false, 0)
	inner_hpaned := gtk.NewHPaned()
	view_vpaned := gtk.NewVPaned()
	outer_hpaned := gtk.NewHPaned()
	outer_hpaned.Add1(inner_hpaned)
	inner_hpaned.Add2(view_vpaned)

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

	file_item := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(file_item)
	file_submenu := gtk.NewMenu()
	file_item.SetSubmenu(file_submenu)

	accel_group := gtk.NewAccelGroup()

	new_item := gtk.NewMenuItemWithMnemonic("_New")
	file_submenu.Append(new_item)
	new_item.Connect("activate", new_cb, nil)
	new_item.AddAccelerator("activate", accel_group, gdk.KEY_n, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	open_item := gtk.NewMenuItemWithMnemonic("_Open")
	file_submenu.Append(open_item)
	open_item.Connect("activate", open_cb, nil)
	open_item.AddAccelerator("activate", accel_group, gdk.KEY_o, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	open_rec_item := gtk.NewMenuItemWithMnemonic("Open _Recursively")
	file_submenu.Append(open_rec_item)
	open_rec_item.Connect("activate", open_rec_cb, nil)

	save_item := gtk.NewMenuItemWithMnemonic("_Save")
	file_submenu.Append(save_item)
	save_item.Connect("activate", save_cb, nil)
	save_item.AddAccelerator("activate", accel_group, gdk.KEY_s, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	save_as_item := gtk.NewMenuItemWithMnemonic("Save _as")
	file_submenu.Append(save_as_item)
	save_as_item.Connect("activate", save_as_cb, nil)

	close_item := gtk.NewMenuItemWithMnemonic("_Close")
	file_submenu.Append(close_item)
	close_item.Connect("activate", close_cb, nil)
	close_item.AddAccelerator("activate", accel_group, gdk.KEY_w, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	exit_item := gtk.NewMenuItemWithMnemonic("E_xit")
	file_submenu.Append(exit_item)
	exit_item.Connect("activate", exit_cb, nil)

	navigation_item := gtk.NewMenuItemWithMnemonic("_Navigation")
	menubar.Append(navigation_item)
	navigation_submenu := gtk.NewMenu()
	navigation_item.SetSubmenu(navigation_submenu)

	prev_instance_item := gtk.NewMenuItemWithMnemonic("_Previous Instance")
	navigation_submenu.Append(prev_instance_item)
	prev_instance_item.Connect("activate", prev_instance_cb, nil)
	prev_instance_item.AddAccelerator("activate", accel_group, gdk.KEY_F2,
		0, gtk.ACCEL_VISIBLE)

	next_instance_item := gtk.NewMenuItemWithMnemonic("_Next Instance")
	navigation_submenu.Append(next_instance_item)
	next_instance_item.Connect("activate", next_instance_cb, nil)
	next_instance_item.AddAccelerator("activate", accel_group, gdk.KEY_F3,
		0, gtk.ACCEL_VISIBLE)

	prev_result_item := gtk.NewMenuItemWithMnemonic("Prev search result")
	navigation_submenu.Append(prev_result_item)
	prev_result_item.Connect("activate", func() { search_view.PrevResult() }, nil)
	prev_result_item.AddAccelerator("activate", accel_group, gdk.KEY_F4,
		0, gtk.ACCEL_VISIBLE)

	next_result_item := gtk.NewMenuItemWithMnemonic("Next search result")
	navigation_submenu.Append(next_result_item)
	next_result_item.Connect("activate", func() { search_view.NextResult() }, nil)
	next_result_item.AddAccelerator("activate", accel_group, gdk.KEY_F5,
		0, gtk.ACCEL_VISIBLE)

	find_item := gtk.NewMenuItemWithMnemonic("_Find")
	navigation_submenu.Append(find_item)
	find_item.Connect("activate", find_cb, nil)
	find_item.AddAccelerator("activate", accel_group, gdk.KEY_f, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	find_file_item := gtk.NewMenuItemWithMnemonic("_Find file")
	navigation_submenu.Append(find_file_item)
	find_file_item.Connect("activate", find_file_cb, nil)
	find_file_item.AddAccelerator("activate", accel_group, gdk.KEY_d, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	fnr_item := gtk.NewMenuItemWithMnemonic("Find and Replace")
	navigation_submenu.Append(fnr_item)
	fnr_item.Connect("activate", fnr_cb, nil)
	fnr_item.AddAccelerator("activate", accel_group, gdk.KEY_r, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	prev_file_item := gtk.NewMenuItemWithMnemonic("Prev File")
	navigation_submenu.Append(prev_file_item)
	prev_file_item.Connect("activate", prev_file_cb, nil)
	prev_file_item.AddAccelerator("activate", accel_group, gdk.KEY_F7,
		0, gtk.ACCEL_VISIBLE)

	next_file_item := gtk.NewMenuItemWithMnemonic("Next File")
	navigation_submenu.Append(next_file_item)
	next_file_item.Connect("activate", next_file_cb, nil)
	next_file_item.AddAccelerator("activate", accel_group, gdk.KEY_F8,
		0, gtk.ACCEL_VISIBLE)

	tools_item := gtk.NewMenuItemWithMnemonic("_Tools")
	menubar.Append(tools_item)
	tools_submenu := gtk.NewMenu()
	tools_item.SetSubmenu(tools_submenu)

	gofmt_item := gtk.NewMenuItemWithMnemonic("_Gofmt")
	tools_submenu.Append(gofmt_item)
	gofmt_item.Connect("activate", gofmt_cb, nil)
	gofmt_item.AddAccelerator("activate", accel_group, gdk.KEY_F9,
		0, gtk.ACCEL_VISIBLE)

	gofmtAll_item := gtk.NewMenuItemWithMnemonic("Gofmt _All")
	tools_submenu.Append(gofmtAll_item)
	gofmtAll_item.Connect("activate", gofmt_all, nil)
	gofmtAll_item.AddAccelerator("activate", accel_group, gdk.KEY_F9, gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)

	options_item := gtk.NewMenuItemWithMnemonic("_Options")
	menubar.Append(options_item)
	options_submenu := gtk.NewMenu()
	options_item.SetSubmenu(options_submenu)

	search_chkitem := gtk.NewCheckMenuItemWithMnemonic("Show _Searchview")
	options_submenu.Append(search_chkitem)
	search_chkitem.SetActive(opt.show_search)
	search_chkitem.Connect("toggled", func() { search_chk_cb(search_chkitem.GetActive()) }, nil)

	error_chkitem := gtk.NewCheckMenuItemWithMnemonic("Show _Errorview")
	options_submenu.Append(error_chkitem)
	error_chkitem.SetActive(opt.show_error)
	error_chkitem.Connect("toggled", func() { error_chk_cb(error_chkitem.GetActive()) }, nil)

	notab_chkitem := gtk.NewCheckMenuItemWithMnemonic("Spaces for _Tabs")
	options_submenu.Append(notab_chkitem)
	notab_chkitem.SetActive(opt.space_not_tab)
	notab_chkitem.Connect("toggled", func() { notab_chk_cb(notab_chkitem.GetActive()) }, nil)

	font_item := gtk.NewMenuItemWithMnemonic("_Font")
	options_submenu.Append(font_item)
	font_item.Connect("activate", font_cb, nil)

	tabsize_item := gtk.NewMenuItemWithMnemonic("_Tab size")
	options_submenu.Append(tabsize_item)
	tabsize_submenu := gtk.NewMenu()
	tabsize_item.SetSubmenu(tabsize_submenu)
	const tabsize_cnt = 8
	tabsize_chk := make([]*gtk.CheckMenuItem, tabsize_cnt)
	for y := 0; y < tabsize_cnt; y++ {
		tabsize_chk[y] = gtk.NewCheckMenuItemWithMnemonic(strconv.Itoa(y + 1))
		tabsize_submenu.Append(tabsize_chk[y])
		cur_ind := y
		tabsize_chk[y].Connect("activate", func() {
			if false == tabsize_chk[cur_ind].GetActive() {
				active_cnt := 0
				for j := 0; j < tabsize_cnt; j++ {
					if tabsize_chk[j].GetActive() {
						active_cnt++
					}
				}
				if 0 == active_cnt {
					tabsize_chk[cur_ind].SetActive(true)
				}
				return
			}
			for j := 0; j < tabsize_cnt; j++ {
				if j != cur_ind {
					tabsize_chk[j].SetActive(false)
				}
			}
			options_set_tabsize(cur_ind + 1)
		},
			nil)
	}

	tree_window := gtk.NewScrolledWindow(nil, nil)
	tree_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	inner_hpaned.Add1(tree_window)
	tree_window.Add(tree_view)

	outer_hpaned.Add2(search_view.window)

	text_window := gtk.NewScrolledWindow(nil, nil)
	text_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
	view_vpaned.Add1(text_window)
	text_window.Add(source_view)

	error_window = gtk.NewScrolledWindow(nil, nil)
	error_window.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
	view_vpaned.Add2(error_window)
	error_window.Add(error_view)

	inner_hpaned.Connect("size_request", func() { ohp_cb(outer_hpaned.GetPosition()) }, nil)
	view_vpaned.Connect("size_request", func() { ihp_cb(inner_hpaned.GetPosition()) }, nil)
	source_view.Connect("size_request", func() { vvp_cb(view_vpaned.GetPosition()) }, nil)
	outer_hpaned.SetPosition(opt.ohp_position)
	inner_hpaned.SetPosition(opt.ihp_position)
	view_vpaned.SetPosition(opt.vvp_position)

	main_window = gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	main_window.AddAccelGroup(accel_group)
	main_window.SetSizeRequest(400, 200) //minimum size
	main_window.Resize(opt.window_width, opt.window_height)
	main_window.Move(opt.window_x, opt.window_y)
	main_window.Connect("destroy", exit_cb, "")
	main_window.Connect("configure-event", window_event_cb, "")
	main_window.Add(vbox)
	// init_tabby blocks for some reason when is called after ShowAll.
	init_vars()
	main_window.ShowAll()
	error_window.SetVisible(opt.show_error)
	// Cannot be called before ShowAll. This is also not clear.
	file_switch_to(file_stack_pop())
	stack_prev(&file_stack_max)
	if "" == cur_file {
		new_cb()
	}
	source_view.GrabFocus()
}
Beispiel #5
0
func win_start() {
	defer catch() // Panic Handler
	// Initiate GTK
	gtk.Init(&os.Args)

	// Window Setup
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

	// Create the Main Window
	// Set title & size
	win := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	win.SetTitle("0x_Calc")

	// on Exit -> Quit the program
	win.Connect("destroy", gtk.MainQuit)

	box_win := gtk.NewVBox(Homogeneous, Default_Spacing)

	// Menu Bar
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

	/*
			// Vertical Box for menu
			box_menu := gtk.NewVBox(false, 1)
			// MenuBar - menu
			mb_menu := gtk.NewMenuBar()
			box_menu.PackStart(mb_menu, false, false, 0)

			// Menu Items

			// [File]
			mi_file := gtk.NewMenuItemWithMnemonic("_File2")
			mb_menu.Append(mi_file)
			// Submenu for [File]
			subm_file := gtk.NewMenu()
			mi_file.SetSubmenu(subm_file)

			mi_exit := gtk.NewMenuItemWithMnemonic("_Exit2")
			mb_menu.Append(mi_exit)

			mi_exit.Connect("activate", func() {
				gtk.MainQuit()
			})

		// Add the menubox
		win.Add(box_menu)
	*/

	// Frame - Calculation
	// This frame contains radix(16,10,8) and result labels
	// ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
	fm_calc := gtk.NewFrame("Calculation")
	// (inner) Box of Calculation
	fm_calc_box := gtk.NewHBox(false, 1)
	fm_calc.Add(fm_calc_box)

	// Box for Radix Buttons.
	box_rdx := gtk.NewVBox(false, 1)
	btn_hex := button("Hex")                 // [Hex] : Hexadecimal
	btn_dec := gtk.NewButtonWithLabel("Dec") // [Dec] : Decimal
	btn_oct := gtk.NewButtonWithLabel("Oct") // [Oct] : Octal
	box_rdx.Add(btn_hex)
	box_rdx.Add(btn_dec)
	box_rdx.Add(btn_oct)

	// Box for Result Labels
	box_labels := gtk.NewVBox(false, 1)
	lbl_prev := gtk.NewLabel("Previous Result") // Previous Calculation
	lbl_late := gtk.NewLabel("Current Result")  // Latest Calculaltion
	box_labels.Add(lbl_prev)
	box_labels.Add(lbl_late)

	// Add both Boxes (Radix & Result) to frame box
	fm_calc_box.Add(box_rdx)
	fm_calc_box.Add(box_labels)

	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

	// Frame - Numbers
	// This frame contains number buttons for calculation
	//  	Hexadecimal	: 0 ~ 9, A ~ F
	//  	Decimal   	: 0 ~ 9
	//  	Octal     	: 0 ~ 7
	// ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
	fm_nums := gtk.NewFrame("Numbers")
	// (inner) Box of Numbers
	fm_nums_box := gtk.NewVBox(false, 1)
	fm_nums.Add(fm_nums_box)

	// Table Initialization
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
	tbl_nums := gtk.NewTable(5, 4, false)

	// Jagged slice of buttons
	// nums := [][]*gtk.Button{}

	// Button for Number
	num := [17]*gtk.Button{
		// 0~7 : Oct
		button("0"), button("1"), button("2"), button("3"),
		button("4"), button("5"), button("6"), button("7"),
		// 0~9 : Dec
		button("8"), button("9"),
		// 0~F : Hex
		button("A"), button("B"), button("C"),
		button("D"), button("E"), button("F"),
	}

	// Place buttons into the table
	tbl_nums.Attach(num[0], 0, 1, 3, 4, gtk.FILL, gtk.FILL, 1, 1) // 0
	tbl_nums.Attach(num[1], 0, 1, 2, 3, gtk.FILL, gtk.FILL, 1, 1) // 1
	tbl_nums.Attach(num[2], 1, 2, 2, 3, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[3], 2, 3, 2, 3, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[4], 0, 1, 1, 2, gtk.FILL, gtk.FILL, 1, 1) // 4
	tbl_nums.Attach(num[5], 1, 2, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[6], 2, 3, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[7], 0, 1, 0, 1, gtk.FILL, gtk.FILL, 1, 1) // 7
	tbl_nums.Attach(num[8], 1, 2, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[9], 2, 3, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[10], 3, 4, 2, 3, gtk.FILL, gtk.FILL, 1, 1) // A
	tbl_nums.Attach(num[11], 4, 5, 2, 3, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[12], 3, 4, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[13], 4, 5, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[14], 3, 4, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	tbl_nums.Attach(num[15], 4, 5, 0, 1, gtk.FILL, gtk.FILL, 1, 1) // F

	// Add the table to box
	fm_nums_box.Add(tbl_nums)
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

	// Frame - Operations
	// This frame contains operations.
	//  	ADD, SUB, MUL, DIV, MOD
	//  	AND, OR, XOR, NOT
	//  	LSHFT, RSHFT
	// ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
	fm_oper := gtk.NewFrame("Operations")
	// (inner) Box of Operations
	fm_oper_box := gtk.NewVBox(false, 1)
	fm_oper.Add(fm_oper_box)

	tbl_opers := gtk.NewTable(5, 3, false)

	// Operation Buttons
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
	// Button for Number
	// 'oper' is Jagged slice of buttons
	oper := [][]*gtk.Button{}
	// slice of Arithmetic
	oper_arit := []*gtk.Button{
		button("ADD"), button("SUB"), button("MUL"), button("DIV"),
		button("MOD")}
	// slice of Bitwise
	oper_bit := []*gtk.Button{
		button("AND"), button("OR"), button("XOR"), button("NOT")}
	// slice of Bit Shift
	oper_shft := []*gtk.Button{
		button("LSHIFT"), button("RSHIFT")}

	// Compose the jagged slice
	oper = append(oper, oper_arit)
	oper = append(oper, oper_bit)
	oper = append(oper, oper_shft)

	// Iterate jagged slice and place them into the table
	for r, btn_slice := range oper {
		// r : row
		// btn_slice : slice of buttons
		for c, btn := range btn_slice {
			// c : column
			// btn == btn_slice[c] == oper[row][col]
			// Place the button to table
			tbl_opers.Attach(btn, uint(c), uint(c)+1, uint(r), uint(r)+1,
				gtk.FILL, gtk.FILL, 1, 1)
		}
	}

	fm_oper_box.Add(tbl_opers)

	// Place buttons into the table
	// tbl_opers.Attach(oper[0], 0, 1, 3, 4, gtk.FILL, gtk.FILL, 5, 1) // 0

	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

	// Frame Positionings
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
	vpan1 := gtk.NewVPaned()
	vpan1.Pack1(fm_calc, No_Resize, No_Shrink)

	hpan1 := gtk.NewHPaned()
	hpan1.Pack1(fm_nums, No_Resize, No_Shrink)
	hpan1.Pack2(fm_oper, No_Resize, No_Shrink)

	vpan1.Pack2(hpan1, No_Resize, No_Shrink)

	box_win.Add(vpan1)

	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
	fmt.Println("UI Over?")
	win.Add(box_win)
	win.SetSizeRequest(UI_Width, UI_Height)
	win.ShowAll()

	// Start the UI
	gtk.Main()
}
Beispiel #6
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) {
		gtk.MainQuit()
	}, "")

	box := gtk.NewHPaned()

	palette := gtk.NewToolPalette()
	group := gtk.NewToolItemGroup("Tools")
	b := gtk.NewToolButtonFromStock(gtk.STOCK_NEW)
	b.OnClicked(func() { println("You clicked new!") })
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_CLOSE)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_REDO)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_REFRESH)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_QUIT)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_YES)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_NO)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_PRINT)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_NETWORK)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_INFO)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_HOME)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_INDEX)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_FIND)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_FILE)
	group.Insert(b, -1)
	b = gtk.NewToolButtonFromStock(gtk.STOCK_EXECUTE)
	group.Insert(b, -1)
	palette.Add(group)

	bcopy := gtk.NewToolButtonFromStock(gtk.STOCK_COPY)
	bcut := gtk.NewToolButtonFromStock(gtk.STOCK_CUT)
	bdelete := gtk.NewToolButtonFromStock(gtk.STOCK_DELETE)

	group = gtk.NewToolItemGroup("Stuff")
	group.Insert(bcopy, -1)
	group.Insert(bcut, -1)
	group.Insert(bdelete, -1)
	palette.Add(group)

	frame := gtk.NewVBox(false, 1)
	align := gtk.NewAlignment(0, 0, 0, 0)
	image := gtk.NewImageFromFile("./turkey.jpg")
	align.Add(image)
	frame.Add(align)

	box.Pack1(palette, true, false)
	box.Pack2(frame, false, false)

	window.Add(box)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
Beispiel #7
0
func main() {
	flag.Parse()

	runtime.GOMAXPROCS(runtime.NumCPU())
	common.SetDefaultGtkTheme()

	machinePassword = uuid.New()[:4]
	clremoton = newClient(&remoton.Client{Prefix: "/remoton", TLSConfig: &tls.Config{}})
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGABRT, syscall.SIGKILL, syscall.SIGTERM)
	go func() {
		<-sigs
		clremoton.Terminate()
	}()
	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("REMOTON CLIENT")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		gtk.MainQuit()
		clremoton.Terminate()
	}, "quit")
	window.SetIcon(common.GetIconGdkPixbuf())

	appLayout := gtk.NewVBox(false, 1)
	menu := gtk.NewMenuBar()
	appLayout.Add(menu)

	cascademenu := gtk.NewMenuItemWithMnemonic("_Help")
	menu.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	menuitem := gtk.NewMenuItemWithMnemonic("_About")
	menuitem.Connect("activate", func() {
		dialog := common.GtkAboutDialog()
		dialog.SetProgramName("Client Desktop")
		dialog.SetComments("Share your desktop secure")
		dialog.Run()
		dialog.Destroy()
	})
	submenu.Append(menuitem)

	hpaned := gtk.NewHPaned()
	appLayout.Add(hpaned)
	statusbar := gtk.NewStatusbar()
	contextID := statusbar.GetContextId("remoton-desktop-client")

	//---
	//CONTROL
	//---
	frameControl := gtk.NewFrame("Controls")
	controlBox := gtk.NewVBox(false, 1)
	frameControl.Add(controlBox)

	controlBox.Add(gtk.NewLabel("MACHINE ID"))
	machineIDEntry := gtk.NewEntry()
	machineIDEntry.SetEditable(false)
	controlBox.Add(machineIDEntry)

	machineAuthEntry := gtk.NewEntry()
	machineAuthEntry.SetEditable(false)
	controlBox.Add(machineAuthEntry)

	controlBox.Add(gtk.NewLabel("Server"))
	serverEntry := gtk.NewEntry()
	serverEntry.SetText("127.0.0.1:9934")
	if os.Getenv("REMOTON_SERVER") != "" {
		serverEntry.SetText(os.Getenv("REMOTON_SERVER"))
		serverEntry.SetEditable(false)
	}
	controlBox.Add(serverEntry)

	controlBox.Add(gtk.NewLabel("Auth Server"))
	authServerEntry := gtk.NewEntry()
	authServerEntry.SetText("public")
	controlBox.Add(authServerEntry)

	var getCertFilename func() string

	localCert := filepath.Join(filepath.Dir(os.Args[0]), "cert.pem")
	if _, err := os.Stat(localCert); err == nil || os.IsExist(err) {
		controlBox.Add(gtk.NewLabel("Cert local"))
		getCertFilename = func() string {
			return localCert
		}
	} else if os.Getenv("REMOTON_CERT_FILE") != "" {
		controlBox.Add(gtk.NewLabel("Cert enviroment"))
		getCertFilename = func() string {
			return os.Getenv("REMOTON_CERT_FILE")
		}
	} else {
		btnCert := gtk.NewFileChooserButton("Cert", gtk.FILE_CHOOSER_ACTION_OPEN)
		getCertFilename = btnCert.GetFilename
		controlBox.Add(btnCert)
	}

	btnSrv := gtk.NewButtonWithLabel("Start")
	clremoton.VNC.OnConnection(func(addr net.Addr) {
		statusbar.Push(contextID, "Someone connected")
		log.Println("New connection from:" + addr.String())
	})
	btnSrv.Clicked(func() {
		if *insecure {
			clremoton.SetInsecure()
		} else {
			certPool, err := common.GetRootCAFromFile(getCertFilename())
			if err != nil {
				dialogError(window, err)
				return
			}
			clremoton.SetCertPool(certPool)
		}

		if !clremoton.Started() {
			log.Println("starting remoton")
			machinePassword = uuid.New()[:4]
			err := clremoton.Start(serverEntry.GetText(), authServerEntry.GetText(),
				machinePassword)

			if err != nil {
				dialogError(btnSrv.GetTopLevelAsWindow(), err)
				statusbar.Push(contextID, "Failed")
			} else {
				btnSrv.SetLabel("Stop")

				machineIDEntry.SetText(clremoton.MachineID())
				machineAuthEntry.SetText(machinePassword)
				statusbar.Push(contextID, "Connected")
			}

		} else {
			clremoton.Stop()
			btnSrv.SetLabel("Start")
			machineIDEntry.SetText("")
			machineAuthEntry.SetText("")
			statusbar.Push(contextID, "Stopped")

		}

	})
	controlBox.Add(btnSrv)

	//---
	// CHAT
	//---
	frameChat := gtk.NewFrame("Chat")
	chatBox := gtk.NewVBox(false, 1)
	frameChat.Add(chatBox)

	swinChat := gtk.NewScrolledWindow(nil, nil)
	chatHistory := gtk.NewTextView()
	clremoton.Chat.OnRecv(func(msg string) {
		chatHistoryRecv(chatHistory, msg)
	})

	swinChat.Add(chatHistory)

	chatEntry := gtk.NewEntry()
	chatEntry.Connect("key-press-event", func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		event := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		if event.Keyval == gdk.KEY_Return {
			msgToSend := chatEntry.GetText()
			clremoton.Chat.Send(msgToSend)
			chatHistorySend(chatHistory, msgToSend)
			chatEntry.SetText("")
		}

	})
	chatBox.Add(chatEntry)
	chatBox.Add(swinChat)

	hpaned.Pack1(frameControl, false, false)
	hpaned.Pack2(frameChat, false, true)
	appLayout.Add(statusbar)
	window.Add(appLayout)
	window.ShowAll()
	gtk.Main()
}