7 def __init__(self, config, device, xively):
8 def get_objects(names):
10 self.builder.get_object(x), names)
15 self.builder = gtk.Builder()
17 self.builder.add_from_file('visual.ui')
18 self.builder.connect_signals(self)
19 self.window = self.builder.get_object("window")
20 self.settings = self.builder.get_object("settings")
22 self.accs = get_objects(['accx', 'accy', 'accz'])
23 self.mags = get_objects(['magx', 'magy', 'magz'])
24 self.touch = get_objects(['touch'])
25 self.light = get_objects(['light'])
26 self.a2ds = get_objects(['a2d0', 'a2d1', 'a2d2', 'a2d3', 'a2d4', 'a2d5'])
29 def on_hide(self, win, *args):
33 def on_show(self, act):
37 def on_serial(self, act):
39 self.status(self.device.connect())
41 self.status(self.device.disconnect())
44 def on_xively(self, act):
46 self.status(self.xively.connect())
48 self.status(self.xively.disconnect())
51 def on_enable(self, _):
52 print "Unimplemented: on_enable"
56 print "Unimplemented: on_rate"
59 def on_key(self, win, ev):
63 def on_destroy(self, win):
67 def load_config(self):
69 device = self.builder.get_object("device")
70 baud = self.builder.get_object("baudrate")
71 parity = self.builder.get_object("parity")
72 datab = self.builder.get_object("databits")
73 stopb = self.builder.get_object("stopbits")
74 device.set_text(self.config.device)
75 baud.set_value(self.config.baudrate)
76 parity.set_text(self.config.parity)
77 datab.set_value(self.config.databits)
78 stopb.set_value(self.config.stopbits)
81 user = self.builder.get_object("username")
82 pwd = self.builder.get_object("password")
83 api = self.builder.get_object("apikey")
84 user.set_text(self.config.username)
85 pwd.set_text(self.config.password)
86 api.set_text(self.config.apikey)
88 # TODO - send changes back to config
90 def update(self, state):
91 def setxyz(objs, vals):
92 if vals[0]: objs[0].set_text('X: %f' % vals[0])
93 if vals[1]: objs[1].set_text('Y: %f' % vals[1])
94 if vals[2]: objs[2].set_text('Z: %f' % vals[2])
95 def setabs(objs, vals):
96 for i in range(0,len(objs)):
97 if vals[i]: objs[i].set_text('%f' % vals[i])
99 setxyz(self.accs, state.acc)
100 setxyz(self.mags, state.mag)
101 setabs(self.touch, state.touch)
102 setabs(self.light, state.light)
103 setabs(self.a2ds, state.a2d)
105 def debug(self, state):
106 print 'update: ' + str(state)
107 print '\tacc - ' + str(state.acc)
108 print '\tmag - ' + str(state.mag)
109 print '\tlgt - ' + str(state.light)
110 print '\ttch - ' + str(state.touch)
111 print '\ta2d - ' + str(state.a2d)
114 serial = self.builder.get_object("serial_btn")
115 status = self.builder.get_object("conn")
117 if self.device.running():
118 serial.set_active(True)
119 status.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON)
121 serial.set_active(False)
122 status.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_BUTTON)
123 if self.device.running():
124 for item in self.device.process():
133 gtk.timeout_add(1000/60, self.timer)
137 def status(self, msg):
140 status = self.builder.get_object("status")
141 status.push(text=('Error: ' + msg), context_id=0)