def GetMLStringTexture(self, font, text, height, rect, align, color): if not text: return self.DefaultFailReturn itm = (font, text, int(height), rect, color) if self.map.has_key(itm): return self.map[itm] elif self.premap.has_key(itm): ret = self.premap[itm] self.map[itm] = ret return ret else: utext = koan.ToUnicode(text) uFont = koan.ToUnicode(font) if koan.useRTL: uFont += u"&RTL" t = self.window.render.CFontTexture(self.window.render) if t is None: return self.DefaultFailReturn succeed, w, h, adp = t.CreateML(uFont, height, rect[0], rect[1], align, color[0], color[1], color[2], color[3], utext) if not succeed: return self.DefaultFailReturn self.map[itm] = (t, (w, h, adp)) return t, (w, h, adp)
def __onCombolist(self): if len(self.data): from menu import PopupMenu, MenuItem m = PopupMenu(self.window) m.applyStyle(self.menuStyle) w = self.width for o in self.data: itm = MenuItem(m) itm.applyStyle(self.itemStyle) itm.align = self.align itm.iconWidth = 0 itm.header = koan.ToUnicode(o) try: itm.enabled = o.enabled except: pass itm.command = str(self.data.index(o)) itm.width = w if o == self.data[self.index]: itm.setFocus() m.xy = self.local2global(0, self.height) m.width = w ret = m.doModal() self.setFocus() if type(ret) is str or type(ret) is unicode: try: self.index = int(ret) except: pass
def LoadAnimatedTexture(self, filename, maxw=-1, maxh=-1): if not filename: raise ValueError, "filename is a zero string" if maxw == -1 and maxh == -1: maxw, maxh = self.window._window.GetDesktopSize() folder, fn = os.path.split(filename) filenames = [] count = 0 duration = 1.0 loop = True static_tex = '' dom = LoadXMLFile(filename) tag_name = dom.documentElement.tagName if tag_name == 'AnimatedTexture': mtexs = dom.getElementsByTagName(tag_name) for mtex in mtexs: try: duration = float(mtex.getAttribute('duration')) loop = eval(mtex.getAttribute('loop')) static_tex = mtex.getAttribute('static') except: pass if static_tex and not koan.useAnimation: return self.LoadTexture(os.path.join(folder, static_tex), maxw, maxh) for tex in mtex.childNodes: try: if tex.tagName == 'Texture': filenames.append( os.path.join(folder, tex.getAttribute('filename'))) count += 1 except: pass t = self.CreateAnimatedTexture(filenames, duration, loop, maxw, maxh) if t: t.SetName(koan.ToUnicode(filename)) return t
def LoadTexture(self, filename, maxw=-1, maxh=-1, gamma=None, *argv, **argd): if not filename: #raise ValueError, "filename is a zero string" print "filename is a zero string" return None if maxw == -1 and maxh == -1: maxw, maxh = self.window._window.GetDesktopSize() tex = self.window.render.CFileTexture(self.window.render) if '|' in filename: filename, margin = filename.split('|') filename = filename.strip() margin = margin.strip() else: margin = None if gamma and len(gamma) > 4: gamma = gamma[:4] + tuple(gamma[4:][0].replace(' ', '').split('->')) if tex.Create(koan.ToUnicode(filename), maxw, maxh, gamma, argd.get('async', False)): if margin: margin = margin.strip()[1:-1] if ',' in margin: m = [eval(i) for i in margin.split(",")] else: m = [eval(i) for i in margin.split(" ")] tex.SetMargin(m[0], m[1], m[2], m[3]) if len(m) > 4: tex.SetHollow('hollow' in m) tex.SetFilter(0x10 if 'linear' in m else 0x20 if 'point' in m else 0x0) return tex return None
def GetStringTextureSize(font, text, height): if font == '': font = koan.defaultFont return GetFontImageSize(koan.ToUnicode(font), height, 0, koan.ToUnicode(text), 0)
def __onChangeSelect(self): self.text = koan.ToUnicode( self.selectedData) if self.selectedData else '' if self.selectedData: self.invoke('Select Changed', self.index)