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 *
48 from subprocess import Popen,PIPE
50 from portrait import FremantleRotation
52 from xdg.IconTheme import getIconPath
53 from win_config import WinConfig
58 from icongrid import IconGrid
59 from sig import Disconnector
64 # IconGrid must be before HomePluginItem for its connect()
65 # and do_button_*() to override those of HomePluginItem
66 class DrlaunchPlugin(IconGrid, HomePluginItem, FremantleRotation, Disconnector):
68 IconGrid.__init__(self)
69 HomePluginItem.__init__(self)
70 FremantleRotation.__init__(self, 'DrlaunchPlugin',
71 mode=FremantleRotation.AUTOMATIC, dontrotate=True)
72 Disconnector.__init__(self)
76 self.gconf=gconf.client_get_default()
78 self.set_settings(True)
86 """If this is called from the constructor then the program
88 aid=self.get_applet_id()
90 # Get desktop activity if D.A.M. is present
92 act="/usr/bin/activity"
94 if os.path.exists(act):
95 r=Popen([act, "current"], stdout=PIPE).communicate()
100 ret="%s-%s" % (aid, activity)
106 self.id=self.get_id0()
110 def get_config(self):
111 if self.config==None:
113 self.config=config.Config(id)
117 def get_desktop_orientation(self):
119 Return desktop orientation
121 NOTE: This is the desktop orientation as it was introduced in CSSU.
122 Not the device orientation.
124 @return "portrait" or "landscape"
127 sw=gdk.screen_width()
128 sh=gdk.screen_height()
137 def is_rotating_desktop(self):
139 Check whether the desktop will change to portrait mode, as
147 # This returns False if the key doesn't exist
148 ret=c.get_bool('/apps/osso/hildon-desktop/ui_can_rotate')
152 def do_realize(self):
154 config=self.get_config()
157 IconGrid.do_realize(self, config)
159 self.setSize(config.getSize())
162 screen=self.get_screen()
163 self.set_colormap(screen.get_rgba_colormap())
164 self.set_app_paintable(True)
166 self.c(self, 'show-settings', self.slot_show_settings)
167 self.c(self, 'long-press', self.signalLongpress)
168 self.c(self, 'click', self.signalClick)
169 self.c(self, 'notify', self.signalNotify)
171 HomePluginItem.do_realize(self)
173 def on_orientation_changed(self, orientation):
175 if orientation==None or len(orientation)==0:
178 # Get the first character of the string (l/p)
181 # Get desktop orientation
182 #do=self.get_desktop_orientation()
184 # Is desktop rotation (per CSSU) enabled?
185 rd=self.is_rotating_desktop()
187 #print "desktop: %s / %s, device: %s" % (do, rd, o)
189 # In case of a rotating desktop, force orientation to be
197 def do_expose_event(self, event):
198 IconGrid.do_expose_event(self, event)
199 HomePluginItem.do_expose_event(self, event)
202 def slot_show_settings(self, dt):
203 if self.winConfig!=None:
205 # self.winConfig.show_all()
208 s=WinConfig(self.get_config())
210 #s.c(s, 'delete-event', self.slotConfigDestroy)
211 self.c(s, 'delete-event', self.slotConfigDestroy)
212 #s.connect('destroy', self.slotConfigDestroy)
215 def slotConfigDestroy(self, sender, event):
216 # print "Sender:", sender
219 # Disconnect signals for that object in order to be deleted
220 self.dis_finish(self.winConfig)
221 #self.winConfig.finish()
222 #self.winConfig.destroy()
226 cfg=self.get_config()
228 cfg.setSize(dt['size'])
229 cfg.setApps(dt['apps'])
230 cfg.setIndiv(dt['indiv'])
231 cfg.setLongpress(dt['longpress'])
232 cfg.setAnimate(dt['animate'])
233 cfg.setNoBg(dt['nobg'])
234 cfg.setThemeBg(dt['themebg'])
235 cfg.setIconSize(dt['iconsize'])
236 cfg.setIconPadding(dt['iconpadding'])
237 cfg.setIconMargin(dt['iconmargin'])
241 self.icons.resizeMax()
242 self.setSize(dt['size'])
245 # Free memory that is used for animations if animations are disabled
246 if not dt['animate']:
247 self.clearAnimationCache()
249 # Free memory of backgrounds in case they changed
254 # print "slot-config-destroy-end"
258 def handle_click(self, sender, icon):
259 """ common handler for longpress and click """
260 if icon.appname!=None and icon.appname!='':
261 launcher.launch(icon.appname)
263 def signalLongpress(self, sender, icon):
264 self.handle_click(sender, icon)
266 def signalClick(self, sender, icon):
267 config=self.get_config()
269 if not config.getLongpress():
270 self.handle_click(sender, icon)
272 def signalNotify(self, sender, property):
273 if property.name=='is-on-current-desktop':
274 v=self.get_property(property.name)
275 if v and self.draw_pending:
279 config=self.get_config()
281 w=(self.size[0] * config.iconsize) + \
282 (self.size[0] * config.getIconSpace())
283 h=(self.size[1] * config.iconsize) + \
284 (self.size[1] * config.getIconSpace())
285 self.set_size_request(w, h)
288 def setSize(self, size):
289 IconGrid.setSize(self, size)
292 hd_plugin_type = DrlaunchPlugin
294 if __name__=="__main__":
295 gobject.type_register(hd_plugin_type)
296 obj=gobject.new(hd_plugin_type, plugin_id="plugin_id")
302 # vim: set ts=8 sts=4 sw=4 noet formatoptions=r ai nocindent: