3
# This application is released under the GNU General Public License
4
# v3 (or, at your option, any later version). You can find the full
5
# text of the license under http://www.gnu.org/licenses/gpl.txt.
6
# By using, editing and/or distributing this software you agree to
7
# the terms and conditions of this license.
8
# Thank you for using free software!
10
# WidgetScreenlet (c) 2007 bu Helder Fraga aka Whise
15
from screenlets import DefaultMenuItem
16
from screenlets.options import BoolOption, IntOption, ColorOption
23
from screenlets import sensors
27
#########WORKARROUND FOR GTKOZEMBED BUG BY WHISE################
28
myfile = 'WidgetScreenlet.py'
29
mypath = sys.argv[0][:sys.argv[0].find(myfile)].strip()
31
if sys.argv[0].endswith(myfile): # Makes Shure its not the manager running...
34
workarround = "python "+ sys.argv[0] + " &"
35
a = str(commands.getoutput('whereis firefox')).replace('firefox: ','').split(' ')
37
if os.path.isfile(b + '/run-mozilla.sh'):
38
c = b + '/run-mozilla.sh'
39
workarround = c + " " + sys.argv[0] + " &"
44
print 'First workarround didnt work let run a second manual workarround'
45
if str(sensors.sys_get_distrib_name()).lower().find('ubuntu') != -1: # Works for ubuntu 32
46
workarround = "export LD_LIBRARY_PATH=/usr/lib/firefox \n export MOZILLA_FIVE_HOME=/usr/lib/firefox \n python "+ sys.argv[0] + " &"
47
elif str(sensors.sys_get_distrib_name()).lower().find('debian') != -1: # Works for debian 32 with iceweasel installed
48
workarround = "export LD_LIBRARY_PATH=/usr/lib/iceweasel \n export MOZILLA_FIVE_HOME=/usr/lib/iceweasel \n python " + sys.argv[0] + " &"
49
elif str(sensors.sys_get_distrib_name()).lower().find('suse') != -1: # Works for suse 32 with seamonkey installed
50
workarround = "export LD_LIBRARY_PATH=/usr/lib/seamonkey \n export MOZILLA_FIVE_HOME=/usr/lib/seamonkey \n python "+ sys.argv[0] + " &"
51
print 'Your running suse , make shure you have seamonkey installed'
52
elif str(sensors.sys_get_distrib_name()).lower().find('fedora') != -1: # Works for fedora 32 with seamonkey installed
53
workarround = "export LD_LIBRARY_PATH=/usr/lib/seamonkey \n export MOZILLA_FIVE_HOME=/usr/lib/seamonkey \n python "+ sys.argv[0] + " &"
54
print 'Your running fedora , make shure you have seamonkey installed'
57
if os.path.isfile("/tmp/"+ myfile+"running"):
58
os.system("rm -f " + "/tmp/"+ myfile+"running")
61
if workarround == "python "+ sys.argv[0] + " &":
62
print 'No workarround will be applied to your sistem , this screenlet will probably not work properly'
63
os.system (workarround)
64
fileObj = open("/tmp/"+ myfile+"running","w") #// open for for write
65
fileObj.write('gtkmozembed bug workarround')
76
if sys.argv[0].endswith(myfile):screenlets.show_error(None,"You need Gtkmozembed to run this Screenlet , please install it")
77
else: print "You need Gtkmozembed to run this Screenlet , please install it"
78
#########WORKARROUND FOR GTKOZEMBED BUG BY WHISE################
79
#Check for internet connection required for web widgets
81
if sys.argv[0].endswith(myfile):# Makes Shure its not the manager running...
82
#os.system('wget www.google.com -O/tmp/index.html &')
83
a = commands.getoutput('wget www.google.com -O/tmp/index.html')
84
if a.find('text/html') == -1:
85
screenlets.show_error(None,"Internet connection is required to use this Screenlet")
86
os.system('rm /tmp/index.html')
88
os.system('rm /tmp/index.html')
90
class WidgetScreenlet (screenlets.Screenlet):
91
"""Converted widgets to screenlets engine"""
93
# default meta-info for Screenlets
94
__name__ = 'WidgetScreenlet'
96
__author__ = 'Helder Fraga aka Whise'
102
mypath = sys.argv[0][:sys.argv[0].find('WidgetScreenlet.py')].strip()
103
url = mypath + 'index.html'
104
color_back = 0.3,0.3,0.3,0.7
105
rgba_color = (1,1,1,0.2)
116
def __init__ (self, **keyword_args):
118
screenlets.Screenlet.__init__(self, width=325, height=370,uses_theme=True,
119
is_widget=False, is_sticky=True,is_sizable=False, **keyword_args)
122
self.add_options_group('Options', 'CPU-Graph specific options')
123
self.add_option(BoolOption('Options', 'show_frame',
124
self.show_frame, 'Show frame border', 'Show frame border arround the widget ...'))
125
self.add_option(ColorOption('Options','rgba_color',
126
self.rgba_color , 'Frame color', 'The color of the frame border'))
127
self.add_option(IntOption('Options', 'set_width', self.set_width, 'Width', 'Custom width', min=10, max=gtk.gdk.screen_width()))
128
self.add_option(IntOption('Options', 'set_height', self.set_height, 'Height', 'Custom height', min=10, max=gtk.gdk.screen_height()))
129
#self.add_option(IntOption('Options', 'border_width', self.border_width, 'Frame border width', 'The width of the frame border', min=1, max=8))
130
self.disable_option('scale')
131
self.theme_name = 'default'
132
self.box = gtk.VBox(False, 0)
133
if hasattr(gtkmozembed, 'set_profile_path'):
134
gtkmozembed.set_profile_path(self.mypath,'mozilla')
136
gtkmozembed.gtk_moz_embed_set_profile_path(self.mypath ,'mozilla')
137
self.moz = gtkmozembed.MozEmbed()
138
self.box.pack_start(self.moz, False, False, 0)
140
self.window.add(self.box)
142
self.window.show_all()
146
def __setattr__(self, name, value):
147
# call Screenlet.__setattr__ in baseclass (ESSENTIAL!!!!)
148
screenlets.Screenlet.__setattr__(self, name, value)
149
if name == 'border_width' or name == 'rgba_color' or name == 'show_frame':
151
if name == 'set_width' and value != self.widget_width:
152
self.widget_width = value
153
self.width = int(value)+30
155
if name == 'set_height' and value != self.widget_height:
156
self.widget_height = value
157
self.height = int(value)+30
161
def on_focus (self, event):
162
"""Called when the Screenlet's window receives focus."""
165
def on_unfocus (self, event):
166
"""Called when the Screenlet's window receives focus."""
169
def on_draw (self, ctx):
172
ctx.scale(self.scale , self.scale )
173
ctx.set_operator(cairo.OPERATOR_OVER)
175
ctx.set_source_rgba(0, 0, 0, 0)
177
bgcolor = self.box.get_style().bg[gtk.STATE_NORMAL]
179
r = bgcolor.red/65535.0
180
g = bgcolor.green/65535.0
181
b = bgcolor.blue/65535.0
182
ctx.set_source_rgba(r, g, b, 1)
184
if self.theme and self.window:
185
ctx.set_source_rgba(self.color_back[0],self.color_back[1],self.color_back[2],self.color_back[3])
186
if self.has_focus == True:
187
if not self.show_frame:
188
self.draw_rounded_rectangle(ctx,int((self.width - 64)),0,5,64,12)
189
ctx.set_source_rgba(self.rgba_color[0], self.rgba_color[1], self.rgba_color[2], self.rgba_color[3])
193
self.draw_rounded_rectangle(ctx,0,0,5,self.width,self.height)
194
ctx.set_source_rgba(1-self.rgba_color[0], 1-self.rgba_color[1], 1- self.rgba_color[2], 0.15)
195
self.draw_rounded_rectangle(ctx,0,0,5,self.width,self.height,fill=False)
197
if self.engine == 'google':
198
self.bgpb = gtk.gdk.pixbuf_new_from_file(self.mypath + 'icon.png').scale_simple(int(self.width),int(self.widget_height),gtk.gdk.INTERP_HYPER)
199
self.bgpbim, self.bgpbms = self.bgpb.render_pixmap_and_mask(alpha_threshold=128)
201
if not self.window.is_composited():
203
self.draw_scaled_image(ctx,0,0,self.width,self.height,self.mypath + 'icon.png')
205
self.moz.shape_combine_mask(self.bgpbms,0,0)
207
self.bgpb = gtk.gdk.pixbuf_new_from_file(self.mypath + 'icon.png').scale_simple(int(self.widget_width),int(self.widget_height),gtk.gdk.INTERP_HYPER)
208
self.bgpbim, self.bgpbms = self.bgpb.render_pixmap_and_mask(alpha_threshold=128)
210
if not self.window.is_composited():
212
self.draw_image(ctx,0,0,self.mypath + 'icon.png')
214
self.moz.shape_combine_mask(self.bgpbms,8,8)
220
self.add_default_menuitems(DefaultMenuItem.WINDOW_MENU | DefaultMenuItem.PROPERTIES |
221
DefaultMenuItem.DELETE | DefaultMenuItem.QUIT | DefaultMenuItem.QUIT_ALL)
222
if self.set_width == 0: self.set_width = int(self.widget_width)
224
self.width = self.set_width + 30
227
if self.set_height == 0: self.set_height = int(self.widget_height)
229
self.height = self.set_height + 30
231
def load_widget(self):
233
self.widget = open(self.url,'r')
234
self.widget_info = self.widget.read()
235
self.widget_info = self.widget_info.replace('width=' +chr(34) + '100%','')
238
if self.widget_info.find("width=" + chr(34)) != -1:
240
self.widget_width = self.widget_info[self.widget_info.find("width=" + chr(34)):]
241
self.widget_width = self.widget_width[7:]
242
self.widget_width = self.widget_width[:self.widget_width.find(chr(34)) ].strip()
243
self.widget_height = self.widget_info[self.widget_info.find("height=" + chr(34)):]
244
self.widget_height = self.widget_height[8:]
245
self.widget_height = self.widget_height[:self.widget_height.find(chr(34)) ].strip()
248
elif self.widget_info.find("width=") != -1:
250
self.widget_width = self.widget_info[self.widget_info.find("width="):]
251
self.widget_width = self.widget_width[6:]
253
self.widget_width = self.widget_width[:self.widget_width.find('&') ].strip()
256
# widget height for scaling porpuse ( the height of the html frame)
257
self.widget_height = self.widget_info[self.widget_info.find("height=" ):]
258
self.widget_height = self.widget_height[7:]
259
self.widget_height = self.widget_height[:self.widget_height.find('&') ].strip()
260
elif self.widget_info.find("w=") != -1:
262
self.widget_width = self.widget_info[self.widget_info.find("w="):]
263
self.widget_width = self.widget_width[2:]
264
self.widget_width = self.widget_width[:self.widget_width.find('&') ].strip()
265
self.widget_height = self.widget_info[self.widget_info.find("h=" ):]
266
self.widget_height = self.widget_height[2:]
267
self.widget_height = self.widget_height[:self.widget_height.find('&') ].strip()
269
self.widget_width = str(self.widget_width).replace('px','')
270
self.widget_height = str(self.widget_height).replace('px','')
275
if self.widget_info.startswith('<script src='):
276
self.url = self.widget_info[13:][:(len(self.widget_info)-24)]
278
self.engine = 'google'
279
self.moz.load_url(self.url)
280
print 'loading ' + self.url
282
self.width = int(self.widget_width)+30
283
self.height = int(self.widget_height)+30
284
#print self.width,self.height
285
#print self.widget_width, self.widget_height
288
self.box.set_border_width(7)
289
if self.engine == 'google':
290
#self.box.set_border_width(10)
292
self.box.set_uposition(-1,7)
294
self.moz.set_size_request(-1,int(self.widget_height))
296
self.moz.set_size_request(-1,int(self.height))
299
def on_mouse_down(self,event):
301
def on_draw_shape (self, ctx):
304
ctx.set_operator(cairo.OPERATOR_OVER)
306
ctx.set_source_rgba(0, 0, 0, 1)
307
#a = self.window.get_size()
309
ctx.rectangle(0, 0, self.width,self.height)
321
if __name__ == "__main__":
323
import screenlets.session
324
screenlets.session.create_session(WidgetScreenlet)