Beispiel #1
0
func main() {
	var menuitem *gtk.MenuItem
	gtk.Init(nil)
	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) {
		println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "foo")

	//--------------------------------------------------------
	// GtkVBox
	//--------------------------------------------------------
	vbox := gtk.NewVBox(false, 1)

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

	//--------------------------------------------------------
	// GtkVPaned
	//--------------------------------------------------------
	vpaned := gtk.NewVPaned()
	vbox.Add(vpaned)

	//--------------------------------------------------------
	// GtkFrame
	//--------------------------------------------------------
	frame1 := gtk.NewFrame("Demo")
	framebox1 := gtk.NewVBox(false, 1)
	frame1.Add(framebox1)

	frame2 := gtk.NewFrame("Demo")
	framebox2 := gtk.NewVBox(false, 1)
	frame2.Add(framebox2)

	vpaned.Pack1(frame1, false, false)
	vpaned.Pack2(frame2, false, false)

	//--------------------------------------------------------
	// GtkImage
	//--------------------------------------------------------
	dir, _ := path.Split(os.Args[0])
	imagefile := path.Join(dir, "../../data/go-gtk-logo.png")

	label := gtk.NewLabel("Go Binding for GTK")
	label.ModifyFontEasy("DejaVu Serif 15")
	framebox1.PackStart(label, false, true, 0)

	//--------------------------------------------------------
	// GtkEntry
	//--------------------------------------------------------
	entry := gtk.NewEntry()
	entry.SetText("Hello world")
	framebox1.Add(entry)

	image := gtk.NewImageFromFile(imagefile)
	framebox1.Add(image)

	//--------------------------------------------------------
	// GtkScale
	//--------------------------------------------------------
	scale := gtk.NewHScaleWithRange(0, 100, 1)
	scale.Connect("value-changed", func() {
		println("scale:", int(scale.GetValue()))
	})
	framebox2.Add(scale)

	//--------------------------------------------------------
	// GtkHBox
	//--------------------------------------------------------
	buttons := gtk.NewHBox(false, 1)

	//--------------------------------------------------------
	// GtkButton
	//--------------------------------------------------------
	button := gtk.NewButtonWithLabel("Button with label")
	button.Clicked(func() {
		println("button clicked:", button.GetLabel())
		messagedialog := gtk.NewMessageDialog(
			button.GetTopLevelAsWindow(),
			gtk.DIALOG_MODAL,
			gtk.MESSAGE_INFO,
			gtk.BUTTONS_OK,
			entry.GetText())
		messagedialog.Response(func() {
			println("Dialog OK!")

			//--------------------------------------------------------
			// GtkFileChooserDialog
			//--------------------------------------------------------
			filechooserdialog := gtk.NewFileChooserDialog(
				"Choose File...",
				button.GetTopLevelAsWindow(),
				gtk.FILE_CHOOSER_ACTION_OPEN,
				gtk.STOCK_OK,
				gtk.RESPONSE_ACCEPT)
			filter := gtk.NewFileFilter()
			filter.AddPattern("*.go")
			filechooserdialog.AddFilter(filter)
			filechooserdialog.Response(func() {
				println(filechooserdialog.GetFilename())
				filechooserdialog.Destroy()
			})
			filechooserdialog.Run()
			messagedialog.Destroy()
		})
		messagedialog.Run()
	})
	buttons.Add(button)

	//--------------------------------------------------------
	// GtkFontButton
	//--------------------------------------------------------
	fontbutton := gtk.NewFontButton()
	fontbutton.Connect("font-set", func() {
		println("title:", fontbutton.GetTitle())
		println("fontname:", fontbutton.GetFontName())
		println("use_size:", fontbutton.GetUseSize())
		println("show_size:", fontbutton.GetShowSize())
	})
	buttons.Add(fontbutton)
	framebox2.PackStart(buttons, false, false, 0)

	buttons = gtk.NewHBox(false, 1)

	//--------------------------------------------------------
	// GtkToggleButton
	//--------------------------------------------------------
	togglebutton := gtk.NewToggleButtonWithLabel("ToggleButton with label")
	togglebutton.Connect("toggled", func() {
		if togglebutton.GetActive() {
			togglebutton.SetLabel("ToggleButton ON!")
		} else {
			togglebutton.SetLabel("ToggleButton OFF!")
		}
	})
	buttons.Add(togglebutton)

	//--------------------------------------------------------
	// GtkCheckButton
	//--------------------------------------------------------
	checkbutton := gtk.NewCheckButtonWithLabel("CheckButton with label")
	checkbutton.Connect("toggled", func() {
		if checkbutton.GetActive() {
			checkbutton.SetLabel("CheckButton CHECKED!")
		} else {
			checkbutton.SetLabel("CheckButton UNCHECKED!")
		}
	})
	buttons.Add(checkbutton)

	//--------------------------------------------------------
	// GtkRadioButton
	//--------------------------------------------------------
	buttonbox := gtk.NewVBox(false, 1)
	radiofirst := gtk.NewRadioButtonWithLabel(nil, "Radio1")
	buttonbox.Add(radiofirst)
	buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio2"))
	buttonbox.Add(gtk.NewRadioButtonWithLabel(radiofirst.GetGroup(), "Radio3"))
	buttons.Add(buttonbox)
	//radiobutton.SetMode(false);
	radiofirst.SetActive(true)

	framebox2.PackStart(buttons, false, false, 0)

	//--------------------------------------------------------
	// GtkVSeparator
	//--------------------------------------------------------
	vsep := gtk.NewVSeparator()
	framebox2.PackStart(vsep, false, false, 0)

	//--------------------------------------------------------
	// GtkComboBoxEntry
	//--------------------------------------------------------
	combos := gtk.NewHBox(false, 1)
	comboboxentry := gtk.NewComboBoxEntryNewText()
	comboboxentry.AppendText("Monkey")
	comboboxentry.AppendText("Tiger")
	comboboxentry.AppendText("Elephant")
	comboboxentry.Connect("changed", func() {
		println("value:", comboboxentry.GetActiveText())
	})
	combos.Add(comboboxentry)

	//--------------------------------------------------------
	// GtkComboBox
	//--------------------------------------------------------
	combobox := gtk.NewComboBoxNewText()
	combobox.AppendText("Peach")
	combobox.AppendText("Banana")
	combobox.AppendText("Apple")
	combobox.SetActive(1)
	combobox.Connect("changed", func() {
		println("value:", combobox.GetActiveText())
	})
	combos.Add(combobox)

	framebox2.PackStart(combos, false, false, 0)

	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)
	textview := gtk.NewTextView()
	var start, end gtk.TextIter
	buffer := textview.GetBuffer()
	buffer.GetStartIter(&start)
	buffer.Insert(&start, "Hello ")
	buffer.GetEndIter(&end)
	buffer.Insert(&end, "World!")
	tag := buffer.CreateTag("bold", map[string]string{
		"background": "#FF0000", "weight": "700"})
	buffer.GetStartIter(&start)
	buffer.GetEndIter(&end)
	buffer.ApplyTag(tag, &start, &end)
	swin.Add(textview)
	framebox2.Add(swin)

	buffer.Connect("changed", func() {
		println("changed")
	})

	//--------------------------------------------------------
	// GtkMenuItem
	//--------------------------------------------------------
	cascademenu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

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

	cascademenu = gtk.NewMenuItemWithMnemonic("_View")
	menubar.Append(cascademenu)
	submenu = gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable")
	checkmenuitem.Connect("activate", func() {
		vpaned.SetSensitive(!checkmenuitem.GetActive())
	})
	submenu.Append(checkmenuitem)

	menuitem = gtk.NewMenuItemWithMnemonic("_Font")
	menuitem.Connect("activate", func() {
		fsd := gtk.NewFontSelectionDialog("Font")
		fsd.SetFontName(fontbutton.GetFontName())
		fsd.Response(func() {
			println(fsd.GetFontName())
			fontbutton.SetFontName(fsd.GetFontName())
			fsd.Destroy()
		})
		fsd.SetTransientFor(window)
		fsd.Run()
	})
	submenu.Append(menuitem)

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

	menuitem = gtk.NewMenuItemWithMnemonic("_About")
	menuitem.Connect("activate", func() {
		dialog := gtk.NewAboutDialog()
		dialog.SetName("Go-Gtk Demo!")
		dialog.SetProgramName("demo")
		dialog.SetAuthors(authors())
		dir, _ := path.Split(os.Args[0])
		imagefile := path.Join(dir, "../../data/mattn-logo.png")
		pixbuf, _ := gdkpixbuf.NewFromFile(imagefile)
		dialog.SetLogo(pixbuf)
		dialog.SetLicense("The library is available under the same terms and conditions as the Go, the BSD style license, and the LGPL (Lesser GNU Public License). The idea is that if you can use Go (and Gtk) in a project, you should also be able to use go-gtk.")
		dialog.SetWrapLicense(true)
		dialog.Run()
		dialog.Destroy()
	})
	submenu.Append(menuitem)

	//--------------------------------------------------------
	// GtkStatusbar
	//--------------------------------------------------------
	statusbar := gtk.NewStatusbar()
	context_id := statusbar.GetContextId("go-gtk")
	statusbar.Push(context_id, "GTK binding for Go!")

	framebox2.PackStart(statusbar, false, false, 0)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	gtk.Main()
}
Beispiel #2
0
func guiMain(confglobal string, conflocal string) {
	var CallID string
	ch := make(chan string, 100)
	Config := ReadConfig(confglobal)
	Configlocal := ReadConfiglocal(conflocal)
	owner := Configlocal.Main.Owner

	//prepare config for XSI
	var xsiConfig xsi.ConfigT
	xsiConfig.Main.User = Configlocal.Main.Owner
	xsiConfig.Main.Password = Configlocal.Main.Password
	xsiConfig.Main.Host = Config.Main.Host
	xsiConfig.Main.HTTPHost = Config.Main.HTTPHost
	xsiConfig.Main.HTTPPort = Config.Main.HTTPPort
	def := xsi.MakeDef(xsiConfig)

	//start main client
	go clientMain(ch, Config)

	//prepare config for OCI
	var ociConfig ocip.ConfigT
	ociConfig.Main.User = Configlocal.Main.Owner
	ociConfig.Main.Password = Configlocal.Main.Password
	ociConfig.Main.Host = Config.Main.Host
	ociConfig.Main.OCIPPort = Config.Main.OCIPPort
	//set unavailable at start app
	ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Unavailable")
	//prepare timer
	timer := time.NewTimer(time.Second)
	timer.Stop()

	//init gthreads
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)

	//names
	names := make(map[string]string)
	for iter, target := range Config.Main.TargetID {
		names[target] = Config.Main.Name[iter]
	}

	//icons to pixbuf map
	pix := make(map[string]*gdkpixbuf.Pixbuf)
	im_call := gtk.NewImageFromFile("ico/Call-Ringing-48.ico")
	pix["call"] = im_call.GetPixbuf()
	im_blank := gtk.NewImageFromFile("ico/Empty-48.ico")
	pix["blank"] = im_blank.GetPixbuf()
	im_green := gtk.NewImageFromFile("ico/Green-ball-48.ico")
	pix["green"] = im_green.GetPixbuf()
	im_grey := gtk.NewImageFromFile("ico/Grey-ball-48.ico")
	pix["grey"] = im_grey.GetPixbuf()
	im_yellow := gtk.NewImageFromFile("ico/Yellow-ball-48.ico")
	pix["yellow"] = im_yellow.GetPixbuf()

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Call Center")
	window.SetIcon(pix["call"])
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetSizeRequest(350, 500)
	window.SetDecorated(false)
	window.SetResizable(true)
	window.Connect("destroy", gtk.MainQuit)

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

	//owner
	owner1 := gtk.NewLabel(names[owner])
	owner2 := gtk.NewLabel("")
	owner3 := gtk.NewImage()

	//qstatus
	qlabel1 := gtk.NewLabel("В очереди:")
	qlabel2 := gtk.NewLabel("")

	//buttons
	b_av := gtk.NewButtonWithLabel("Доступен")
	b_av.SetCanFocus(false)
	b_av.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Available")
	})
	b_un := gtk.NewButtonWithLabel("Недоступен")
	b_un.SetCanFocus(false)
	b_un.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Unavailable")
	})
	b_wr := gtk.NewButtonWithLabel("Дообработка")
	b_wr.SetCanFocus(false)
	b_wr.Connect("clicked", func() {
		ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Wrap-Up")
	})

	//main table
	table := gtk.NewTable(3, 3, false)
	table.Attach(owner1, 0, 1, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(owner3, 1, 2, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(owner2, 2, 3, 0, 1, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(b_av, 0, 1, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(b_un, 1, 2, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(b_wr, 2, 3, 1, 2, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(qlabel1, 0, 1, 2, 3, gtk.FILL, gtk.FILL, 1, 1)
	table.Attach(qlabel2, 1, 2, 2, 3, gtk.FILL, gtk.FILL, 1, 1)

	//menu buttons
	btnclose := gtk.NewToolButtonFromStock(gtk.STOCK_STOP)
	btnclose.SetCanFocus(false)
	btnclose.OnClicked(gtk.MainQuit)

	btnhide := gtk.NewToolButtonFromStock(gtk.STOCK_REMOVE)
	btnhide.SetCanFocus(false)
	btnhide.OnClicked(window.Iconify)

	//move window
	var p2, p1 point
	var gdkwin *gdk.Window
	p1.x = -1
	p2.y = -1
	var x int = 0
	var y int = 0
	var diffx int = 0
	var diffy int = 0
	px := &x
	py := &y
	movearea := gtk.NewDrawingArea()
	movearea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		if gdkwin == nil {
			gdkwin = movearea.GetWindow()
		}
		arg := ctx.Args(0)
		mev := *(**gdk.EventMotion)(unsafe.Pointer(&arg))
		var mt gdk.ModifierType
		if mev.IsHint != 0 {
			gdkwin.GetPointer(&p2.x, &p2.y, &mt)
		}
		if (gdk.EventMask(mt) & gdk.BUTTON_PRESS_MASK) != 0 {
			if p1.x != -1 && p1.y != -1 {
				window.GetPosition(px, py)
				diffx = p2.x - p1.x
				diffy = p2.y - p1.y
				window.Move(x+diffx, y+diffy)
			}
			p1.x = p2.x - diffx
			p1.y = p2.y - diffy
		} else {
			p1.x = -1
			p2.y = -1
		}
	})
	movearea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))

	//resize window
	var p2r, p1r point
	var gdkwinr *gdk.Window
	p1r.x = -1
	p2r.y = -1
	var xr int = 0
	var yr int = 0
	var diffxr int = 0
	var diffyr int = 0
	pxr := &xr
	pyr := &yr

	resizearea := gtk.NewDrawingArea()
	resizearea.SetSizeRequest(10, 10)
	resizearea.Connect("motion-notify-event", func(ctx *glib.CallbackContext) {
		if gdkwinr == nil {
			gdkwinr = resizearea.GetWindow()
		}
		argr := ctx.Args(0)
		mevr := *(**gdk.EventMotion)(unsafe.Pointer(&argr))
		var mtr gdk.ModifierType
		if mevr.IsHint != 0 {
			gdkwinr.GetPointer(&p2r.x, &p2r.y, &mtr)
		}
		if (gdk.EventMask(mtr) & gdk.BUTTON_PRESS_MASK) != 0 {
			if p1r.x != -1 && p1r.y != -1 {
				diffxr = p2r.x - p1r.x
				diffyr = p2r.y - p1r.y
				window.GetSize(pxr, pyr)
				window.Resize(xr+diffxr, yr+diffyr)
			}
		}
		p1r = p2r
	})
	resizearea.SetEvents(int(gdk.POINTER_MOTION_MASK | gdk.POINTER_MOTION_HINT_MASK | gdk.BUTTON_PRESS_MASK))

	//menu
	menutable := gtk.NewTable(1, 8, true)
	menutable.Attach(movearea, 0, 6, 0, 1, gtk.FILL, gtk.FILL, 0, 0)
	menutable.Attach(btnhide, 6, 7, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0)
	menutable.Attach(btnclose, 7, 8, 0, 1, gtk.EXPAND, gtk.EXPAND, 0, 0)

	//agents
	dlabel1 := make(map[string]*gtk.Label)
	dlabel2 := make(map[string]*gtk.Image)
	dlabel3 := make(map[string]*gtk.Image)
	b_tr := make(map[string]*gtk.Button)

	var count uint = 0
	for _, target := range Config.Main.TargetID {
		if target != owner {
			count = count + 1
			dlabel1[target] = gtk.NewLabel(names[target])
			dlabel2[target] = gtk.NewImage()
			dlabel3[target] = gtk.NewImage()
			tmp := gtk.NewButtonWithLabel("Перевод")
			tmp.SetCanFocus(false)
			tmptarget := target
			tmp.Connect("clicked", func() {
				xsi.XSITransfer(xsiConfig, def, owner, CallID, tmptarget)
			})
			b_tr[target] = tmp
		}
	}

	table_ag := gtk.NewTable(4, count+1, false)
	var place uint = 0
	for _, target := range Config.Main.TargetID {
		if target != owner {
			place = place + 1
			table_ag.Attach(dlabel1[target], 0, 1, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
			table_ag.Attach(dlabel3[target], 2, 3, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
			table_ag.Attach(dlabel2[target], 1, 2, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
			table_ag.Attach(b_tr[target], 3, 4, place, place+1, gtk.FILL, gtk.FILL, 1, 1)
		}
	}

	//calls
	table_cl := gtk.NewTable(2, 15, false)
	dlabel4 := make(map[uint]*gtk.Label)
	dlabel5 := make(map[uint]*gtk.Label)
	var i uint
	for i = 0; i < 15; i++ {
		dlabel4[i] = gtk.NewLabel("")
		table_cl.Attach(dlabel4[i], 0, 1, i, i+1, gtk.FILL, gtk.FILL, 1, 1)
		dlabel5[i] = gtk.NewLabel("")
		table_cl.Attach(dlabel5[i], 1, 2, i, i+1, gtk.FILL, gtk.FILL, 1, 1)
	}

	//tabs
	notebook := gtk.NewNotebook()
	notebook.AppendPage(table_ag, gtk.NewLabel("Агенты"))
	notebook.AppendPage(table_cl, gtk.NewLabel("Звонки"))

	//add all to window
	vbox := gtk.NewVBox(false, 1)
	vbox.Add(menutable)
	vbox.Add(table)
	vbox.Add(notebook)
	vbox.Add(resizearea)

	swin.AddWithViewPort(vbox)
	window.Add(swin)
	window.ShowAll()

	//main func for update
	go func() {
		for {
			select {
			case data := <-ch:
				cinfo := strings.Split(strings.Trim(data, "\n"), ";")
				//owner
				if cinfo[0] == owner && cinfo[1] == "state" {
					if cinfo[4] != "" {
						CallID = cinfo[5]
						gdk.ThreadsEnter()
						owner2.SetLabel(strings.Trim(cinfo[4], "tel:"))
						gdk.ThreadsLeave()
					} else {
						CallID = ""
						gdk.ThreadsEnter()
						owner2.SetLabel("")
						gdk.ThreadsLeave()
					}
					if cinfo[3] == "Available" {
						gdk.ThreadsEnter()
						owner3.SetFromPixbuf(pix["green"])
						gdk.ThreadsLeave()
					} else if cinfo[3] == "Wrap-Up" {
						gdk.ThreadsEnter()
						owner3.SetFromPixbuf(pix["yellow"])
						gdk.ThreadsLeave()
						timer.Reset(time.Second * Config.Main.Wraptime)
					} else {
						gdk.ThreadsEnter()
						owner3.SetFromPixbuf(pix["grey"])
						gdk.ThreadsLeave()
					}
				}
				//CC q
				if cinfo[0] == Config.Main.CCID && cinfo[1] == "state" {
					if cinfo[6] != "" {
						gdk.ThreadsEnter()
						qlabel2.SetLabel(cinfo[6])
						gdk.ThreadsLeave()
					}
				}
				//CC calls
				if cinfo[0] == Config.Main.CCID && cinfo[1] == "calls" {
					if cinfo[3] != "" {
						var i, j uint
						j = 2
						for i = 0; i < 15; i++ {
							if cinfo[j] != "" {
								date, _ := strconv.Atoi(cinfo[j])
								date = date / 1000
								j++
								Addr := strings.Trim(cinfo[j], "tel:")
								j++
								Time := time.Unix(int64(date), 0)
								gdk.ThreadsEnter()
								tmp4 := dlabel4[i]
								tmp4.SetLabel(Time.Format(time.Stamp))
								tmp5 := dlabel5[i]
								tmp5.SetLabel(Addr)
								dlabel4[i] = tmp4
								dlabel5[i] = tmp5
								gdk.ThreadsLeave()
							}
						}
					}
				}
				//Targets
				if cinfo[0] != owner && cinfo[0] != Config.Main.CCID && cinfo[1] == "state" {
					if cinfo[2] == "On-Hook" {
						gdk.ThreadsEnter()
						tmp := dlabel3[cinfo[0]]
						tmp.SetFromPixbuf(pix["blank"])
						dlabel3[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					}
					if cinfo[2] == "Off-Hook" {
						gdk.ThreadsEnter()
						tmp := dlabel3[cinfo[0]]
						tmp.SetFromPixbuf(pix["call"])
						dlabel3[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					}
					if cinfo[3] == "Available" {
						gdk.ThreadsEnter()
						tmp := dlabel2[cinfo[0]]
						tmp.SetFromPixbuf(pix["green"])
						dlabel2[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					} else if cinfo[3] == "Wrap-Up" {
						gdk.ThreadsEnter()
						tmp := dlabel2[cinfo[0]]
						tmp.SetFromPixbuf(pix["yellow"])
						dlabel2[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					} else {
						gdk.ThreadsEnter()
						tmp := dlabel2[cinfo[0]]
						tmp.SetFromPixbuf(pix["grey"])
						dlabel2[cinfo[0]] = tmp
						gdk.ThreadsLeave()
					}
				}
				//timer for wrap-up
			case <-timer.C:
				ocip.OCIPsend(ociConfig, "UserCallCenterModifyRequest19", ConcatStr("", "userId=", owner), "agentACDState=Available")
			}
		}
	}()
	gtk.Main()
}
Beispiel #3
0
func loadImageAsset(assetName string) gtk.IWidget {
	assetFile := assets[assetName]
	return gtk.NewImageFromFile(assetFile)
}
Beispiel #4
0
func main() {
	gtk.Init(nil)
	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")

	//--------------------------------------------------------
	// GtkVBox
	//--------------------------------------------------------
	vbox := gtk.NewVBox(false, 1)

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

	//--------------------------------------------------------
	// GtkVPaned
	//--------------------------------------------------------
	vpaned := gtk.NewVPaned()
	vbox.Add(vpaned)

	//--------------------------------------------------------
	// GtkFrame
	//--------------------------------------------------------
	frame1 := gtk.NewFrame("Demo")
	framebox1 := gtk.NewVBox(false, 1)
	//frame2 := gtk.NewFrame("Demo")
	//framebox2 := gtk.NewVBox(false, 1)
	//frame2.Add(framebox2)
	frame1.Add(framebox1)
	vpaned.Pack1(frame1, false, false)
	//vpaned.Pack1(frame2, false, false)

	entry := gtk.NewEntry()
	entry.SetText("Hej")
	framebox1.Add(entry)
	//vbox.PackStart(menubar, false, false, 0)

	imagefile := "texy1.png"
	image := gtk.NewImageFromFile(imagefile)
	framebox1.Add(image)
	button := gtk.NewButtonWithLabel("Calculate!")
	button.Clicked(func() {
		handlestring(entry.GetText())
		image.SetFromFile("temp.png")
	})
	framebox1.Add(button)

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

}
Beispiel #5
0
func main() {
	gtk.Init(nil)

	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetPosition(gtk.WIN_POS_CENTER)
	window.SetTitle("GoMADScan")
	window.SetIconName("GoMADScan-info")
	window.Connect("destroy", func(ctx *glib.CallbackContext) {
		// fmt.Println("got destroy!", ctx.Data().(string))
		gtk.MainQuit()
	}, "")

	//--------------------------------------------------------
	// GtkVBox
	//--------------------------------------------------------
	vbox := gtk.NewVBox(false, 1)

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

	//--------------------------------------------------------
	// GtkVPaned
	//--------------------------------------------------------
	vpaned := gtk.NewVPaned()
	vbox.Add(vpaned)

	//--------------------------------------------------------
	// GtkFrame
	//--------------------------------------------------------
	frame1 := gtk.NewFrame("")
	framebox1 := gtk.NewVBox(false, 1)
	frame1.Add(framebox1)

	frame2 := gtk.NewFrame("Column index for search (0: all columns)")
	framebox2 := gtk.NewVBox(false, 1)
	frame2.Add(framebox2)

	vpaned.Pack1(frame1, false, false)
	vpaned.Pack2(frame2, false, false)

	//--------------------------------------------------------
	// GtkImage
	//--------------------------------------------------------
	dir := os.Getenv("GOPATH")
	if dir == "" {
		dir = filepath.Join(os.Getenv("HOME"), "/go")
	}
	imagefile := filepath.Join(dir, "/src/github.com/carushi/GoMADScan/image/logo.png")
	label := gtk.NewLabel("Go-based Modification associated database scanner")
	label.ModifyFontEasy("DejaVu Serif 15")
	framebox1.PackStart(label, false, true, 0)
	image := gtk.NewImageFromFile(imagefile)
	framebox1.Add(image)

	//--------------------------------------------------------
	// Data input and output filename
	//--------------------------------------------------------
	arg := arguments{
		0,
		filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/Sample_modification_site"),
		filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/Ras_gene_synonym.txt"),
		filepath.Join(dir, "/src/github.com/carushi/GoMADScan/data/output.txt"),
		false,
		true,
		"\t"}

	//--------------------------------------------------------
	// GtkScale
	//--------------------------------------------------------
	scale := gtk.NewHScaleWithRange(0, 20, 1)
	scale.Connect("value-changed", func() {
		arg.column = int(scale.GetValue())
		// fmt.Println("scale:", int(scale.GetValue()))
	})
	framebox2.Add(scale)

	//--------------------------------------------------------
	// InputArea
	//--------------------------------------------------------
	ientry := gtk.NewEntry()
	ientry.SetText(arg.inputPath)
	inputs := gtk.NewHBox(false, 1)
	button := gtk.NewButtonWithLabel("Choose input file")
	button.Clicked(func() {
		//--------------------------------------------------------
		// GtkFileChooserDialog
		//--------------------------------------------------------
		filechooserdialog := gtk.NewFileChooserDialog(
			"Choose File...",
			button.GetTopLevelAsWindow(),
			gtk.FILE_CHOOSER_ACTION_OPEN,
			gtk.STOCK_OK,
			gtk.RESPONSE_ACCEPT)
		filter := gtk.NewFileFilter()
		filter.AddPattern("*")
		filechooserdialog.AddFilter(filter)
		filechooserdialog.Response(func() {
			arg.inputPath = filechooserdialog.GetFilename()
			ientry.SetText(arg.inputPath)
			filechooserdialog.Destroy()
		})
		filechooserdialog.Run()
	})
	inputs.Add(button)
	inputs.Add(ientry)
	framebox2.PackStart(inputs, false, false, 0)

	fentry := gtk.NewEntry()
	fentry.SetText(arg.filterPath)
	inputs = gtk.NewHBox(false, 1)
	button = gtk.NewButtonWithLabel("Choose keyword file")
	button.Clicked(func() {
		//--------------------------------------------------------
		// GtkFileChooserDialog
		//--------------------------------------------------------
		filechooserdialog := gtk.NewFileChooserDialog(
			"Choose File...",
			button.GetTopLevelAsWindow(),
			gtk.FILE_CHOOSER_ACTION_OPEN,
			gtk.STOCK_OK,
			gtk.RESPONSE_ACCEPT)
		filter := gtk.NewFileFilter()
		filter.AddPattern("*")
		filechooserdialog.AddFilter(filter)
		filechooserdialog.Response(func() {
			arg.filterPath = filechooserdialog.GetFilename()
			fentry.SetText(arg.filterPath)
			filechooserdialog.Destroy()
		})
		filechooserdialog.Run()
	})
	inputs.Add(button)
	inputs.Add(fentry)
	framebox2.PackStart(inputs, false, false, 0)

	oentry := gtk.NewEntry()
	oentry.SetText(arg.outputPath)
	inputs = gtk.NewHBox(false, 1)
	button = gtk.NewButtonWithLabel("Choose output file")
	button.Clicked(func() {
		//--------------------------------------------------------
		// GtkFileChooserDialog
		//--------------------------------------------------------
		filechooserdialog := gtk.NewFileChooserDialog(
			"Choose File...",
			button.GetTopLevelAsWindow(),
			gtk.FILE_CHOOSER_ACTION_OPEN,
			gtk.STOCK_OK,
			gtk.RESPONSE_ACCEPT)
		filter := gtk.NewFileFilter()
		filter.AddPattern("*")
		filechooserdialog.AddFilter(filter)
		filechooserdialog.Response(func() {
			arg.outputPath = filechooserdialog.GetFilename()
			oentry.SetText(arg.outputPath)
			filechooserdialog.Destroy()
		})
		filechooserdialog.Run()
	})
	inputs.Add(button)
	inputs.Add(oentry)
	framebox2.PackStart(inputs, false, false, 0)

	buttons := gtk.NewHBox(false, 1)

	//--------------------------------------------------------
	// GtkCheckButton
	//--------------------------------------------------------
	checkbutton := gtk.NewCheckButtonWithLabel("Case-insensitive (lower/upper)")
	checkbutton.Connect("toggled", func() {
		if checkbutton.GetActive() {
			arg.ignoreCase = true
		} else {
			arg.ignoreCase = false
		}
	})
	buttons.Add(checkbutton)

	checkMatchButton := gtk.NewCheckButtonWithLabel("Partial matching / Perfect matching")
	checkMatchButton.Connect("toggled", func() {
		if checkMatchButton.GetActive() {
			arg.perfectMatch = false
		} else {
			arg.perfectMatch = true
		}
	})
	buttons.Add(checkMatchButton)

	combobox := gtk.NewComboBoxText()
	for _, delim := range delimName {
		combobox.AppendText(delim)
	}
	combobox.SetActive(0)
	combobox.Connect("changed", func() {
		fmt.Println("value:", combobox.GetActiveText())
		arg.delim = combobox.GetActiveText()
	})
	buttons.Add(combobox)

	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	swin := gtk.NewScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.SHADOW_IN)
	textview := gtk.NewTextView()
	// var start, end gtk.TextIter
	var end gtk.TextIter
	buffer := textview.GetBuffer()
	swin.Add(textview)

	//--------------------------------------------------------
	// Run button
	//--------------------------------------------------------
	runbutton := gtk.NewButtonWithLabel("Run")
	runbutton.Clicked(func() {
		arg.inputPath = ientry.GetText()
		arg.filterPath = fentry.GetText()
		arg.outputPath = oentry.GetText()
		num, err := getKeysearchWords(arg)
		buffer.GetStartIter(&end)
		if err != nil {
			log.Println(err)
			buffer.Insert(&end, err.Error()+"\n")
		} else {
			buffer.Insert(&end, "GoMADScan found "+strconv.Itoa(num)+
				" modification sites.\nThe result is written into "+arg.outputPath+".\n")
		}
	})
	buttons.Add(runbutton)
	framebox2.PackStart(buttons, false, false, 0)

	//--------------------------------------------------------
	// GtkVSeparator
	//--------------------------------------------------------
	vsep := gtk.NewVSeparator()
	framebox2.PackStart(vsep, false, false, 0)

	//--------------------------------------------------------
	// GtkTextView
	//--------------------------------------------------------
	framebox2.Add(swin)

	// buffer.Connect("changed", func() {
	//  // fmt.Println("changed")
	// })

	//--------------------------------------------------------
	// GtkMenuItem
	//--------------------------------------------------------
	cascademenu := gtk.NewMenuItemWithMnemonic("_File")
	menubar.Append(cascademenu)
	submenu := gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	var menuitem *gtk.MenuItem
	menuitem = gtk.NewMenuItemWithMnemonic("_Exit")
	menuitem.Connect("activate", func() {
		gtk.MainQuit()
	})
	submenu.Append(menuitem)

	cascademenu = gtk.NewMenuItemWithMnemonic("_View")
	menubar.Append(cascademenu)
	submenu = gtk.NewMenu()
	cascademenu.SetSubmenu(submenu)

	checkmenuitem := gtk.NewCheckMenuItemWithMnemonic("_Disable")
	checkmenuitem.Connect("activate", func() {
		vpaned.SetSensitive(!checkmenuitem.GetActive())
	})
	submenu.Append(checkmenuitem)

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

	menuitem = gtk.NewMenuItemWithMnemonic("_About")
	menuitem.Connect("activate", func() {
		dialog := gtk.NewAboutDialog()
		dialog.SetName("GoMADScan")
		dialog.SetProgramName("GoMADScan")
		dialog.SetAuthors(authors())
		dialog.SetLicense("LGPL v3")
		dialog.SetWrapLicense(true)
		dialog.Run()
		dialog.Destroy()
	})
	submenu.Append(menuitem)

	//--------------------------------------------------------
	// GtkStatusbar
	//--------------------------------------------------------
	statusbar := gtk.NewStatusbar()
	context_id := statusbar.GetContextId("GoMADScan v0")
	statusbar.Push(context_id, "Simple search GUI")

	framebox2.PackStart(statusbar, false, false, 0)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()
	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()
}