clean-ups
[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         self.doConfig(icon)
89
90     def slotButtonSize(self, sender, id):
91         self.setSize(id+1)
92         
93     def setSize(self, sz):
94         if self.ignore_toggle:
95             return
96
97         self.ignore_toggle=True
98
99         id=sz-1
100
101         for i in xrange(4):
102             but=self.butsSize[i]
103             but.set_active(i==id)
104
105         self.ignore_toggle=False
106
107         self.igw.setSize(sz)
108
109         self.igw.queue_draw()
110
111
112     def doConfig(self, icon):
113         aps=apps.scan()
114
115         lst=[aps[x]['name'] for x in aps]
116         lst.sort()
117
118         dialog=gtk.Dialog('App select', None,
119             gtk.DIALOG_DESTROY_WITH_PARENT, buttons=())
120
121         selector=hildon.TouchSelectorEntry(text=True)
122         selector.set_column_selection_mode(
123             hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
124
125         dialog.vbox.pack_start(selector, True, True, 0)
126         dialog.set_size_request(0,900)
127         dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
128         dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
129
130         selector.append_text('None')
131
132         idx=0
133         cnt=1
134         for app in lst:
135             if app==None:
136                 continue
137             selector.append_text(app)
138             if icon.name!=None and aps[icon.name]['name']==app:
139                 idx=cnt
140             cnt+=1
141
142         selector.set_active(0, idx)
143
144         dialog.show_all()
145
146         app=None
147
148         r=dialog.run()
149
150         if r==gtk.RESPONSE_OK:
151             cur=selector.get_current_text()
152             if cur=='None':
153                 app=None
154             else:
155                 for i in aps:
156                     if aps[i]['name']==cur:
157                         app=aps[i]
158                         break
159             if app!=None:
160                 app['icon2']=getIcon(app['icon'])
161             else:
162                 app={
163                     'id':       None,
164                     'icon2':    None,
165                     }
166             icon.setApp(app)
167
168         dialog.destroy()
169
170     def getData(self):
171         sz=0
172         for but in self.butsSize:
173             sz+=1
174             if but.get_active()==True:
175                 break
176
177         wapps={}
178
179         for x in xrange(sz):
180             for y in xrange(sz):
181                 ico=self.igw.get(x,y)
182                 k=(x,y)
183                 wapps[k]=ico.name
184
185         ret={
186             'size':     sz,
187             'apps':     wapps
188             }
189
190         return(ret)
191
192 if __name__=="__main__":
193     win=WinConfig()
194     win.connect('delete-event', gtk.main_quit)
195
196     win.show_all()
197     gtk.main()
198
199
200
201 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
202