2 # -*- coding: utf-8 -*-
7 from subprocess import *
10 supports_alpha = False
12 class UssdConfigDialog(gtk.Dialog):
13 def __init__(self, config):
14 gtk.Dialog.__init__(self, "USSD widget", None,
15 gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR,
16 ("Save", gtk.RESPONSE_OK))
17 self.ussdNumber = hildon.Entry(gtk.HILDON_SIZE_AUTO)
18 self.ussdNumber.set_text(config[0])
19 self.parser = hildon.Entry(gtk.HILDON_SIZE_AUTO)
20 self.parser.set_text(config[1])
21 self.vbox.add(gtk.Label("USSD number"))
22 self.vbox.add(self.ussdNumber)
23 self.vbox.add(gtk.Label("Parser"))
24 self.vbox.add(self.parser)
30 config = open(os.getenv("HOME")+"/.ussdWidget.conf","r")
33 number = config.readline().strip()
35 parser = config.readline().strip()
37 return [number, parser]
41 def set_config(config):
42 fconfig = open(os.getenv("HOME")+"/.ussdWidget.conf","w")
43 fconfig.writelines(["# Parameters are taken by line number, do not move them\n", "# USSD query to be run by widget\n", config[0], "\n"])
44 fconfig.writelines(["Parser command\n", config[1], "\n"])
47 def ussd_renew(widget, event):
50 widget.label.set_text("Processing")
53 # widget.send_expose(gtk.gdk.EXPOSE)
55 p = Popen(['python', '/usr/bin/ussdquery.py', config[0]], stdout=PIPE)
56 reply = p.communicate()[0].strip()
61 # p = Popen([config[1]], stdout=PIPE)
62 # reply = p.communicate(reply)[0].strip()
64 reply = " Bad config "
66 widget.label.set_text(reply)
68 def on_show_settings(widget):
73 dialog = UssdConfigDialog(config)
76 set_config ([dialog.ussdNumber.get_text(), dialog.parser.get_text()])
80 if config == ["", ""] :
81 widget.label.set_text("Click to update")
83 def get_color(logicalcolorname):
84 settings = gtk.settings_get_default()
85 color_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', 'osso-logical-colors', gtk.Button)
86 return color_style.lookup_color(logicalcolorname)
88 class UssdWidgetPlugin(hildondesktop.HomePluginItem):
90 hildondesktop.HomePluginItem.__init__(self)
94 colormap = self.get_screen().get_rgba_colormap()
95 self.set_colormap (colormap)
99 self.label = gtk.Label("Click to update")
101 self.label = gtk.Label("Configure me")
103 self.connect("button-press-event", ussd_renew)
105 self.label.set_padding(15, 10)
106 self.label.set_size_request(-1,-1)
107 self.set_size_request(-1,-1)
109 self.vbox = gtk.HBox()
110 self.vbox.add(self.label)
113 self.set_settings(True)
114 self.connect("show-settings", on_show_settings)
118 def _expose(self, event):
119 cr = self.window.cairo_create()
122 width, height = self.allocation[2], self.allocation[3]
124 #/* a custom shape, that could be wrapped in a function */
125 x0 = 0 #/*< parameters like cairo_rectangle */
128 radius = min(15, width/2, height/2) #/*< and an approximate curvature radius */
133 cr.move_to (x0, y0 + radius)
134 cr.arc (x0 + radius, y0 + radius, radius, 3.14, 1.5 * 3.14)
135 cr.line_to (x1 - radius, y0)
136 cr.arc (x1 - radius, y0 + radius, radius, 1.5 * 3.14, 0.0)
137 cr.line_to (x1 , y1 - radius)
138 cr.arc (x1 - radius, y1 - radius, radius, 0.0, 0.5 * 3.14)
139 cr.line_to (x0 + radius, y1)
140 cr.arc (x0 + radius, y1 - radius, radius, 0.5 * 3.14, 3.14)
144 fg_color = get_color("ActiveTextColor")
149 bg_color=gtk.gdk.color_parse('#000000')
151 cr.set_source_rgba (bg_color.red / 65535.0, bg_color.green/65535.0, bg_color.blue/65535.0, 0.7)
154 cr.set_source_rgba (fg_color.red / 65535.0, fg_color.green / 65535.0, fg_color.blue / 65535.0, 0.5)
157 def do_expose_event(self, event):
160 self.vbox.do_expose_event (self, event)
162 hd_plugin_type = UssdWidgetPlugin
164 # The code below is just for testing purposes.
165 # It allows to run the widget as a standalone process.
166 if __name__ == "__main__":
168 gobject.type_register(hd_plugin_type)
169 obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")