class loader: def __init__(self, img, ani_xy=100): self.status = 0 self.ani_xy = ani_xy self.img = img.resize((self.ani_xy, self.ani_xy)) self.gif = TopWindow() self.gif.size = (ani_xy, ani_xy) self.gif.position = self.get_mid((ani_xy, ani_xy)) self.txt = TopWindow() self.blank = graphics.Image.new((1, 1)) self.ani_xy = ani_xy def get_mid(self, d): return ((scr()[0] - d[0]) / 2, (scr()[1] - d[1]) / 2) def addtext(self, text, update=0): size = self.img.measure_text(text) t_w, t_h = (size[0][2], (size[0][1] * -1) + size[0][3]) self.text = graphics.Image.new((t_w, t_h)) self.text.text((0, 12), text) self.txt.size = (t_w, t_h) mid = self.get_mid((t_w, self.ani_xy)) self.txt.position = (mid[0], mid[1] + self.ani_xy) if update: self.disp_text() def rotate(self): e32.ao_sleep(0.01) self.gif.remove_image(self.img, (0, 0)) self.img = self.img.transpose(graphics.ROTATE_90) self.gif.add_image(self.img, (0, 0)) def start(self): self.gif.show() self.txt.show() self.status = 1 def stop(self): self.gif.hide() self.txt.hide() self.status = 0 def disp_text(self): if not self.status: self.start() #self.txt.add_image(self.blank,(0,0)) try: self.txt.remove_image(self.text) except ValueError, e: pass #print 'not removed e='+str(e) self.txt.images = [] self.txt.add_image(self.text, (0, 0)) self.gif.add_image(self.img, (0, 0)) del self.text self.rotate()
class loader: def __init__(self,img,ani_xy=100): self.status=0 self.wait=0.01 self.ani_xy=ani_xy self.img=graphics.Image.open(img).resize((self.ani_xy,self.ani_xy)) self.gif=TopWindow() self.gif.size=(ani_xy, ani_xy) self.gif.position=self.get_mid((ani_xy,ani_xy)) self.txt=TopWindow() self.blank=graphics.Image.new((1,1)) self.ani_xy=ani_xy def get_mid(self, d): return ((scr()[0]-d[0])/2,(scr()[1]-d[1])/2) def addtext(self,text,update=0): size=self.img.measure_text(text) t_w,t_h=(size[0][2],(size[0][1]*-1)+size[0][3]) self.text=graphics.Image.new((t_w,t_h)) self.text.text((0,12), text) self.txt.size=(t_w,t_h) mid=self.get_mid((t_w,self.ani_xy)) self.txt.position=(mid[0],mid[1]+self.ani_xy) if update:self.disp_text() def rotate(self): def rem(): try:self.gif.remove_image(self.img, (0,0)) except:pass e32.ao_sleep(self.wait,rem) self.img=self.img.transpose(graphics.ROTATE_90) self.gif.add_image(self.img, (0,0)) def start(self): self.gif.show() self.txt.show() self.status=1 def stop(self): self.gif.hide() self.txt.hide() self.status=0 def disp_text(self): if not self.status:self.start() #self.txt.add_image(self.blank,(0,0)) try:self.txt.remove_image(self.text); except ValueError,e:pass#print 'not removed e='+str(e) self.txt.images=[] self.txt.add_image(self.text,(0,0)) self.gif.add_image(self.img, (0,0)) del self.text self.rotate()
class Windows_menu: __module__ = __name__ def __init__(self, items, title=u'Menu:'): self.items = items self.title = title self.capture = KeyCapturer(self.keys_answer) self.window_main = TopWindow() self.window_add1 = TopWindow() self.window_add2 = TopWindow() self.y, self.y1, self.y2, self.flag1, self.flag2 = 0, 0, 0, 0, 0 try: self.size_display = aw.app.layout(aw.EScreen)[0] except AttributeError: self.size_display = (176, 208) def initialization(self): try: self.window_main.shadow = self.shadow except AttributeError: self.window_main.shadow = 2 try: self.x_pos = self.x_pos except AttributeError: self.x_pos = 5 try: self.y_pos = self.y_pos except AttributeError: self.y_pos = 5 try: self.width = self.width except AttributeError: self.width = self.size_display[0] * 30 / 42 try: self.color_background = self.color_background except AttributeError: self.color_background = 0xffffff try: self.color_background_upper = self.color_background_upper except AttributeError: self.color_background_upper = self.color_background try: self.color_cursor = self.color_cursor except AttributeError: self.color_cursor = 0xaaaaaa try: self.color_text = self.color_text except AttributeError: self.color_text = 0 try: self.color_text_cursor = self.color_text_cursor except AttributeError: self.color_text_cursor = self.color_text try: self.color_text_upper = self.color_text_upper except AttributeError: self.color_text_upper = self.color_text try: self.x_pos_add1 = self.x_pos_add1 except AttributeError: self.x_pos_add1 = self.x_pos + 20 try: self.y_pos_add1 = self.y_pos_add1 except AttributeError: self.y_pos_add1 = self.y_pos + 25 try: self.width_add1 = self.width_add1 except AttributeError: self.width_add1 = self.width try: self.color_background_add1 = self.color_background_add1 except AttributeError: self.color_background_add1 = self.color_background try: self.color_cursor_add1 = self.color_cursor_add1 except AttributeError: self.color_cursor_add1 = self.color_cursor try: self.color_text_add1 = self.color_text_add1 except AttributeError: self.color_text_add1 = self.color_text try: self.color_text_cursor_add1 = self.color_text_cursor_add1 except AttributeError: self.color_text_cursor_add1 = self.color_text_cursor try: self.x_pos_add2 = self.x_pos_add2 except AttributeError: self.x_pos_add2 = self.x_pos_add1 + 20 try: self.y_pos_add2 = self.y_pos_add2 except AttributeError: self.y_pos_add2 = self.y_pos_add1 + 8 try: self.width_add2 = self.width_add2 except AttributeError: self.width_add2 = self.width_add1 try: self.color_background_add2 = self.color_background_add2 except AttributeError: self.color_background_add2 = self.color_background_add1 try: self.color_cursor_add2 = self.color_cursor_add2 except AttributeError: self.color_cursor_add2 = self.color_cursor_add1 try: self.color_text_add2 = self.color_text_add2 except AttributeError: self.color_text_add2 = self.color_text_add1 try: self.color_text_cursor_add2 = self.color_text_cursor except AttributeError: self.color_text_cursor_add2 = self.color_text_add2 def keys(self): self.capture.keys = [63495, 63496, 63497, 63498, 63557, 63554 ] + [i for i in xrange(48, 58)] self.capture.forwarding = 0 aw.app.focus = self.focus self.capture.start() def focus(self, foc): if not foc: self.stop_menu() def stop_menu(self): self.window_main.hide() self.window_add1.hide() self.window_add2.hide() self.capture.stop() self.y1, self.y2, self.flag1, self.flag2 = 0, 0, 0, 0 aw.app.exit_key_handler = self.exit_key_handler_old aw.app.exit_key_text = self.exit_key_text_old aw.app.menu_key_text = self.menu_key_text_old def start_menu(self, exit_key_text=u'Cancel'): self.exit_key_handler_old = aw.app.exit_key_handler self.exit_key_text_old = aw.app.exit_key_text self.menu_key_text_old = aw.app.menu_key_text aw.app.menu_key_text = u'Ok' aw.app.exit_key_text = exit_key_text aw.app.exit_key_handler = self.stop_menu self.keys() self.picture() def keys_answer(self, code): if code in xrange(48, 58): y = int(chr(code)) - 1 if y < 0: y = 9 if self.flag2: if len(self.items[self.y][2][self.y1][2]) >= y + 1: self.y2 = y self.picture2() aw.e32.ao_sleep(0.2) code = 63557 elif self.flag1: if len(self.items[self.y][2]) >= y + 1: self.y1 = y self.picture1() aw.e32.ao_sleep(0.2) code = 63557 else: if len(self.items) >= y + 1: self.y = y self.picture() aw.e32.ao_sleep(0.2) code = 63557 elif code == 63498: if self.flag2: self.y2 += 1 if self.y2 > len(self.items[self.y][2][self.y1][2]) - 1: self.y2 = 0 self.picture2() return None elif self.flag1: self.y1 += 1 if self.y1 > len(self.items[self.y][2]) - 1: self.y1 = 0 self.picture1() return None else: self.y += 1 if self.y > len(self.items) - 1: self.y = 0 self.picture() return None elif code == 63497: if self.flag2: self.y2 -= 1 if self.y2 < 0: self.y2 = len(self.items[self.y][2][self.y1][2]) - 1 self.picture2() return None elif self.flag1: self.y1 -= 1 if self.y1 < 0: self.y1 = len(self.items[self.y][2]) - 1 self.picture1() return None else: self.y -= 1 if self.y < 0: self.y = len(self.items) - 1 self.picture() return None elif code == 63495: if self.flag2: self.window_add2.hide() self.y2, self.flag2 = 0, 0 elif self.flag1: self.window_add1.hide() self.y1, self.flag1 = 0, 0 return None elif code == 63496: if self.flag1 and self.items[self.y][2][ self.y1][1] is '2' and not self.flag2: self.flag2 = 1 self.picture2() return None elif self.items[self.y][1] is '1' and not self.flag1: self.flag1 = 1 self.picture1() return None if code == 63557 or code == 63554: if not self.flag1: if self.items[self.y][1] is not '1': self.window_main.hide() aw.app.exit_key_handler = self.exit_key_handler_old aw.app.exit_key_text = self.exit_key_text_old aw.app.menu_key_text = self.menu_key_text_old self.items[self.y][1](*self.items[self.y][2:]) self.capture.stop() return None elif self.items[self.y][1] is '1': self.flag1 = 1 self.picture1() return None elif self.flag1 and not self.flag2: if self.items[self.y][2][self.y1][1] is not '2': self.window_main.hide() self.window_add1.hide() aw.app.exit_key_handler = self.exit_key_handler_old aw.app.exit_key_text = self.exit_key_text_old aw.app.menu_key_text = self.menu_key_text_old self.items[self.y][2][self.y1][1]( *self.items[self.y][2][self.y1][2:]) self.capture.stop() self.y1, self.flag1 = 0, 0 return None elif self.items[self.y][2][self.y1][1] is '2': self.flag2 = 1 self.picture2() return None elif self.flag2: self.window_main.hide() self.window_add1.hide() self.window_add2.hide() aw.app.exit_key_handler = self.exit_key_handler_old aw.app.exit_key_text = self.exit_key_text_old aw.app.menu_key_text = self.menu_key_text_old self.items[self.y][2][self.y1][2][self.y2][1]( *self.items[self.y][2][self.y1][2][self.y2][2:]) self.capture.stop() self.y1, self.y2, self.flag1, self.flag2 = 0, 0, 0, 0 return None def picture(self): try: self.window_main.remove_image(self.img, (0, 0)) del self.img except Exception: pass size = (self.width, len(self.items) * 20 + 20) self.img = Image.new(size) self.window_main.size = size self.window_main.position = (self.x_pos, self.y_pos) self.img.rectangle((0, 0, size[0], size[1]), 0x0, self.color_background) self.img.rectangle((1, 1, size[0] - 1, 20), fill=self.color_background_upper) self.img.rectangle( (2, self.y * 20 + 22, size[0] - 2, self.y * 20 + 38), fill=self.color_cursor) a = self.img.measure_text(self.title, 'annotation', maxwidth=self.width - 15) if len(self.title) > a[2]: self.img.text(((self.width - a[0][2]) / 2, 14), self.title[:a[2] - 1] + u'...', self.color_text_upper, 'annotation') else: self.img.text(((self.width - a[0][2]) / 2, 14), self.title, self.color_text_upper, 'annotation') d, n = 20, 0 for t in self.items: n += 1 if n - 1 is not self.y: color_text = self.color_text else: color_text = self.color_text_cursor if n < 10: i = unicode(n) elif n == 10: i = u'0' else: i = u'' a = self.img.measure_text(i + u' ' + t[0], 'annotation', maxwidth=self.width - 23) if len(i + u' ' + t[0]) > a[2]: self.img.text((4, 14 + d), i + u' ' + t[0][:a[2] - 2] + u'...', color_text, 'annotation') else: self.img.text((4, 14 + d), i + u' ' + t[0], color_text, 'annotation') if t[1] is '1': self.img.polygon((self.width - 9, 16 + d, self.width - 9, 4 + d, self.width - 3, 10 + d), fill=color_text) d += 20 self.window_main.add_image(self.img, (0, 0)) self.window_main.show() def picture1(self): try: self.window_add1.remove_image(self.img_add1, (0, 0)) del self.img_add1 except Exception: pass size = (self.width_add1, len(self.items[self.y][2]) * 20) self.img_add1 = Image.new(size) self.window_add1.size = size self.window_add1.position = (self.x_pos_add1, self.y_pos_add1) self.img_add1.rectangle((0, 0, size[0], size[1]), 0x0, self.color_background_add1) self.img_add1.rectangle( (2, self.y1 * 20 + 2, size[0] - 2, self.y1 * 20 + 18), fill=self.color_cursor_add1) d, n = 0, 0 for t in self.items[self.y][2]: n += 1 if n - 1 is not self.y1: color_text = self.color_text_add1 else: color_text = self.color_text_cursor_add1 if n < 10: i = unicode(n) elif n == 10: i = u'0' else: i = u'' a = self.img_add1.measure_text(i + u' ' + t[0], 'annotation', maxwidth=self.width_add1 - 23) if len(i + u' ' + t[0]) > a[2]: self.img_add1.text((4, 14 + d), i + u' ' + t[0][:a[2] - 2] + u'...', color_text, 'annotation') else: self.img_add1.text((4, 14 + d), i + u' ' + t[0], color_text, 'annotation') if t[1] is '2': self.img_add1.polygon( (self.width_add1 - 9, 16 + d, self.width_add1 - 9, 4 + d, self.width_add1 - 3, 10 + d), fill=color_text) d += 20 self.window_add1.add_image(self.img_add1, (0, 0)) self.window_add1.show() def picture2(self): try: self.window_add2.remove_image(self.img_add2, (0, 0)) del self.img_add2 except Exception: pass size = (self.width_add2, len(self.items[self.y][2][self.y1][2]) * 20) self.img_add2 = Image.new(size) self.window_add2.size = size self.window_add2.position = (self.x_pos_add2, self.y_pos_add2) self.img_add2.rectangle((0, 0, size[0], size[1]), 0x0, self.color_background_add2) self.img_add2.rectangle( (2, self.y2 * 20 + 2, size[0] - 2, self.y2 * 20 + 18), fill=self.color_cursor_add2) d, n = 0, 0 for t in self.items[self.y][2][self.y1][2]: n += 1 if n - 1 is not self.y2: color_text = self.color_text_add2 else: color_text = self.color_text_cursor_add2 if n < 10: i = unicode(n) elif n == 10: i = u'0' else: i = u'' a = self.img_add2.measure_text(i + u' ' + t[0], 'annotation', maxwidth=self.width_add2 - 23) if len(i + u' ' + t[0]) > a[2]: self.img_add2.text((4, 14 + d), i + u' ' + t[0][:a[2] - 2] + u'...', color_text, 'annotation') else: self.img_add2.text((4, 14 + d), i + u' ' + t[0], color_text, 'annotation') d += 20 self.window_add2.add_image(self.img_add2, (0, 0)) self.window_add2.show() # the end :)
class Pbar(object): def __init__(self): self.old_func_focus = appuifw.app.focus appuifw.app.focus = self.focus self.focusflag = 1 if e32.s60_version_info >= (2, 8): self.scr = appuifw.app.layout(appuifw.EScreen)[0] else: self.scr = (176, 208) img_none = Image.new((1, 1)) h = img_none.measure_text(u'by', 'annotation')[0] self.__h_text = h[3] - h[1] self.__dislocation_text = h[3] h2 = img_none.measure_text(u'by', 'dense')[0] h_text2 = h2[3] - h2[1] self.__dislocation_text2 = h2[3] self.__sizeW = 6 + h_text2 self.__sizeY = self.__sizeW + self.__h_text * 2 + 6 self.img = Image.new((self.scr[0] - 10, self.__sizeY)) self.top_shadow = TopWindow() x = max(self.scr) self.top_shadow.position = (-x, -x) self.top_shadow.shadow = x / 2 self.window = TopWindow() self.window.size = (self.scr[0] - 10, self.__sizeY) self.window.position = (5, self.scr[1] / 2 - self.__sizeY / 2) self.color_background = 0x555500 self.color_text = 0xffffff self.color_background2 = 0xffffff self.color_text2 = 0x707070 self.img1 = Image.new((self.scr[0] - 22, self.__sizeW), mode = 'RGB') self.img2 = Image.new((self.scr[0] - 22, self.__sizeW - 2), mode = 'RGB') self.img_gradient = Image.new((self.scr[0] - 22, self.__sizeW - 2), mode = 'RGB') r = 255 / ((self.scr[0] - 22) / 4.0) for i in xrange(self.scr[0] - 22): if i <= (self.scr[0] - 22) / 4.0: self.img_gradient.line((i, 0, i, self.__sizeW - 2), (255, int(i * r), 0)) elif (self.scr[0] - 22) / 4.0 < i <= (self.scr[0] - 22) / 2.0: self.img_gradient.line((i, 0, i, self.__sizeW - 2), (int(255 - (i - (self.scr[0] - 22) / 4.0) * r), 255, 0)) elif (self.scr[0] - 22) / 2.0 < i <= (self.scr[0] - 22) * 3 / 4.0: self.img_gradient.line((i, 0, i, self.__sizeW - 2), (0, 255, int((i - (self.scr[0] - 22) / 2.0) * r))) else: self.img_gradient.line((i, 0, i, self.__sizeW - 2), (0, int(255 - (i - (self.scr[0] - 22) * 3 /4.0) * r), 255)) e32.ao_yield() def set_posY(self, pos): if not isinstance(pos, int): return pos = min(self.scr[1] - self.__sizeY, max(0, pos)) self.window.position = (5, pos) position_y = property(lambda self: self.window.position[1], set_posY) size_y = property(lambda self: self.__sizeY) def x_text(self, text, font, w): xx = self.img.measure_text(text, font, maxwidth = w) if xx[2] < len(text): text = '%s%s' % (text[:xx[2] - 1], u'...') xx = self.img.measure_text(text, font) return text, (self.scr[0] - xx[0][2]) / 2 def show(self, goto, full, text=u'Loading...', shadow=1, stop=1): if goto > full or \ not self.focusflag or \ not full or \ goto < 0: return if isinstance(text, (tuple, list)): text, text2 = text else: text2 = None text, xx = self.x_text(text, 'annotation', self.scr[0] - 26) xx -=5 try: self.window.remove_image(self.img) except ValueError: pass self.img.rectangle((0, 0, self.img.size[0], self.__sizeY), 0xcccccc, self.color_background) x = abs((self.img.size[0] - 12) * goto / full) self.img1.clear(self.color_background2) a, b = self.img1.size self.img2.blit(self.img_gradient) if text2: text2, xx2 = self.x_text(text2, 'dense', self.scr[0] - 37) xx2 -= 11 self.img1.text((xx2, b - 3 - self.__dislocation_text2), text2, self.color_text2, 'dense') self.img2.text((xx2, b - 4 - self.__dislocation_text2), text2, 0, 'dense') self.img1.blit(self.img2, source = (0, 0, x, self.__sizeW), target = (0, 1)) self.img1.rectangle((0, 0, a, b), 0xcccccc) self.img.blit(self.img1, target = (6, self.__sizeY - self.__sizeW - 6)) self.img.text((xx, self.__sizeY - self.__sizeW - 6 - self.__h_text / 2 - self.__dislocation_text), text, self.color_text, 'annotation') self.window.add_image(self.img, (0, 0)) if shadow and not self.top_shadow.visible: self.top_shadow.show() self.window.show() e32.ao_yield() if goto == full and stop: e32.ao_sleep(0.1, self.stop) def stop(self): self.top_shadow.hide() self.window.hide() def focus(self, f): self.focusflag = f if not self.focusflag: self.stop() if self.old_func_focus: self.old_func_focus(self.focusflag)