28
25
def __init__( self ):
30
self.link = serial.Serial( self.SERIAL_DEVICE, 9600 )
31
self.link_error = None
32
except serial.serialutil.SerialException as e:
26
self.link = serial.Serial( self.SERIAL_DEVICE, 9600 )
35
27
self.got_one = False
36
self.motor_values = [ 0 ] * self.NUM_MOTORS
28
self.channel_values = []
38
30
self.buffer = bytearray()
41
def add_info( self, vbox, heading = False, text = '' ):
44
label.set_markup( "<b>%s</b>" % text )
46
label.set_label( text )
47
# label.set_justify( gtk.JUSTIFY_LEFT )
48
label.set_alignment( 0, 0 )
49
vbox.pack_start( label, False, False )
51
33
def setup_window( self ):
53
35
# create and set up window
59
41
self.window.set_modal( True )
60
42
self.window.connect( "key-press-event", self.key_press_event )
62
hbox = gtk.HBox( False, 10 )
63
self.window.add( hbox )
66
frame = gtk.Frame( "Channels" )
67
frame.set_shadow_type( gtk.SHADOW_IN )
68
hbox.pack_start( frame )
70
table = gtk.Table( 2, self.NUM_CHANNELS )
71
table.set_border_width( 25 )
72
table.set_row_spacings( 10 )
73
table.set_col_spacings( 15 )
45
table = gtk.Table( self.NUM_CHANNELS, 2 )
46
table.set_row_spacings( 20 )
47
table.set_col_spacings( 10 )
48
self.window.add( table )
78
for a in range( self.NUM_CHANNELS ):
52
for a in range( 0, self.NUM_CHANNELS ):
80
label = gtk.Label( a + 1 )
81
table.attach( label, a, a + 1, 1, 2 )
54
label = gtk.Label( "Channel %d" % ( a + 1 ) )
55
table.attach( label, 0, 1, a, a + 1 )
83
57
adj = gtk.Adjustment( 0, 0, self.MAX_CHANNEL_VALUE, 1, 0, 0 )
84
control = gtk.VScale( adj )
58
control = gtk.HScale( adj )
85
59
control.set_draw_value( False )
86
control.set_inverted( True )
87
control.set_size_request( -1, 200 )
60
control.set_property( 'width-request', 300 )
88
61
control.set_sensitive( False )
89
table.attach( control, a, a + 1, 0, 1 )
62
table.attach( control, 1, 2, a, a + 1 )
91
64
self.controls.append( control )
94
frame = gtk.Frame( "Motors" )
95
frame.set_shadow_type( gtk.SHADOW_IN )
96
hbox.pack_start( frame )
98
table = gtk.Table( 2, self.NUM_MOTORS )
99
table.set_border_width( 25 )
100
table.set_row_spacings( 10 )
101
table.set_col_spacings( 15 )
106
for a in range( self.NUM_MOTORS ):
108
label = gtk.Label( a + 1 )
109
table.attach( label, a, a + 1, 1, 2 )
111
adj = gtk.Adjustment( 0, 0, self.MAX_CHANNEL_VALUE, 1, 0, 0 )
112
control = gtk.VScale( adj )
113
control.set_draw_value( False )
114
control.set_inverted( True )
115
control.set_size_request( -1, 200 )
116
table.attach( control, a, a + 1, 0, 1 )
118
control.connect( "value-changed", self.on_motor_change, a )
120
self.motors.append( control )
123
frame = gtk.Frame( "Info" )
124
hbox.pack_start( frame )
127
vbox.set_border_width( 10 )
130
self.add_info( vbox, True, "USB Device:" )
131
self.add_info( vbox, False, self.SERIAL_DEVICE )
132
self.add_info( vbox )
134
if( self.link_error is not None ):
135
self.add_info( vbox, True, "USB Error:" )
136
label = gtk.Label( self.link_error )
137
label.set_line_wrap( True )
138
label.set_size_request( 150, -1 )
139
vbox.pack_start( label, False )
143
vbox.pack_start( gtk.Label( "" ) )
146
67
self.window.show_all()
149
def on_motor_change( self, widget, motor ):
150
self.motor_values[ motor ] = int( widget.get_value() )
154
70
def key_press_event( self, widget, event ):
155
71
if event.keyval == gtk.keysyms.Escape:
156
72
self.window.destroy()