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 baud = self.builder.get_object("baudrate")
70 parity = self.builder.get_object("parity")
71 datab = self.builder.get_object("databits")
72 stopb = self.builder.get_object("stopbits")
73 baud.set_value(self.config.baudrate)
74 parity.set_text(self.config.parity)
75 datab.set_value(self.config.databits)
76 stopb.set_value(self.config.stopbits)
79 user = self.builder.get_object("username")
80 pwd = self.builder.get_object("password")
81 api = self.builder.get_object("apikey")
82 user.set_text(self.config.username)
83 pwd.set_text(self.config.password)
84 api.set_text(self.config.apikey)
86 # TODO - send changes back to config
88 def update(self, state):
89 def setxyz(objs, vals):
90 if vals[0]: objs[0].set_text('X: %f' % vals[0])
91 if vals[1]: objs[1].set_text('Y: %f' % vals[1])
92 if vals[2]: objs[2].set_text('Z: %f' % vals[2])
93 def setabs(objs, vals):
94 for i in range(0,len(objs)):
95 if vals[i]: objs[i].set_text('%f' % vals[i])
97 setxyz(self.accs, state.acc)
98 setxyz(self.mags, state.mag)
99 setabs(self.touch, state.touch)
100 setabs(self.light, state.light)
101 setabs(self.a2ds, state.a2d)
103 def debug(self, state):
104 print 'update: ' + str(state)
105 print '\tacc - ' + str(state.acc)
106 print '\tmag - ' + str(state.mag)
107 print '\tlgt - ' + str(state.light)
108 print '\ttch - ' + str(state.touch)
109 print '\ta2d - ' + str(state.a2d)
112 serial = self.builder.get_object("serial_btn")
113 status = self.builder.get_object("conn")
115 if self.device.running():
116 serial.set_active(True)
117 status.set_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_BUTTON)
119 serial.set_active(False)
120 status.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_BUTTON)
121 if self.device.running():
122 for item in self.device.process():
131 gtk.timeout_add(1000/60, self.timer)
135 def status(self, msg):
138 status = self.builder.get_object("status")
139 status.push(text=('Error: ' + msg), context_id=0)