Serial port data integrity
[armadillo_software.git] / gui / main.py
blob2f9606c7af003d6c5b673325c510479aca0a97ed
1 #!/usr/bin/env python
2 import pygtk
3 pygtk.require("2.0")
4 import sys
5 import gtk
6 from com import COM
7 import re
9 class Main:
10 def __init__(self):
11 builder = gtk.Builder()
12 builder.add_from_file(conf.d['glade_file'])
13 self.window = builder.get_object("window1")
14 self.about = builder.get_object("aboutdialog1")
15 self.tbconnect=builder.get_object("tbconnect")
16 self.preferences_dialog=builder.get_object("preferences_dialog")
17 self.preferences_dialog_align= builder.get_object("preferences_dialog_vbox")
18 self.pd_entry=builder.get_object("pd_entry")
19 self.pd_cb=builder.get_object("pd_cb")
20 self.pd_cb_liststore=builder.get_object("pd_cb_liststore")
21 self.l_message=builder.get_object("l_message")
22 self.statusbar=builder.get_object("statusbar1")
23 self.console_view=builder.get_object("console_view")
24 self.console_text=builder.get_object("console_text")
25 builder.connect_signals(self)
27 self.com=COM(read_cbf=self.read_cbf)
28 self.tbconnect.set_active(True)
29 self.pd_init()
30 def read_cbf(self,data):
31 if(data[0]=='s'):
32 if(len(data)>12):
33 #self.l_message.set_text(''.join(data))
34 str=''.join(data)
35 str=re.split('[^0-9]', str)
36 self.statusbar.push(0,''.join(str)+' seconds')
37 if(data[0]=='$'):
38 str=''.join(data)
39 ct=self.console_text
40 enditer = ct.get_end_iter()
41 ct.insert(enditer, str)
42 def on_btsend_clicked(self, widget, data=None):
43 self.com.write("id?\r")
44 def on_tbconnect_clicked(self, widget, data=None):
45 if widget.get_active():
46 self.com.connect()
47 widget.set_label("Connected")
48 else:
49 self.com.disconnect()
50 widget.set_label(" Closed")
51 def on_pd_cb_changed(self, widget, data=None):
52 entry=self.pd_entry #Preferences dialog combobox
53 cb=self.pd_cb
54 active=cb.get_active_text()
55 entry.set_text(conf.d[active])
56 def pd_init(self):
57 cb=self.pd_cb #Fill in preferences dialog
58 liststore = self.pd_cb_liststore
59 for item in conf.d:
60 liststore.append([item])
61 cb.set_model(liststore)
62 cb.set_text_column(0)
63 cb.set_active(0)
64 def on_preferences_dialog_show(self, widget, data=None):
65 self.preferences_dialog.show()
66 def on_pd_set_bt_clicked(self, widget, data=None):
67 entry=self.pd_entry
68 cb=self.pd_cb
69 active=cb.get_active_text()
70 conf.d[active]=entry.get_text()
71 conf.save()
72 def on_pd_close_bt_clicked(self, widget, data=None):
73 self.preferences_dialog.hide()
74 def on_window1_destroy(self, widget, data=None):
75 try:
76 self.com.close()
77 except:
78 a=0
79 gtk.main_quit()
80 def on_aboutdialog1_show(self, widget, data=None):
81 self.about.show()
82 def on_aboutdialog1_response(self, widget, data=None):
83 self.about.hide()
85 class STD:
86 def __init__(self,file):
87 self.file=file
88 def write(self,arg=None):
89 self.file.write(arg)
90 sys.__stdout__.write(arg)
92 class Configure:
93 def __init__(self):
94 import pickle
95 self.p=pickle
96 self.load()
97 d=self.d
98 if d['mod']=="debug":
99 f=open(d['debug_file'],"w")
100 sys.stdout=STD(f)
101 sys.stderr=sys.stdout
102 def load(self):
103 pickle=self.p
104 fpickle=open('config.pickle','r')
105 self.d=pickle.load(fpickle) # Dictionary
106 fpickle.close()
107 def save(self):
108 pickle=self.p
109 fpickle=open('config.pickle','w')
110 #self.d['newitem']='newvalue'
111 pickle.dump(self.d, fpickle) # Dictionary
112 fpickle.close()
114 conf=Configure()
116 if __name__=="__main__":
117 gtk.gdk.threads_init()
118 app=Main()
119 app.window.show()
120 gtk.gdk.threads_enter()
121 gtk.main()
122 gtk.gdk.threads_leave()
123 #gtk.threads_enter()
124 #gtk.threads_leave()