(no commit message)
[drlaunch] / src / win_config.py
1 #!/usr/bin/env python
2 # coding=UTF-8
3
4 # Copyright (C) 2010 Stefanos Harhalakis
5 #
6 # This file is part of wifieye.
7 #
8 # wifieye is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # wifieye is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with wifieye.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
22
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
24
25 import gtk
26 import gobject
27 import hildon
28 import time
29
30 from hildon import StackableWindow
31 #from portrait import FremantleRotation
32 #from xdg.IconTheme import getIconPath
33
34 import config
35 import apps
36 from icon import Icon, getIcon
37 from icongrid import IconGridWidget
38
39 class WinConfig(StackableWindow):
40     def __init__(self, *args):
41         StackableWindow.__init__(self)
42
43         self.setupUi()
44
45     def setupUi(self):
46         self.igw=IconGridWidget(True)
47 #       self.igw.setSize(config.getSize())
48
49         hbox=gtk.HBox()
50         self.add(hbox)
51
52         # Add the icongrid
53         hbox.add(self.igw)
54
55         # Now go for the right side
56         al=gtk.Alignment(yscale=0)
57         hbox.add(al)
58
59         vbox=gtk.VBox()
60 #       hbox.add(vbox)
61         al.add(vbox)
62
63         vbox.add(gtk.Label('Grid size:'))
64
65         self.butsSize=[]
66         for i in xrange(4):
67             but=gtk.ToggleButton("%sx%s" % (i+1,i+1))
68             but.set_size_request(160, 90)
69             self.butsSize.append(but)
70             but.connect('toggled', self.slotButtonSize, i)
71
72         hbox2=gtk.HBox()
73         vbox.add(hbox2)
74         hbox2.add(self.butsSize[0])
75         hbox2.add(self.butsSize[1])
76         hbox2=gtk.HBox()
77         vbox.add(hbox2)
78         hbox2.add(self.butsSize[2])
79         hbox2.add(self.butsSize[3])
80
81         self.igw.connect('long-press', self.slotLongpress)
82
83         self.ignore_toggle=False
84
85         self.setSize(config.getSize())
86
87     def slotLongpress(self, sender, icon):
88         print "slp", icon
89         self.doConfig(icon)
90
91     def slotButtonSize(self, sender, id):
92         print "size:", id
93
94         self.setSize(id+1)
95         
96     def setSize(self, sz):
97         if self.ignore_toggle:
98             return
99
100         self.ignore_toggle=True
101
102         id=sz-1
103
104         for i in xrange(4):
105             but=self.butsSize[i]
106             but.set_active(i==id)
107
108         self.ignore_toggle=False
109
110         self.igw.setSize(sz)
111
112         self.igw.queue_draw()
113
114
115     def doConfig(self, icon):
116         aps=apps.scan()
117
118         lst=[aps[x]['name'] for x in aps]
119         lst.sort()
120
121         dialog=gtk.Dialog('App select', None,
122             gtk.DIALOG_DESTROY_WITH_PARENT, buttons=())
123
124         selector=hildon.TouchSelectorEntry(text=True)
125         selector.set_column_selection_mode(
126             hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
127
128         dialog.vbox.pack_start(selector, True, True, 0)
129         dialog.set_size_request(0,900)
130         dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
131         dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
132
133         selector.append_text('None')
134
135         idx=0
136         cnt=1
137         for app in lst:
138             if app==None:
139                 continue
140             selector.append_text(app)
141             if icon.name!=None and aps[icon.name]['name']==app:
142                 idx=cnt
143             cnt+=1
144
145         selector.set_active(0, idx)
146
147         dialog.show_all()
148
149         app=None
150
151         r=dialog.run()
152
153         if r==gtk.RESPONSE_OK:
154             cur=selector.get_current_text()
155             if cur=='None':
156                 app=None
157             else:
158                 for i in aps:
159                     if aps[i]['name']==cur:
160                         app=aps[i]
161                         break
162             if app!=None:
163                 app['icon2']=getIcon(app['icon'])
164             else:
165                 app={
166                     'id':       None,
167                     'icon2':    None,
168                     }
169             icon.setApp(app)
170
171         dialog.destroy()
172
173     def getData(self):
174         sz=0
175         for but in self.butsSize:
176             sz+=1
177             if but.get_active()==True:
178                 break
179
180         print "conf: sz=", sz
181
182         wapps={}
183
184         for x in xrange(sz):
185             for y in xrange(sz):
186                 ico=self.igw.get(x,y)
187                 k=(x,y)
188                 wapps[k]=ico.name
189
190         ret={
191             'size':     sz,
192             'apps':     wapps
193             }
194
195         print "ret:", ret
196
197         return(ret)
198
199 if __name__=="__main__":
200     win=WinConfig()
201     win.connect('delete-event', gtk.main_quit)
202
203     win.show_all()
204     gtk.main()
205
206
207
208 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
209