Change defaults to 'no longpress' and 'rotate icons individually'.
[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 setWindow(self, win):
120         """ Set the window for all icons """
121
122         for i in self.icons:
123             ic=self.icons[i]
124             ic.setWindow(win)
125
126     def signalLongpress(self, icon):
127         #print "signalLongpress()", icon
128         self.emit('long-press', icon)
129
130     def signalClick(self, icon):
131         #print "signalClick()", icon
132         self.emit('click', icon)
133
134     def signalTrippleClick(self, icon):
135         #print "signalTrippleClick()", icon
136         self.emit('tripple-click', icon)
137
138     def get(self, x, y):
139         k=(x,y)
140         if self.icons.has_key(k):
141             ret=self.icons[k]
142         else:
143             ret=None
144
145         return(ret)
146
147     def load(self):
148 #       x=0
149 #       y=0
150 #       fn=["maegirls", "wifieye", 'battery-eye', 'image-viewer',
151 #           'tecnoballz', 'ncalc', 'rtcom-call-ui', 'rtcom-messaging-ui',
152 #           'extcalllog', 'browser', 'modest', 'osso-addressbook']
153
154         wapps=self.config.getApps()
155         sz=self.config.getSize()
156
157         for k in wapps:
158             x,y=k
159             if x>=sz or y>=sz:
160                 continue
161
162             appname=wapps[k]
163             if appname!=None:
164                 app=apps.readOne(appname)
165                 if app!=None:
166                     app['icon2']=getIcon(app['icon'], self.config.getIconSize())
167                     self.get(x,y).setApp(app)
168             else:
169                 self.get(x,y).setApp(None)
170
171 #       for f in fn:
172 #           dt=apps.readOne(f)
173 #           dt['icon2']=getIcon(dt['icon'])
174 #           print x, y, dt
175 #           self.get(x,y).setApp(dt)
176 #           x+=1
177 #           if x>=config.getSize(getSize()):
178 #               x=0
179 #               y+=1
180 ##          self.icons.append(p)
181
182 gobject.type_register(Icons)
183 Icons.register_signals()
184
185 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
186