(no commit message)
[drlaunch] / src / icons.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 config
26 import apps
27 import icon
28 from icon import getIcon, Icon
29
30 import gobject
31
32 class IconIter:
33     def __init__(self, items):
34         self.iter=items.__iter__()
35
36     def __iter__(self):
37         ret=self.iter.__iter__()
38         return(ret)
39
40     def next(self):
41         ret=self.iter.next()
42         return(ret)
43
44 class Icons(gobject.GObject):
45     def __init__(self, isconfig):
46         self.__gobject_init__()
47         self.icons={}
48         self.allicons={}
49         self.size=0
50         self.isconfig=isconfig
51
52         # signal handlers
53         self.h={}
54
55         # setup allicons
56         maxsz=4
57         for x in xrange(maxsz):
58             for y in xrange(maxsz):
59                 k=(x,y)
60                 ico=Icon(self.isconfig)
61                 self.allicons[k]=ico
62                 self.connect_one(ico)
63
64     @classmethod
65     def register_signals(cls):
66         signals=icon.signals
67         for s in signals:
68             gobject.signal_new(s, cls, gobject.SIGNAL_RUN_FIRST,
69                 gobject.TYPE_NONE, (Icon,))
70
71     def __iter__(self):
72         return(IconIter(self.icons))
73
74     def connect_one(self, which):
75         self.h[which]={
76             'longpress':    which.connect('long-press', self.signalLongpress),
77             'click':        which.connect('click', self.signalClick),
78             'tripple':      which.connect('tripple-click',
79                                 self.signalTrippleClick)
80             }
81
82     def disconnect_one(self, which):
83         for i in self.h[which]:
84             which.disconnect(self.h[which][i])
85         self.h.pop(which)
86 #       which.disconnect(self.h[which]_longpress)
87 #       which.disconnect(self.h_click)
88 #       which.disconnect(self.h_tripple)
89
90     def setSize(self, sz):
91 #       print "sz:", sz, self.size
92
93         if sz==self.size:
94             return
95
96         old=self.icons
97         self.icons={}
98
99         for x in xrange(sz):
100             for y in xrange(sz):
101                 k=(x,y)
102                 ico=self.allicons[k]
103                 self.icons[k]=ico
104 #               if old.has_key(k):
105 #                   old.pop(k)  # Re-used
106 #               else:
107 #                   self.connect_one(ico)
108
109         # Disconnect signals
110 #       for i in old:
111 #           self.disconnect_one(old[i])
112
113         self.size=sz
114
115     def signalLongpress(self, icon):
116         print "signalLongpress()", icon
117         self.emit('long-press', icon)
118
119     def signalClick(self, icon):
120         print "signalClick()", icon
121         self.emit('click', icon)
122
123     def signalTrippleClick(self, icon):
124         print "signalTrippleClick()", icon
125         self.emit('tripple-click', icon)
126
127     def get(self, x, y):
128         k=(x,y)
129         if self.icons.has_key(k):
130             ret=self.icons[k]
131         else:
132             ret=None
133
134         return(ret)
135
136     def load(self):
137 #       x=0
138 #       y=0
139 #       fn=["maegirls", "wifieye", 'battery-eye', 'image-viewer',
140 #           'tecnoballz', 'ncalc', 'rtcom-call-ui', 'rtcom-messaging-ui',
141 #           'extcalllog', 'browser', 'modest', 'osso-addressbook']
142
143         wapps=config.getApps()
144         sz=config.getSize()
145
146         for k in wapps:
147             x,y=k
148             if x>=sz or y>=sz:
149                 continue
150
151             appname=wapps[k]
152             if appname!=None:
153                 app=apps.readOne(appname)
154                 if app!=None:
155                     app['icon2']=getIcon(app['icon'])
156                     self.get(x,y).setApp(app)
157
158 #       for f in fn:
159 #           dt=apps.readOne(f)
160 #           dt['icon2']=getIcon(dt['icon'])
161 #           print x, y, dt
162 #           self.get(x,y).setApp(dt)
163 #           x+=1
164 #           if x>=config.getSize(getSize()):
165 #               x=0
166 #               y+=1
167 ##          self.icons.append(p)
168
169         print "end of Icons init"
170
171
172 gobject.type_register(Icons)
173 Icons.register_signals()
174
175 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
176