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
#MyIpScreenlet (c) Whise <helder.fraga@hotmail.com>
13
from screenlets.options import FloatOption, BoolOption, StringOption, FontOption, ColorOption, IntOption
14
from screenlets import DefaultMenuItem
18
from urllib import urlopen
19
from screenlets import Plugins
20
proxy = Plugins.importAPI('Proxy')
24
class MyIpScreenlet(screenlets.Screenlet):
25
"""A Screenlet that displays Internet Ip"""
27
# default meta-info for Screenlets
28
__name__ = 'MyIpScreenlet'
30
__author__ = 'Helder Fraga aka Whise (c) 2007'
31
__desc__ = 'A Screenlet that displays Internet Ip'
33
font_color = (1,1,1, 0.8)
34
background_color = (0,0,0, 0.8)
36
def __init__(self, **keyword_args):
37
screenlets.Screenlet.__init__(self, width=200, height=50,uses_theme=True, **keyword_args)
39
self.theme_name = "default"
40
self.add_default_menuitems(DefaultMenuItem.XML)
41
self.add_options_group('Options',
42
'The Options widget settings')
45
self.add_option(ColorOption('Options','font_color',
46
self.font_color, 'Text color', 'font_color'))
47
self.add_option(ColorOption('Options','background_color',
48
self.background_color, 'Back color(only with default theme)', 'only works with default theme'))
51
self.__timeout = gobject.timeout_add(24 * 60 * 60 * 1000, self.update)
53
def __setattr__(self, name, value):
54
# call Screenlet.__setattr__ in baseclass (ESSENTIAL!!!!)
55
screenlets.Screenlet.__setattr__(self, name, value)
58
print "Screenlet has been initialized."
59
# add default menuitems
60
self.add_default_menuitems()
65
return True # keep running this event
71
proxies = proxy.Proxy().get_proxy()
72
self.myip = str(urlopen("http://www.whatismyip.com/automation/n09230945.asp",proxies=proxies).read())
75
from screenlets import sensors
76
self.myip = str(sensors.net_get_ip())
78
def on_draw(self, ctx):
79
ctx.scale(self.scale, self.scale)
80
ctx.set_operator(cairo.OPERATOR_OVER)
82
self.theme.render(ctx,'background')
84
ctx.set_source_rgba(*self.background_color)
85
if self.theme_name == 'default':self.draw_rounded_rectangle(ctx,0,0,6,200,40)
86
ctx.set_source_rgba(1, 1, 1, 1)
87
ctx.set_source_rgba(*self.font_color)
88
self.draw_text(ctx,'IP - ' + self.myip,0,10, 'FreeSans',16, self.width,allignment = pango.ALIGN_CENTER)
89
try:self.theme.render(ctx,'glass')
92
def on_menuitem_select (self, id):
93
"""handle MenuItem-events in right-click menu"""
96
# TODO: use DBus-call for this
97
#self.switch_hide_show()
100
def on_draw_shape(self,ctx):
101
ctx.rectangle(0,0,self.width,self.height)
105
if __name__ == "__main__":
106
import screenlets.session
107
screenlets.session.create_session(MyIpScreenlet)