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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#!/usr/bin/python
#TJR 10-02-13
#version 1.0 : initial version
import pygtk
pygtk.require('2.0')
import gtk, gobject
from socket import *
from pyfirmata import Arduino, util
labels=["guide\nfocus\nin","guide\nfocus\nout","\n4","\n5","\n6","\n7","\nheat","camera\n&\nteleskop","\nlight","flat\nfield","\n12","\n13"];
arduino=Arduino("/dev/ttyUSB0")
class arduinobtn(gtk.ToggleButton):
def __init__(self, label,num):
super(arduinobtn, self).__init__(label)
self.num=num
self.set_size_request(60,60)
self.connect("clicked", self.toggle, "click")
self.time=0
map = self.get_colormap()
color = map.alloc_color("red")
style = self.get_style().copy()
style.bg[gtk.STATE_ACTIVE] = color
self.set_style(style)
def toggle(self,widget,data):
arduino.digital[self.num].write(self.get_active())
if self.time>0.0 and self.get_active():
if self.num==2 or self.num==3:
dome.alterFocus(((self.num*2)-5)*self.time)
gobject.timeout_add(int(self.time*1000), self.cancel)
def setTime(self,entry):
try:
self.time=float(entry.get_text())
except:
self.time=0.0
print "button",self.num,"set to",self.time
def cancel(self):
self.set_active(False)
arduino.digital[self.num].write(0)
print "cancelled button",self.num
return False;
class domecontrol:
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Dome mains control")
self.window.connect("delete_event", self.delete_event)
self.window.set_border_width(10)
self.box = gtk.VBox(False, 0)
self.totalFocus=0.0
self.focusLabel=gtk.Label()
self.focusLabel.set_text("total focus:"+str(self.totalFocus))
self.focusLabel.set_alignment(0.0,0.0)
self.box.pack_start(self.focusLabel, True, True, 0)
self.focusLabel.show()
self.boxes=[]
for i in range (0,4):
self.boxes.append(gtk.HBox(False, 0))
self.buttons=[]
self.texts=[]
for i in range (0,12):
self.buttons.append(arduinobtn(labels[i],i+2))
self.boxes[(i/6)*2].pack_start(self.buttons[i], True, True, 0)
self.buttons[i].show()
self.texts.append(gtk.Entry(5))
self.texts[i].set_editable(True)
self.texts[i].connect("activate", self.buttons[i].setTime)
self.texts[i].set_width_chars(5)
self.boxes[((i/6)*2)+1].pack_start(self.texts[i], True, True, 0)
self.texts[i].show()
for i in range (0,4):
self.boxes.append(gtk.HBox(False, 0))
self.boxes[i].show()
self.box.pack_start(self.boxes[i], True, True, 0)
self.window.add(self.box)
self.box.show()
self.window.show()
def alterFocus(self,amount):
self.totalFocus+=amount
self.focusLabel.set_text("total focus:"+str(self.totalFocus))
def main():
gtk.main()
dome = domecontrol()
if __name__ == "__main__":
main()
|