(no commit message)
[drlaunch] / 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):
41         StackableWindow.__init__(self)
42
43         self.setupUi()
44
45     def setupUi(self):
46         self.igw=IconGridWidget(True)
47
48         self.add(self.igw)
49
50         self.igw.connect('long-press', self.signalLongpress)
51
52     def signalLongpress(self, sender, icon):
53         print "slp", icon
54         self.doConfig(icon)
55
56     def doConfig(self, icon):
57         aps=apps.scan()
58
59         lst=[aps[x]['name'] for x in aps]
60         lst.sort()
61
62         dialog=gtk.Dialog('App select', None,
63             gtk.DIALOG_DESTROY_WITH_PARENT, buttons=())
64
65         selector=hildon.TouchSelectorEntry(text=True)
66         selector.set_column_selection_mode(
67             hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
68
69         dialog.vbox.pack_start(selector, True, True, 0)
70         dialog.set_size_request(0,900)
71         dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
72         dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
73
74         selector.append_text('None')
75
76         idx=0
77         cnt=1
78         for app in lst:
79             if app==None:
80                 continue
81             selector.append_text(app)
82             if icon.name!=None and aps[icon.name]['name']==app:
83                 idx=cnt
84             cnt+=1
85
86         selector.set_active(0, idx)
87
88         dialog.show_all()
89
90         app=None
91
92         r=dialog.run()
93
94         if r==gtk.RESPONSE_OK:
95             cur=selector.get_current_text()
96             if cur=='None':
97                 app=None
98             else:
99                 for i in aps:
100                     if aps[i]['name']==cur:
101                         app=aps[i]
102                         break
103             if app!=None:
104                 app['icon2']=getIcon(app['icon'])
105             else:
106                 app={
107                     'id':       None,
108                     'icon2':    None,
109                     }
110             icon.setApp(app)
111
112         dialog.destroy()
113
114
115 if __name__=="__main__":
116     win=WinConfig()
117     win.connect('delete-event', gtk.main_quit)
118
119     win.show_all()
120     gtk.main()
121
122
123
124 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
125