Ejemplo n.º 1
0
func main() {
	gtk.Init(&os.Args)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("GTK Table")
	window.Connect("destroy", gtk.MainQuit)

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

	table := gtk.NewTable(5, 5, false)
	for y := uint(0); y < 5; y++ {
		for x := uint(0); x < 5; x++ {
			table.Attach(gtk.NewButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)), x, x+1, y, y+1, gtk.FILL, gtk.FILL, 5, 5)
		}
	}
	swin.AddWithViewPort(table)

	window.Add(swin)
	window.SetDefaultSize(200, 200)
	window.ShowAll()

	gtk.Main()
}
Ejemplo n.º 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()
}
Ejemplo n.º 3
0
// Login creates a GTK fullscreen window where users can log inn.
// It returns when a user successfully authenticates.
func Login(hostAPI, client string, extraMinutes, agel, ageh int) (user string, minutes int, userType 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())
	button := gtk.NewButtonWithLabel("Logg inn")
	userlabel := gtk.NewLabel("Lånenummer/brukernavn")
	pinlabel := gtk.NewLabel("PIN-kode/passord")
	table := gtk.NewTable(3, 2, false)
	userentry := gtk.NewEntry()
	userentry.SetMaxLength(10)
	userentry.SetSizeRequest(150, 23)
	pinentry := gtk.NewEntry()
	pinentry.SetVisibility(false)
	pinentry.SetMaxLength(10)

	table.Attach(userlabel, 0, 1, 0, 1, gtk.FILL, gtk.FILL, 7, 5)
	table.Attach(userentry, 1, 2, 0, 1, gtk.FILL, gtk.FILL, 7, 5)
	table.Attach(pinlabel, 0, 1, 1, 2, gtk.FILL, gtk.FILL, 7, 5)
	table.Attach(pinentry, 1, 2, 1, 2, gtk.FILL, gtk.FILL, 7, 5)
	table.Attach(button, 1, 2, 2, 3, gtk.FILL, gtk.FILL, 7, 5)

	error := gtk.NewLabel("")

	vbox := gtk.NewVBox(false, 20)
	vbox.SetBorderWidth(20)
	vbox.Add(logo)
	vbox.Add(table)
	vbox.Add(error)

	frame.Add(vbox)

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

	// Functions to validate and check responses
	checkResponse := func(username, password string) {
		user, err := authenticate(hostAPI, username, password)
		if err != nil {
			log.Println("authentication API call failed: ", err)
			//error.SetMarkup("<span foreground='red'>Fikk ikke kontakt med server, vennligst prøv igjen!</span>")
			error.SetMarkup("<span foreground='red'>Feil lånenummer/brukernavn eller PIN/passord</span>")
			return
		}
		if !user.Authenticated {
			error.SetMarkup("<span foreground='red'>" + user.Message + "</span>")
			return
		}
		if user.Minutes+extraMinutes <= 0 && user.Type != "G" {
			error.SetMarkup("<span foreground='red'>Beklager, du har brukt opp kvoten din for i dag!</span>")
			return
		}
		if user.Type == "G" && user.Minutes <= 0 {
			error.SetMarkup("<span foreground='red'>Beklager, du har brukt opp kvoten din for i dag!</span>")
			return
		}
		if user.Age < agel || user.Age > ageh {
			error.SetMarkup("<span foreground='red'>Denne maskinen er kun for de mellom " +
				strconv.Itoa(agel) + " og " + strconv.Itoa(ageh) + "</span>")
			return
		}

		// sucess!
		userType = user.Type
		minutes = user.Minutes

		// set printer billing
		//LNUMMER
		cmd := exec.Command("/bin/sh", "-c", "/usr/bin/lpoptions -p publikumsskriver -o job-billing="+username)
		output, err := cmd.CombinedOutput()
		if err != nil {
			log.Println("failed to set printer billing options: ", string(output))
		}

		gtk.MainQuit()
		return
	}
	validate := func(ctx *glib.CallbackContext) {
		arg := ctx.Args(0)
		kev := *(**gdk.EventKey)(unsafe.Pointer(&arg))
		username := userentry.GetText()
		password := pinentry.GetText()
		if kev.Keyval == gdk.KEY_Return {
			if username == "" && password == "" {
				return
			}
			if username != "" && password == "" {
				pinentry.GrabFocus()
				return
			}
			if password != "" && username == "" {
				userentry.GrabFocus()
				return
			}
			checkResponse(username, password)
			return
		}
	}

	// Connect GUI event signals to function callbacks
	pinentry.Connect("key-press-event", validate)
	userentry.Connect("key-press-event", validate)
	button.Connect("clicked", func() {
		username := userentry.GetText()
		password := pinentry.GetText()
		if (username == "") || (password == "") {
			error.SetMarkup("<span foreground='red'>Skriv inn ditt lånenummer og PIN-kode</span>")
			userentry.GrabFocus()
			return
		}
		checkResponse(username, password)
	})
	window.Connect("delete-event", func() bool {
		return true
	})

	window.ShowAll()
	gtk.Main()
	user = userentry.GetText()
	return
}
Ejemplo n.º 4
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()
}
Ejemplo n.º 5
0
// Frame - Operations
// This frame contains operations.
//  	ADD, SUB, MUL, DIV, MOD
//  	AND, OR, XOR, NOT
//  	LSHFT, RSHFT
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
func (this *UI) init_Oper() {
	// In this function, the designated frame is Oper_Frame
	_Frame := this.Oper_Frame
	if _Frame == nil {
		panic("UI::init_Oper() : nil Frame received")
	}

	// (inner) Box of Operations
	fm_oper_box := gtk.NewVBox(false, 1)
	if fm_oper_box == nil {
		panic("UI::init_Nums() : VBox allocation Failed")
	}

	_Frame.Add(fm_oper_box)

	tbl_opers := gtk.NewTable(5, 3, false)
	if tbl_opers == nil {
		panic("UI::init_Nums() : Table allocation Failed")
	}

	// Operation Buttons
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

	// '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)
		}
	}

	// "Do calculate" button!
	btn_done := button("=")
	tbl_opers.Attach(btn_done, uint(4), uint(4)+1, uint(2), uint(2)+1,
		gtk.FILL, gtk.FILL, 1, 1)

	// Insert all buttons to button map
	this.Btn_map["="] = btn_done

	this.Btn_map["ADD"] = oper_arit[0]
	this.Btn_map["SUB"] = oper_arit[1]
	this.Btn_map["MUL"] = oper_arit[2]
	this.Btn_map["DIV"] = oper_arit[3]
	this.Btn_map["MOD"] = oper_arit[4]
	this.Btn_map["AND"] = oper_bit[0]
	this.Btn_map["OR"] = oper_bit[1]
	this.Btn_map["XOR"] = oper_bit[2]
	this.Btn_map["NOT"] = oper_bit[3]
	this.Btn_map["LSHFT"] = oper_shft[0]
	this.Btn_map["RSHFT"] = oper_shft[1]
	fm_oper_box.Add(tbl_opers)

	fmt.Println("UI::init_Oper() done.")
}
Ejemplo n.º 6
0
// Frame - Numbers
// This frame contains number buttons for calculation
//  	Hexadecimal	: 0 ~ 9, A ~ F
//  	Decimal   	: 0 ~ 9
//  	Octal     	: 0 ~ 7
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
func (this *UI) init_Nums() {
	// In this function, the designated frame is Nums_Frame
	_Frame := this.Nums_Frame

	if _Frame == nil {
		panic("UI::init_Nums() : nil Frame received")
	}

	// (inner) Box of Numbers
	fm_nums_box := gtk.NewVBox(false, 1)
	if fm_nums_box == nil {
		panic("UI::init_Nums() : VBox allocation Failed")
	}
	// Add to given frame
	_Frame.Add(fm_nums_box)

	// Table Initialization
	// ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
	tbl_nums := gtk.NewTable(5, 4, false)
	if tbl_nums == nil {
		panic("UI::init_Nums() : Table allocation Failed")
	}
	// Jagged slice of buttons?
	// nums := [][]*gtk.Button{}

	// Button for Number
	num := [...]*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"),
		// A~F : Hex
		button("A"), button("B"), button("C"),
		button("D"), button("E"), button("F"),
	}

	// Insert all Buttons to map
	for idx, btn := range num {
		//fmt.Println("UI::init_Nums() : Index :\t", idx, "Button :\t", btn.GetLabel())
		s_idx := strconv.Itoa(idx)
		this.Btn_map[s_idx] = btn
	}

	// 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)
	fmt.Println("UI::init_Nums() done.")
}