4 # Copyright (C) 2010 Stefanos Harhalakis
6 # This file is part of wifieye.
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.
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.
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/>.
21 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
23 __version__ = "$Id: 0.py 2265 2010-02-21 19:16:26Z v13 $"
26 # Add the current module's directory to sys.path to bypass
27 # problems when running as widget.
28 # Restore the path at the end of the imports
33 tmp_path=os.path.dirname( os.path.realpath( __file__ ) )
34 sys.path.append(tmp_path)
41 from hildondesktop import *
47 from subprocess import Popen,PIPE
49 from portrait import FremantleRotation
51 from xdg.IconTheme import getIconPath
52 from win_config import WinConfig
57 from icongrid import IconGrid
58 from sig import Disconnector
63 # IconGrid must be before HomePluginItem for its connect()
64 # and do_button_*() to override those of HomePluginItem
65 class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
67 IconGrid.__init__(self)
68 HomePluginItem.__init__(self)
69 FremantleRotation.__init__(self, 'DrlaunchPlugin',
70 mode=FremantleRotation.AUTOMATIC, dontrotate=True)
71 Disconnector.__init__(self)
75 self.set_settings(True)
83 """If this is called from the constructor then the program
85 aid=self.get_applet_id()
87 # Get desktop activity if D.A.M. is present
89 act="/usr/bin/activity"
91 if os.path.exists(act):
92 r=Popen([act, "current"], stdout=PIPE).communicate()
97 ret="%s-%s" % (aid, activity)
103 self.id=self.get_id0()
107 def get_config(self):
108 if self.config==None:
110 self.config=config.Config(id)
114 def do_realize(self):
116 config=self.get_config()
119 IconGrid.do_realize(self, config)
121 self.setSize(config.getSize())
124 screen=self.get_screen()
125 self.set_colormap(screen.get_rgba_colormap())
126 self.set_app_paintable(True)
128 self.c(self, 'show-settings', self.slot_show_settings)
129 self.c(self, 'long-press', self.signalLongpress)
130 self.c(self, 'click', self.signalClick)
131 self.c(self, 'notify', self.signalNotify)
133 HomePluginItem.do_realize(self)
135 def on_orientation_changed(self, orientation):
137 if orientation==None or len(orientation)==0:
140 # Get the first character of the string (l/p)
145 def do_expose_event(self, event):
146 IconGrid.do_expose_event(self, event)
147 HomePluginItem.do_expose_event(self, event)
150 def slot_show_settings(self, dt):
151 if self.winConfig!=None:
153 # self.winConfig.show_all()
156 s=WinConfig(self.get_config())
158 #s.c(s, 'delete-event', self.slotConfigDestroy)
159 self.c(s, 'delete-event', self.slotConfigDestroy)
160 #s.connect('destroy', self.slotConfigDestroy)
163 def slotConfigDestroy(self, sender, event):
164 # print "Sender:", sender
167 # Disconnect signals for that object in order to be deleted
168 self.dis_finish(self.winConfig)
169 #self.winConfig.finish()
170 #self.winConfig.destroy()
174 cfg=self.get_config()
176 cfg.setSize(dt['size'])
177 cfg.setApps(dt['apps'])
178 cfg.setIndiv(dt['indiv'])
179 cfg.setLongpress(dt['longpress'])
180 cfg.setAnimate(dt['animate'])
181 cfg.setNoBg(dt['nobg'])
182 cfg.setThemeBg(dt['themebg'])
183 cfg.setIconSize(dt['iconsize'])
184 cfg.setIconPadding(dt['iconpadding'])
185 cfg.setIconMargin(dt['iconmargin'])
189 self.setSize(dt['size'])
191 self.icons.resizeMax()
193 # Free memory that is used for animations if animations are disabled
194 if not dt['animate']:
195 self.clearAnimationCache()
197 # Free memory of backgrounds in case they changed
202 # print "slot-config-destroy-end"
206 def handle_click(self, sender, icon):
207 """ common handler for longpress and click """
208 if icon.appname!=None and icon.appname!='':
209 launcher.launch(icon.appname)
211 def signalLongpress(self, sender, icon):
212 self.handle_click(sender, icon)
214 def signalClick(self, sender, icon):
215 config=self.get_config()
217 if not config.getLongpress():
218 self.handle_click(sender, icon)
220 def signalNotify(self, sender, property):
221 if property.name=='is-on-current-desktop':
222 v=self.get_property(property.name)
223 if v and self.draw_pending:
227 config=self.get_config()
229 w=(self.size[0] * config.iconsize) + \
230 (self.size[0] * config.getIconSpace())
231 h=(self.size[1] * config.iconsize) + \
232 (self.size[1] * config.getIconSpace())
233 self.set_size_request(w, h)
236 def setSize(self, size):
237 IconGrid.setSize(self, size)
240 hd_plugin_type = DrlaunchPlugin
242 if __name__=="__main__":
243 gobject.type_register(hd_plugin_type)
244 obj=gobject.new(hd_plugin_type, plugin_id="plugin_id")
250 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: