1 from com import Component, msgs
2 from ui.Button import Button
3 from ui.Label import Label
4 from ui.layout import Arrangement
5 from ui.Window import Window
6 from theme import theme
11 _PORTRAIT_ARRANGEMENT = """
13 <widget name="lbl_code" x1="1%" y1="0%" x2="99%" y2="15%"/>
15 <widget name="btn_1" x1="1%" y1="15%" x2="33%" y2="31%"/>
16 <widget name="btn_2" x1="34%" y1="15%" x2="66%" y2="31%"/>
17 <widget name="btn_3" x1="67%" y1="15%" x2="99%" y2="31%"/>
19 <widget name="btn_4" x1="1%" y1="32%" x2="33%" y2="48%"/>
20 <widget name="btn_5" x1="34%" y1="32%" x2="66%" y2="48%"/>
21 <widget name="btn_6" x1="67%" y1="32%" x2="99%" y2="48%"/>
23 <widget name="btn_7" x1="1%" y1="49%" x2="33%" y2="65%"/>
24 <widget name="btn_8" x1="34%" y1="49%" x2="66%" y2="65%"/>
25 <widget name="btn_9" x1="67%" y1="49%" x2="99%" y2="65%"/>
27 <widget name="btn_star" x1="1%" y1="66%" x2="33%" y2="82%"/>
28 <widget name="btn_0" x1="34%" y1="66%" x2="66%" y2="82%"/>
29 <widget name="btn_hash" x1="67%" y1="66%" x2="99%" y2="82%"/>
31 <widget name="btn_send" x1="1%" y1="83%" x2="66%" y2="99%"/>
32 <widget name="btn_back" x1="67%" y1="83%" x2="99%" y2="99%"/>
37 class MainWindow(Component, Window):
41 self.__current_code = ""
44 Component.__init__(self)
45 Window.__init__(self, Window.TYPE_TOPLEVEL)
46 self.set_title("USSD Pad")
47 self.set_portrait_mode(True)
48 self.connect_closed(self.__on_close_window)
50 self.__arr = Arrangement()
53 self.__lbl_code = Label("", theme.font_ui_plain, theme.color_ui_text)
54 self.__arr.add(self.__lbl_code, "lbl_code")
56 for lbl, name in [("1", "btn_1"),
69 ("BACK", "btn_back")]:
71 btn.connect_clicked(self.__on_button, lbl)
72 self.__arr.add(btn, name)
75 self.__arr.set_xml(_PORTRAIT_ARRANGEMENT)
77 self.set_visible(True)
80 def set_size(self, w, h):
82 old_w, old_h = self.get_size()
83 if ((w, h) != (old_w, old_h)):
84 Window.set_size(self, w, h)
85 self.__arr.set_geometry(0, 0, w, h)
88 def render_this(self):
90 w, h = self.get_size()
91 screen = self.get_screen()
93 screen.fill_area(0, 0, w, h, theme.color_ui_background)
95 #self.__arr.set_geometry(0, 0, w, h)
98 def __on_close_window(self):
103 def __on_button(self, lbl):
106 msg = self.call_service(msgs.USSD_SVC_SEND, self.__current_code)
109 self.__lbl_code.set_text(msg or " ")
111 elif (lbl == "BACK"):
112 self.__set_code(self.__current_code[:-1])
115 self.__set_code(self.__current_code + lbl)
118 def __set_code(self, new_code):
120 self.__current_code = new_code
121 self.__lbl_code.set_text(new_code or " ")