(no commit message)
[drlaunch] / 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.size=0
49         self.isconfig=isconfig
50
51     @classmethod
52     def register_signals(cls):
53         signals=icon.signals
54         for s in signals:
55             gobject.signal_new(s, cls, gobject.SIGNAL_RUN_FIRST,
56                 gobject.TYPE_NONE, (Icon,))
57
58     def __iter__(self):
59         return(IconIter(self.icons))
60
61     def connect_one(self, which):
62         which.connect('long-press', self.signalLongpress)
63         which.connect('click', self.signalClick)
64         which.connect('tripple-click', self.signalTrippleClick)
65
66     def disconnect_one(self, which):
67         which.disconnect('long-press', self.signalLongpress)
68         which.disconnect('click', self.signalClick)
69         which.disconnect('tripple-click', self.signalTrippleClick)
70
71     def setSize(self, sz):
72         if sz==self.size:
73             return
74
75         old=self.icons
76         self.icons={}
77
78         for x in xrange(sz):
79             for y in xrange(sz):
80                 k=(x,y)
81                 if old.has_key(k):
82                     self.icons[k]=old[k]
83                     old.pop(k)
84                 else:
85                     ico=Icon(self.isconfig)
86                     self.icons[k]=ico
87                     self.connect_one(ico)
88
89         # Disconnect signals
90         for i in old:
91             self.disconnect_one(old[i])
92
93         self.size=sz
94
95     def signalLongpress(self, icon):
96         print "signalLongpress()", icon
97         self.emit('long-press', icon)
98
99     def signalClick(self, icon):
100         print "signalClick()", icon
101         self.emit('click', icon)
102
103     def signalTrippleClick(self, icon):
104         print "signalTrippleClick()", icon
105         self.emit('tripple-click', icon)
106
107     def get(self, x, y):
108         k=(x,y)
109         if self.icons.has_key(k):
110             ret=self.icons[k]
111         else:
112             ret=None
113
114         return(ret)
115
116     def load(self):
117         x=0
118         y=0
119         fn=["maegirls", "wifieye", 'battery-eye', 'image-viewer',
120             'tecnoballz', 'ncalc', 'rtcom-call-ui', 'rtcom-messaging-ui',
121             'extcalllog', 'browser', 'modest', 'osso-addressbook']
122         for f in fn:
123             dt=apps.readOne(f)
124             dt['icon2']=getIcon(dt['icon'])
125             print x, y, dt
126             self.get(x,y).setApp(dt)
127             x+=1
128             if x>=config.size:
129                 x=0
130                 y+=1
131 #           self.icons.append(p)
132
133         print "end of Icons init"
134
135
136 gobject.type_register(Icons)
137 Icons.register_signals()
138
139 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent:
140