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
104
|
# -*- coding: utf-8 -*-
# h-client, a python library to manage the database of an h-source node
# Copyright (C) 2011 Antonio Gallo
#
#
# h-client is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# h-client is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with h-client. If not, see <http://www.gnu.org/licenses/>.
import pygtk
pygtk.require('2.0')
import gtk
from hlibrary import *
class hclient:
#the device that has to be displaced in the right window
currentDevice = ''
#set the device that has to be displaced in the right window
def setCurrentDevice(self, widget, data):
self.currentDevice = data
print self.currentDevice
# another callback
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
#start the client object
self.client = Client('h-source')
self.client.createDevices()
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# This is a new call, which just sets the title of our
# new window to "Hello Buttons!"
self.window.set_title("h-client")
#self.window.set_size_request(200, 100)
# Here we just set a handler for delete_event that immediately
# exits GTK.
self.window.connect("delete_event", self.delete_event)
# Sets the border width of the window.
self.window.set_border_width(10)
self.bottomWindow = gtk.HBox(False, 0)
#add the bottom box
self.window.add(self.bottomWindow)
## build the left window ##
#start the left vertical box
self.leftWindow = gtk.VBox(False, 0)
#start the right vertical box
self.rightWindow = gtk.VBox(False, 0)
self.frame = gtk.Frame("Your devices")
self.bottomWindow.pack_start(self.frame, True, True, 0)
self.bottomWindow.pack_start(self.rightWindow, True, True, 0)
for key,dev in self.client.devices.iteritems():
self.button = gtk.Button(dev[0].getType())
self.button.connect("clicked", self.setCurrentDevice, key)
self.leftWindow.pack_start(self.button, False, True, 0)
self.button.show()
self.frame.add(self.leftWindow)
self.bottomWindow.show()
self.frame.show()
self.leftWindow.show()
self.rightWindow.show()
self.window.show()
def main():
gtk.main()
if __name__ == "__main__":
Client = hclient()
main()
|