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