summary refs log tree commit diff
path: root/GtkUI.py
blob: 9d68fccabe74b3d8c6eba3d38d292666ba9ca017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#This is part of Blather
# -- this code is licensed GPLv3
# Copyright 2013 Jezra
import sys
import gobject
#Gtk
import pygtk
import gtk

class UI(gobject.GObject):
	__gsignals__ = {
		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
	}
	
	def __init__(self,args):
		gobject.GObject.__init__(self)
		#make a window
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.connect("delete_event", self.delete_event)
		#give the window a name
		self.window.set_title("BlatherGtk")
		self.window.set_resizable(False)
		
		layout = gtk.VBox()
		self.window.add(layout)
		#make a listen/stop button
		self.lsbutton = gtk.Button("Listen")
		layout.add(self.lsbutton)
		#make a continuous button
		self.ccheckbox = gtk.CheckButton("Continuous Listen")
		layout.add(self.ccheckbox)
		
		#connect the buttonsc
		self.lsbutton.connect("clicked",self.lsbutton_clicked)
		self.ccheckbox.connect("clicked",self.ccheckbox_clicked)
		
		#add a label to the UI to display the last command
		self.label = gtk.Label()
		layout.add(self.label)
	
	def ccheckbox_clicked(self, widget):
		checked = self.ccheckbox.get_active()
		self.lsbutton.set_sensitive(not checked)
		if checked:
			self.lsbutton_stopped()
			self.emit('command', "continuous_listen")
		else:
			self.emit('command', "continuous_stop")
	
	def lsbutton_stopped(self):
		self.lsbutton.set_label("Listen")
		
	def lsbutton_clicked(self, button):
		val = self.lsbutton.get_label()
		if val == "Listen":
			self.emit("command", "listen")
			self.lsbutton.set_label("Stop")
			#clear the label
			self.label.set_text("")
		else:
			self.lsbutton_stopped()
			self.emit("command", "stop")
			
	def run(self):
		self.window.show_all()
	
	def quit(self):
		pass
	
	def delete_event(self, x, y ):
		self.emit("command", "quit")
		
	def finished(self, text):
		print text
		#if the continuous isn't pressed
		if not self.ccheckbox.get_active():
			self.lsbutton_stopped()
		self.label.set_text(text)