Exemplo n.º 1
0
Arquivo: dmxd.go Projeto: uvgroovy/dmx
func main() {
	libusb.Init()
	// Todo check for errors

	dmxControllers := k8062.GetDmxControlers()
	fmt.Printf("Got %d devices\n", len(dmxControllers))

	checkForErrors(dmxControllers)
	// yuval
	if os.Getenv("OSC_TEST") != "" {
		if len(dmxControllers) == 0 {
			return
		}
	}

	for _, d := range dmxControllers {
		defer d.Close()
	}
	gui := true
	if gui {
		dmxControllers = append(dmxControllers, <-GetGuiController())
		gdk.ThreadsInit()
	}

	lightFixtures := openFixtures()

	keyframes := getKeyFrames()

	setupOsc()

	worker(keyframes, dmxControllers, lightFixtures)

}
Exemplo n.º 2
0
func main() {
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gtk.Init(nil)
	runGUI([]string{os.Getenv("SHELL")})

}
Exemplo n.º 3
0
func main() {
	gtk.Init(nil)
	gdk.ThreadsInit()
	MainGui.buildSplash()
	MainGui.buildGUI()
	MainGui.SplashWindow.ShowAll()
	go unlinked_main()
	gtk.Main()
}
Exemplo n.º 4
0
func main() {
	if debug {
		logging.SetLogging("DEBUG")
	} else {
		logging.SetLogging("INFO")
	}
	log.Printf("[INFO] Start Actarus")
	runtime.GOMAXPROCS(runtime.NumCPU())
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gtk.Init(nil)
	runGUI()
}
Exemplo n.º 5
0
Arquivo: main.go Projeto: kch42/biomed
func main() {
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)

	gui := new(GUI)
	gui.Init()
	gui.Show()

	gtk.Main()
	gdk.ThreadsLeave()
}
Exemplo n.º 6
0
Arquivo: main.go Projeto: udhos/tabby
func main() {
	gdk.ThreadsInit()
	if false == init_args() {
		return
	}
	load_options()
	defer save_options()

	gdk.ThreadsEnter()
	gtk.Init(nil)
	init_tabby()
	gtk.Main()
}
Exemplo n.º 7
0
Arquivo: webkit.go Projeto: zackb/code
func InitWebKit() {
	gtk.Init(nil)
	gdk.ThreadsInit()
	c = make(chan bool, 2)
	gdk.ThreadsEnter()
	webview = CreateWebView(func() {
		fmt.Printf("HEEEERLoad Finished\n")
		c <- true
	})
	gdk.ThreadsLeave()

	go func() {
		gdk.ThreadsEnter()
		gtk.Main()
		gdk.ThreadsLeave()
	}()
}
Exemplo n.º 8
0
func Startup() {
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	initializeEnvironment()
	gtk.Init(nil)

	window := windows.MainWindow()
	window.ShowAll()

	config := models.Config()
	if config.AccessToken == "" {
		authWindow := windows.AuthWindow()
		authWindow.ShowAll()
	}

	gtk.Main()
}
Exemplo n.º 9
0
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()
}
Exemplo n.º 10
0
func main() {
	runtime.GOMAXPROCS(10)
	glib.ThreadInit(nil)
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	gtk.Init(nil)
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	label1 := gtk.NewLabel("")
	vbox.Add(label1)
	label2 := gtk.NewLabel("")
	vbox.Add(label2)

	window.Add(vbox)

	window.SetSizeRequest(100, 100)
	window.ShowAll()
	time.Sleep(1000 * 1000 * 100)
	go (func() {
		for i := 0; i < 300000; i++ {
			gdk.ThreadsEnter()
			label1.SetLabel(strconv.Itoa(i))
			gdk.ThreadsLeave()
		}
		gtk.MainQuit()
	})()
	go (func() {
		for i := 300000; i >= 0; i-- {
			gdk.ThreadsEnter()
			label2.SetLabel(strconv.Itoa(i))
			gdk.ThreadsLeave()
		}
		gtk.MainQuit()
	})()
	gtk.Main()
}
Exemplo n.º 11
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()
}
Exemplo n.º 12
0
func main() {
	hostAPI := flag.String("api", "http://mycel:9000", "mycel host (api)")
	hostWS := flag.String("ws", "ws://mycel:9001", "mycel host (ws)")
	flag.Parse()

	// Get the Mac-address of client
	eth0, err := ioutil.ReadFile("/sys/class/net/eth0/address")
	if err != nil {
		log.Fatal(err)
	}
	MAC := strings.TrimSpace(string(eth0))

	// Identify the client
	var client *Client
	for {
		client, err = identify(*hostAPI, MAC)
		if err != nil {
			if err.Error() == "404 Not Found" {
				log.Fatal("client MAC address not found in mycel DB: ", MAC)
			}
			log.Println("Couldn't reach Mycel server. Trying again in 1 seconds...")
			time.Sleep(1 * time.Second)
			continue
		}
		break
	}

	// Do local modifications to the client's environment

	// 1. Screen Resolution
	if client.ScreenRes != "auto" {
		xrandr, err := exec.Command("/usr/bin/xrandr").Output()
		if err != nil {
			log.Println("failed to run xrandr", err)
		}
		rgx := regexp.MustCompile(`([\w]+)\sconnected`)
		display := rgx.FindSubmatch(xrandr)[1]
		cmd := exec.Command("/bin/sh", "-c", "/usr/bin/xrandr --output "+string(display)+" --mode "+client.ScreenRes)
		output, err := cmd.CombinedOutput()
		if err != nil {
			log.Println("failed to set screen resolution: ", string(output))
		}
	}

	// 2. Firefox homepage
	if client.Options.Homepage != nil {
		escHomepage := strings.Replace(*client.Options.Homepage, `/`, `\/`, -1)

		sed := `/bin/sed -i 's/user_pref("browser.startup.homepage",.*/user_pref("browser.startup.homepage","` +
			escHomepage + `");/' $HOME/.mozilla/firefox/*.default/prefs.js`
		cmd := exec.Command("/bin/sh", "-c", sed)
		output, err := cmd.CombinedOutput()
		if err != nil {
			log.Println("failed to set Firefox startpage: ", string(output))
		}
	}

	// 3. Printer address
	if client.Options.Printer != nil {
		cmd := exec.Command("/bin/sh", "-c", "/usr/bin/sudo -n /usr/sbin/lpadmin -p publikumsskriver -v "+*client.Options.Printer)
		output, err := cmd.CombinedOutput()
		if err != nil {
			log.Println("failed to set network printer address:", string(output))
		}
	}

	// Get today's closing time from client API response
	var hm string
	now := time.Now()
	switch now.Weekday() {
	case time.Monday:
		hm = *client.Options.Hours.MonCl
	case time.Tuesday:
		hm = *client.Options.Hours.TueCl
	case time.Wednesday:
		hm = *client.Options.Hours.WedCl
	case time.Thursday:
		hm = *client.Options.Hours.ThuCl
	case time.Friday:
		hm = *client.Options.Hours.FriCl
	case time.Saturday:
		hm = *client.Options.Hours.SatCl
	case time.Sunday:
		hm = *client.Options.Hours.SunCl
	}

	// Convert closing time to datetime
	hour, _ := strconv.Atoi(hm[0:2])
	min, _ := strconv.Atoi(hm[3:])
	closingTime := time.Date(now.Year(), now.Month(), now.Day(), hour, min-*client.Options.Hours.Min, 0, 0, time.Local)

	// Show login screen
	gtk.Init(nil)
	var user, userType string
	var userMinutes, extraMinutes int
	if client.ShortTime {
		userMinutes = *client.Options.ShortTimeLimit
		extraMinutes = 0
		user = window.ShortTime(client.Name, userMinutes)
	} else {
		extraMinutes = *client.Options.Minutes - DefaultMinutes
		user, userMinutes, userType = window.Login(*hostAPI, client.Name, extraMinutes, *client.Options.AgeL, *client.Options.AgeH)
		if userType == "G" {
			// If guest user, minutes is user.minutes left or the minutes limit on the client
			tempMinutes := int(math.Min(float64(userMinutes), float64(*client.Options.Minutes)))
			extraMinutes = tempMinutes - userMinutes
		}
	}

	// Calculate how long until closing time.
	// Adjust minutes acording to closing hours, so that maximum minutes does
	// not exceed available minutes until closing
	untilClose := int(closingTime.Sub(now).Minutes())
	if userMinutes+extraMinutes > untilClose {
		extraMinutes = untilClose - userMinutes
	}

	// Show status window
	conn := connect(*hostWS, user, client.Id)
	gdk.ThreadsInit()
	status := new(window.Status)

	status.Init(client.Name, user, userMinutes+extraMinutes)
	status.Show()
	status.Move()

	// goroutine to check for websocket messages and update status window
	// with number of minutes left
	go func() {
		var msg message
		for {
			err := websocket.JSON.Receive(conn, &msg)
			if err != nil {
				if err == io.EOF {
					println("ws disconnected")
					// reconnect
					conn = connect(*hostWS, user, client.Id)
				}
				continue
			}

			if msg.Status == "ping" {
				if msg.User.Minutes+extraMinutes <= 0 {
					gtk.MainQuit()
				}
				gdk.ThreadsEnter()
				status.SetMinutes(msg.User.Minutes + extraMinutes)
				gdk.ThreadsLeave()
			}
		}
	}()

	// This blocks until the 'logg out' button is clicked, or until the user
	// has spent all minutes
	gtk.Main()

	// Send log-out message to server
	logOffMsg := logOnOffMessage{Action: "log-off", Client: client.Id, User: user}
	err = websocket.JSON.Send(conn, logOffMsg)
	if err != nil {
		// Don't bother to resend. Server will log off user anyway, when the
		// connection is closed
	}

	// Force session restart
	cmd := exec.Command("/bin/sh", "-c", "/usr/bin/killall /usr/bin/lxsession")
	err = cmd.Run()
}
Exemplo n.º 13
0
func Gui() {
	//--------------------------------------------------------
	// Setting up the GTK-Foo
	//--------------------------------------------------------
	gdk.ThreadsInit()
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Zwitscher!")
	window.Connect("destroy", func() {
		gtk.MainQuit()
	})

	vbox := gtk.VBox(false, 1)
	notebook := gtk.Notebook()

	//--------------------------------------------------------
	// Home View
	//--------------------------------------------------------
	vboxHome := gtk.VBox(false, 1)
	scrolledWinHome := gtk.ScrolledWindow(nil, nil)
	//Disable hscrollbar, enable vscrollbar
	scrolledWinHome.SetPolicy(gtk.GTK_POLICY_NEVER, gtk.GTK_POLICY_ALWAYS)
	vboxHome.Add(scrolledWinHome)
	vboxScrolledWinHome := gtk.VBox(false, 1)
	scrolledWinHome.AddWithViewPort(vboxScrolledWinHome)

	tweetwidgets := []*gtk.GtkFrame{}
	buttonUpdateTimeline := gtk.ButtonWithLabel("Update Timeline")
	buttonUpdateTimeline.Clicked(func() {
		var tweet gotter.Tweet
		tweets, err := gotter.GetTweets(accounts.Credentials, "https://api.twitter.com/1/statuses/home_timeline.json", map[string]string{})
		if err != nil {
			println("failed to get tweets:", err.String())
			return
		}
		for i := len(tweets) - 1; i >= 0; i-- {
			tweet = tweets[i]
			id, _ := strconv.Atoi64(tweet.Identifier)
			if accounts.Maxreadid < id {
				if len(tweetwidgets) > 20 {
					tweetwidgets[0].Destroy()
					tweetwidgets = tweetwidgets[1:]
				}
				tweetwidget := TweetWidget(tweet)
				vboxScrolledWinHome.PackEnd(tweetwidget, false, false, 0)
				tweetwidget.ShowAll()
				tweetwidgets = append(tweetwidgets, tweetwidget)
				accounts.Maxreadid = id
			}
		}
	})
	vboxHome.PackEnd(buttonUpdateTimeline, false, false, 0)
	notebook.AppendPage(vboxHome, gtk.Label("Home"))

	//--------------------------------------------------------
	// Mentions View
	//--------------------------------------------------------
	scrolledwin := gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Mentions"))

	//--------------------------------------------------------
	// Messages View
	//--------------------------------------------------------
	scrolledwin = gtk.ScrolledWindow(nil, nil)
	notebook.AppendPage(scrolledwin, gtk.Label("Messages"))

	vbox.Add(notebook)

	//--------------------------------------------------------
	// Fild for Tweets
	//--------------------------------------------------------
	hbox := gtk.HBox(false, 1)

	dir, _ := filepath.Split(os.Args[0])
	imagefile := filepath.Join(dir, "Awesome Smiley Original.jpg")
	image := gtk.ImageFromFile(imagefile)
	hbox.PackStart(image, false, false, 0)

	buttonZwitscher := gtk.ButtonWithLabel("Zwitscher!")
	newTweetTextField := gtk.Entry()
	charCounterLabel := gtk.Label("140")

	buttonZwitscher.SetTooltipMarkup("Tweet")

	buttonZwitscher.Clicked(func() {
		charCounterLabel.SetLabel("140")
		SendTweet(newTweetTextField.GetText())
		newTweetTextField.SetText("")
	})

	newTweetTextField.Connect("key-release-event", func() {
		length := utf8.RuneCountInString(newTweetTextField.GetText())
		charCounterLabel.SetLabel((string)(strconv.Itoa(140 - length)))
	})

	newTweetTextField.Connect("activate", func() {
		if newTweetTextField.GetText() != "" { //pressed enter, and text is not empty
			charCounterLabel.SetLabel("140")
			SendTweet(newTweetTextField.GetText())
			newTweetTextField.SetText("")
		}
	})
	hbox.PackStartDefaults(newTweetTextField)
	hbox.PackStart(charCounterLabel, false, false, 0)
	hbox.PackEnd(buttonZwitscher, false, false, 0)

	vbox.PackEnd(hbox, false, false, 0)

	//--------------------------------------------------------
	// Event
	//--------------------------------------------------------
	window.Add(vbox)
	window.SetSizeRequest(400, 550)
	window.ShowAll()

	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
Exemplo n.º 14
0
Arquivo: main.go Projeto: mattn/tabby
func init_tabby() {
	init_navigation()
	gdk.ThreadsInit()
	init_inotify()

	search_view.Init()

	source_buf = gtk.SourceBuffer()
	source_buf.Connect("paste-done", paste_done_cb, nil)
	source_buf.Connect("mark-set", mark_set_cb, nil)
	source_buf.Connect("changed", buf_changed_cb, nil)

	init_lang()

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

	tree_store = gtk.TreeStore(gtk.GTK_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.TextView()
	error_view.ModifyFontEasy("Monospace Regular 8")
	error_view.SetEditable(false)
	error_buf = error_view.GetBuffer()

	source_view = gtk.SourceViewWithBuffer(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(gtk.GTK_SOURCE_DRAW_SPACES_TAB)
	source_view.SetSmartHomeEnd(gtk.GTK_SOURCE_SMART_HOME_END_ALWAYS)
	source_view.SetWrapMode(gtk.GTK_WRAP_WORD)

	vbox := gtk.VBox(false, 0)
	inner_hpaned := gtk.HPaned()
	view_vpaned := gtk.VPaned()
	outer_hpaned := gtk.HPaned()
	outer_hpaned.Add1(inner_hpaned)
	inner_hpaned.Add2(view_vpaned)

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

	file_item := gtk.MenuItemWithMnemonic("_File")
	menubar.Append(file_item)
	file_submenu := gtk.Menu()
	file_item.SetSubmenu(file_submenu)

	accel_group := gtk.AccelGroup()

	new_item := gtk.MenuItemWithMnemonic("_New")
	file_submenu.Append(new_item)
	new_item.Connect("activate", new_cb, nil)
	new_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_n,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	open_item := gtk.MenuItemWithMnemonic("_Open")
	file_submenu.Append(open_item)
	open_item.Connect("activate", open_cb, nil)
	open_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_o,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

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

	save_item := gtk.MenuItemWithMnemonic("_Save")
	file_submenu.Append(save_item)
	save_item.Connect("activate", save_cb, nil)
	save_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_s,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

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

	close_item := gtk.MenuItemWithMnemonic("_Close")
	file_submenu.Append(close_item)
	close_item.Connect("activate", close_cb, nil)
	close_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_w,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

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

	navigation_item := gtk.MenuItemWithMnemonic("_Navigation")
	menubar.Append(navigation_item)
	navigation_submenu := gtk.Menu()
	navigation_item.SetSubmenu(navigation_submenu)

	prev_instance_item := gtk.MenuItemWithMnemonic("_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.GDK_KEY_F2,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_instance_item := gtk.MenuItemWithMnemonic("_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.GDK_KEY_F3,
		0, gtk.GTK_ACCEL_VISIBLE)

	prev_result_item := gtk.MenuItemWithMnemonic("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.GDK_KEY_F4,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_result_item := gtk.MenuItemWithMnemonic("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.GDK_KEY_F5,
		0, gtk.GTK_ACCEL_VISIBLE)

	find_item := gtk.MenuItemWithMnemonic("_Find")
	navigation_submenu.Append(find_item)
	find_item.Connect("activate", find_cb, nil)
	find_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_f,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	find_file_item := gtk.MenuItemWithMnemonic("_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.GDK_KEY_d,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	fnr_item := gtk.MenuItemWithMnemonic("Find and Replace")
	navigation_submenu.Append(fnr_item)
	fnr_item.Connect("activate", fnr_cb, nil)
	fnr_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_r,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	prev_file_item := gtk.MenuItemWithMnemonic("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.GDK_KEY_F7,
		0, gtk.GTK_ACCEL_VISIBLE)

	next_file_item := gtk.MenuItemWithMnemonic("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.GDK_KEY_F8,
		0, gtk.GTK_ACCEL_VISIBLE)

	tools_item := gtk.MenuItemWithMnemonic("_Tools")
	menubar.Append(tools_item)
	tools_submenu := gtk.Menu()
	tools_item.SetSubmenu(tools_submenu)

	gofmt_item := gtk.MenuItemWithMnemonic("_Gofmt")
	tools_submenu.Append(gofmt_item)
	gofmt_item.Connect("activate", gofmt_cb, nil)
	gofmt_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F9,
		0, gtk.GTK_ACCEL_VISIBLE)

	gofmtAll_item := gtk.MenuItemWithMnemonic("Gofmt _All")
	tools_submenu.Append(gofmtAll_item)
	gofmtAll_item.Connect("activate", gofmt_all, nil)
	gofmtAll_item.AddAccelerator("activate", accel_group, gdk.GDK_KEY_F9,
		int(gdk.GDK_CONTROL_MASK), gtk.GTK_ACCEL_VISIBLE)

	options_item := gtk.MenuItemWithMnemonic("_Options")
	menubar.Append(options_item)
	options_submenu := gtk.Menu()
	options_item.SetSubmenu(options_submenu)

	search_chkitem := gtk.CheckMenuItemWithMnemonic("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.CheckMenuItemWithMnemonic("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.CheckMenuItemWithMnemonic("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.MenuItemWithMnemonic("_Font")
	options_submenu.Append(font_item)
	font_item.Connect("activate", font_cb, nil)

	tabsize_item := gtk.MenuItemWithMnemonic("_Tab size")
	options_submenu.Append(tabsize_item)
	tabsize_submenu := gtk.Menu()
	tabsize_item.SetSubmenu(tabsize_submenu)
	const tabsize_cnt = 8
	tabsize_chk := make([]*gtk.GtkCheckMenuItem, tabsize_cnt)
	for y := 0; y < tabsize_cnt; y++ {
		tabsize_chk[y] = gtk.CheckMenuItemWithMnemonic(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.ScrolledWindow(nil, nil)
	tree_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	inner_hpaned.Add1(tree_window)
	tree_window.Add(tree_view)

	outer_hpaned.Add2(search_view.window)

	text_window := gtk.ScrolledWindow(nil, nil)
	text_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_ALWAYS)
	view_vpaned.Add1(text_window)
	text_window.Add(source_view)

	error_window = gtk.ScrolledWindow(nil, nil)
	error_window.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.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.Window(gtk.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()
}
Exemplo n.º 15
0
func main() {
	gtk.Init(&os.Args)
	gdk.ThreadsInit()
	window := gtk.NewWindow(gtk.WINDOW_TOPLEVEL)
	window.SetTitle("Twitter!")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.NewVBox(false, 1)

	scrolledwin := gtk.NewScrolledWindow(nil, nil)
	textview := gtk.NewTextView()
	textview.SetEditable(false)
	textview.SetCursorVisible(false)
	scrolledwin.Add(textview)
	vbox.Add(scrolledwin)

	buffer := textview.GetBuffer()

	tag := buffer.CreateTag("blue", map[string]string{
		"foreground": "#0000FF", "weight": "700"})
	button := gtk.NewButtonWithLabel("Update Timeline")
	button.SetTooltipMarkup("update <b>public timeline</b>")
	button.Clicked(func() {
		b, err := ioutil.ReadFile("settings.json")
		if err != nil {
			fmt.Println(`"settings.json" not found: `, err)
			return
		}
		var config map[string]string
		err = json.Unmarshal(b, &config)
		if err != nil {
			fmt.Println(`can't read "settings.json": `, err)
			return
		}
		client := &oauth.Client{
			Credentials: oauth.Credentials{
				config["ClientToken"], config["ClientSecret"]}}
		cred := &oauth.Credentials{
			config["AccessToken"], config["AccessSecret"]}

		gdk.ThreadsEnter()
		button.SetSensitive(false)
		gdk.ThreadsLeave()
		go func() {
			ts, err := twitterstream.Open(client, cred,
				"https://stream.twitter.com/1/statuses/filter.json",
				url.Values{"track": {"picplz,instagr"}})
			if err != nil {
				println(err.Error())
				return
			}
			for ts.Err() == nil {
				t := tweet{}
				if err := ts.UnmarshalNext(&t); err != nil {
					fmt.Println("error reading tweet: ", err)
					continue
				}
				var iter gtk.TextIter
				pixbufbytes, resp := readURL(t.User.ProfileImageUrl)
				gdk.ThreadsEnter()
				buffer.GetStartIter(&iter)
				if resp != nil {
					buffer.InsertPixbuf(&iter, bytes2pixbuf(pixbufbytes, resp.Header.Get("Content-Type")))
				}
				gdk.ThreadsLeave()
				gdk.ThreadsEnter()
				buffer.Insert(&iter, " ")
				buffer.InsertWithTag(&iter, t.User.ScreenName, tag)
				buffer.Insert(&iter, ":"+t.Text+"\n")
				gtk.MainIterationDo(false)
				gdk.ThreadsLeave()
			}
		}()
	})
	vbox.PackEnd(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()
	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
Exemplo n.º 16
0
func main() {
	gdk.ThreadsInit()
	gtk.Init(&os.Args)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("Twitter!")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.VBox(false, 1)

	scrolledwin := gtk.ScrolledWindow(nil, nil)
	textview := gtk.TextView()
	textview.SetEditable(false)
	textview.SetCursorVisible(false)
	scrolledwin.Add(textview)
	vbox.Add(scrolledwin)

	buffer := textview.GetBuffer()

	tag := buffer.CreateTag("blue", map[string]string{
		"foreground": "#0000FF", "weight": "700"})
	button := gtk.ButtonWithLabel("Update Timeline")
	button.SetTooltipMarkup("update <b>public timeline</b>")
	button.Clicked(func() {
		go func() {
			gdk.ThreadsEnter()
			button.SetSensitive(false)
			gdk.ThreadsLeave()
			r, err := http.Get("http://twitter.com/statuses/public_timeline.json")
			if err == nil {
				var b []byte
				if r.ContentLength == -1 {
					b, err = ioutil.ReadAll(r.Body)
				} else {
					b = make([]byte, r.ContentLength)
					_, err = io.ReadFull(r.Body, b)
				}
				if err != nil {
					println(err.String())
					return
				}
				var j interface{}
				json.NewDecoder(bytes.NewBuffer(b)).Decode(&j)
				arr := j.([]interface{})
				for i := 0; i < len(arr); i++ {
					data := arr[i].(map[string]interface{})
					icon := data["user"].(map[string]interface{})["profile_image_url"].(string)
					var iter gtk.GtkTextIter
					gdk.ThreadsEnter()
					buffer.GetStartIter(&iter)
					buffer.InsertPixbuf(&iter, url2pixbuf(icon))
					gdk.ThreadsLeave()
					name := data["user"].(map[string]interface{})["screen_name"].(string)
					text := data["text"].(string)
					gdk.ThreadsEnter()
					buffer.Insert(&iter, " ")
					buffer.InsertWithTag(&iter, name, tag)
					buffer.Insert(&iter, ":"+text+"\n")
					gtk.MainIterationDo(false)
					gdk.ThreadsLeave()
				}
			}
			button.SetSensitive(true)
		}()
	})
	vbox.PackEnd(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(800, 500)
	window.ShowAll()
	gdk.ThreadsEnter()
	gtk.Main()
	gdk.ThreadsLeave()
}
Exemplo n.º 17
0
Arquivo: main.go Projeto: ronindev/dms
func main() {
	runtime.LockOSThread()
	gtk.Init(&os.Args)
	gdk.ThreadsInit()

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

	vbox := gtk.NewVBox(false, 0)
	window.Add(vbox)

	hbox := gtk.NewHBox(false, 0)
	vbox.PackStart(hbox, false, true, 0)

	hbox.PackStart(gtk.NewLabel("Shared directory: "), false, true, 0)

	dialog := gtk.NewFileChooserDialog(
		"Select directory to share", window, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
		gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
		gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)

	button := gtk.NewFileChooserButtonWithDialog(dialog)
	hbox.Add(button)

	logView := gtk.NewTextView()
	logView.SetEditable(false)
	logView.ModifyFontEasy("monospace")
	logView.SetWrapMode(gtk.WRAP_WORD_CHAR)
	logViewScroller := gtk.NewScrolledWindow(nil, nil)
	logViewScroller.Add(logView)
	logViewScroller.SetPolicy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
	vbox.PackEnd(logViewScroller, true, true, 0)

	getPath := func() string {
		return button.GetFilename()
	}

	window.ShowAll()
	if dialog.Run() != gtk.RESPONSE_ACCEPT {
		return
	}
	go func() {
		dmsServer := dms.Server{
			RootObjectPath: getPath(),
		}
		if err := dmsServer.Serve(); err != nil {
			log.Fatalln(err)
		}
		defer dmsServer.Close()
		runtime.LockOSThread()
		gdk.ThreadsEnter()
		button.Connect("selection-changed", func() {
			dmsServer.RootObjectPath = getPath()
		})
		gdk.ThreadsLeave()
		runtime.UnlockOSThread()
		dmsServer.Serve()
	}()
	gtk.Main()
	runtime.UnlockOSThread()
}