def Load(self, contentList=[], scrolltotop=0, scrollTo=0.0, *args): browser = uiutil.GetBrowser(self) if browser: self.attrStack = browser.attrStack self.css = browser.css self.LoadFont() self.LoadContent(contentList)
def Startup(self, *args): attrs = self.data.attrs self.name = 'div' browser = uiutil.GetBrowser(self) contentWidth = browser.GetContentWidth() self.width = width = self.GetPercent( attrs.stack['width'] or contentWidth - attrs.stack.get('left', 0), contentWidth - attrs.stack.get('left', 0)) self.height = attrs.stack['height'] or 32 self.SetAlign(uiconst.RELATIVE) self.AddBackground(self, attrs.stack) self.LoadBuffer(self.data.attrs.content, setWidth=self.width) self.CheckOverlaysAndUnderlays() self.width = attrs.width = width or self.contentWidth self.height = attrs.height = attrs.stack.get( 'height', None) or self.contentHeight if attrs.stack['position'] == 'absolute': self.left = attrs.left = attrs.stack.get('left', 0) self.top = attrs.top = attrs.stack.get('top', 0) elif attrs.stack['position'] == 'relative' and attrs.stack['align']: if attrs.stack['align'] == 'center': aL, aT, aW, aH = self.parent.GetAbsolute() self.left = attrs.left = (aW - self.width) / 2 elif attrs.stack['align'] == 'right': aL, aT, aW, aH = self.parent.GetAbsolute() self.left = attrs.left = aW - self.width else: self.left = attrs.left self.top = attrs.top elif attrs.stack['float'] in ('left', 'right'): self.left = attrs.left self.top = attrs.top
def OnSetFocus(self, *args): if self and not self.destroyed and self.parent and self.parent.name == 'inlines': if self.parent.parent and self.parent.parent.sr.node: browser = uiutil.GetBrowser(self) if browser: uthread.new(browser.ShowObject, self) if self.sr.activeframe: self.sr.activeframe.state = uiconst.UI_DISABLED
def OnSetFocus(self, *args): if self and not self.destroyed and self.parent and self.parent.name == 'inlines': browser = uiutil.GetBrowser(self) if browser: browser.ShowNodeIdx(self.parent.parent.sr.node.idx) if self and not self.destroyed and self.sr and self.sr.activeframe: self.sr.activeframe.state = uiconst.UI_DISABLED btns = self.GetDefaultBtnsInSameWnd() if btns: self.SetWndDefaultFrameState(btns, 0)
def __init__(self, attrs, browser): if getattr(attrs, 'action', None) is None: setattr(attrs, 'action', uiutil.GetBrowser(browser).sr.currentURL.split('?')[0]) if str(getattr(attrs, 'method', 'get')).lower() not in ('get', 'post'): setattr(attrs, 'method', 'get') self.submitting = 0 self.attrs = attrs self.browser = browser self.fields = []
def Unload(self): browser = uiutil.GetBrowser(self) if browser and self.sr.inlines: for control in self.sr.inlines.children[:]: if not control: continue if self.destroyed: break control.state = uiconst.UI_HIDDEN uiutil.Transplant(control, browser.sr.cacheContainer) if hasattr(control, 'Unload') and control.loaded: control.Unload()
def OnSetFocus(self, *args): if self.disabled: return if self and not self.destroyed and self.parent and self.parent.name == 'inlines': if self.parent.parent and self.parent.parent.sr.node: browser = uiutil.GetBrowser(self) if browser: uthread.new(browser.ShowObject, self) if self and not self.destroyed and self.sr and self.sr.activeframe: self.sr.activeframe.state = uiconst.UI_DISABLED btns = self.GetDefaultBtnsInSameWnd() if btns: self.SetWndDefaultFrameState(btns, 0)
def LinkEnter(self, link, *args): browser = uiutil.GetBrowser(self) if browser and browser.sr.window and hasattr(browser.sr.window, 'ShowHint'): browser.sr.window.ShowHint(link.hint or link.url) self.sr.hiliteLinks = [] for entry in self.sr.node.scroll.GetNodes(): if not entry.panel: continue if entry.panel.sr.Get('links', None): for item in entry.panel.sr.links.children: if item.name == 'textlink' and item.url == link.url: self.HiliteLink(item) self.sr.hiliteLinks.append(item)
def AddBackground(self, where, s): for i, side in enumerate(['top', 'left', 'right', 'bottom']): if s['border-%s-width' % side]: align = [ uiconst.TOTOP, uiconst.TOLEFT, uiconst.TORIGHT, uiconst.TOBOTTOM ][i] uicls.Line(parent=where, align=align, weight=s['border-%s-width' % side], color=s['border-%s-color' % side], idx=0) if s['background-image'] and where.sr.background: browser = uiutil.GetBrowser(self) currentURL = None if browser: currentURL = browser.sr.currentURL texture, tWidth, tHeight = sm.GetService( 'browserImage').GetTextureFromURL( s['background-image'], currentURL, fromWhere='VirtualTable::AddBackground') pic = uicls.Sprite() pic.left = pic.top = 0 pic.width = tWidth pic.height = tHeight pic.texture = texture row = uicls.Container(name='row', align=uiconst.TOTOP, pos=(0, 0, 0, tHeight), clipChildren=1) if s['background-repeat'] in ('repeat', 'repeat-x'): for x in xrange(max(where.width / tWidth, 2) + 1): row.children.append(pic.CopyTo()) pic.left += pic.width else: row.children.append(pic.CopyTo()) if s['background-repeat'] in ('repeat', 'repeat-y'): for y in xrange(max(where.height / tHeight, 2) + 1): row.height = min(where.height - tHeight * y, row.height) where.sr.background.children.append(row.CopyTo()) else: where.sr.background.children.append(row.CopyTo()) if s['background-color']: uicls.Fill(parent=where, color=s['background-color'])
def OnSubmit(self, *etc): if self.submitting: uicore.Message('Busy') return self.submitting = 1 e = [] for attrs, wnd in self.fields: if not attrs.name: continue if getattr(attrs, 'type', None).lower() == 'submit' and wnd not in etc: continue getval = getattr(self, 'GetValue_%s' % attrs.type.lower(), lambda *args: None) val = getval(wnd, attrs) if val is not None: e.append((attrs.name, val)) d = [] for key, val in e: if type(val) == list: for v in val: if isinstance(v, unicode): v = self.decode(v) d.append((key, v)) else: if isinstance(val, unicode): val = self.decode(val) d.append((key, val)) s = urllib.urlencode(d) if isinstance(s, unicode): s = self.decode(val) browser = uiutil.GetBrowser(self.browser) if not browser: return if getattr(self.attrs, 'method', 'get').lower() == 'get': if 'localsvc:' in self.attrs.action: uicls.BaseLinkCore().LocalSvcCall( self.attrs.action[9:] + ''.join([name for name, value in d])) self.submitting = 0 else: browser.GoTo('?'.join((self.attrs.action, s))) elif self.attrs.method.lower() == 'post': browser.GoTo(self.attrs.action, s)
def OnSetFocus(self, *args): if not self.readonly: sm.GetService('ime').SetFocus(self) if self and not self.destroyed and self.parent and self.parent.name == 'inlines': if self.parent.parent and getattr(self.parent.parent.sr, 'node', None): browser = uiutil.GetBrowser(self) if browser: uthread.new(browser.ShowObject, self) if self.sr.activeframe: self.sr.activeframe.state = uiconst.UI_DISABLED if self.integermode or self.floatmode: self.SetText(self.text) self.caretIndex = self.GetCursorFromIndex(-1) self.ShowCaret() if self.autoselect: self.SelectAll() else: self.RefreshSelectionDisplay()
def ApplyAttributes(self, attributes): uicls.SE_BaseClassCore.ApplyAttributes(self, attributes) parser.ParserBase.Prepare(self) self.sr.selfProxy = _weakref.proxy(self) self.htmldebug = 0 self.xmargin = 0 self.sr.entries = [] self.sr.overlays = [] self.sr.overlays_content = uicls.Container(name='overlays', parent=self, padding=(1, 1, 1, 1)) self.sr.content = uicls.Container(name='content', parent=self) self.sr.underlays_content = uicls.Container(name='underlays_content', parent=self, padding=(1, 1, 1, 1)) self.sr.background = uicls.Container(name='background', parent=self) self.sr.backgroundColorContainer = uicls.Container( name='backgroundColorContainer', parent=self) browser = uiutil.GetBrowser(self) self.sr.browser = browser
def ClickLink(self, parent, URL): if URL.startswith('shellexec:http://') or URL.startswith( 'shellexec:https://'): blue.os.ShellExecute(URL[10:]) return if URL.startswith('localsvc:'): self.LocalSvcCall(URL[9:]) return linkUsed = self.ClickGameLinks(parent, URL) if linkUsed: return if self.CanOpenBrowser(): browser = uicore.cmd.OpenBrowser(URL) else: browser = uiutil.GetBrowser(parent) if browser: if hasattr(browser.sr, 'window') and hasattr( browser.sr.window, 'ShowHint'): browser.sr.window.ShowHint('') browser.GoTo(URL) else: self.UrlHandlerDelegate(parent, 'GoTo', URL)
def AddBackground(self, where, s): contentWidth = uiutil.GetBrowser(self).GetContentWidth() for i, side in enumerate(['top', 'left', 'right', 'bottom']): align = [ uiconst.TOTOP, uiconst.TOLEFT, uiconst.TORIGHT, uiconst.TOBOTTOM ][i] if s['margin-%s' % side]: s['margin-%s' % side] = self.GetPercent( s['margin-%s' % side], contentWidth) uicls.Container(name='margin-%s' % side, parent=where, align=align, padding=(0, 0, int(s['margin-%s' % side]), int(s['margin-%s' % side])), idx=0) if s['border-%s-width' % side]: uicls.Line(parent=where, align=align, weight=s['border-%s-width' % side], color=s['border-%s-color' % side]) if s['background-color']: uicls.Fill(parent=where, color=s['background-color'])
def AddInput(self, attrs, add=1): attrs.vspace = getattr(attrs, 'vspace', 1) if attrs.type is None: attrs.type = 'text' create = getattr(self, 'Create_%s' % attrs.type.lower(), None) if create: wnd = create(attrs) else: wnd = uicls.Container() browser = uiutil.GetBrowser(self.browser) if not browser: return if add: self.fields.append((attrs, wnd)) attrs.control = wnd attrs.align = getattr(attrs, 'align', None) obj = uiutil.Bunch() obj.font = None obj.key = 'input_%s' % attrs.type.lower() obj.type = '<input>' obj.attrs = attrs wnd.state = uiconst.UI_HIDDEN if hasattr(self.browser, 'sr'): uiutil.Transplant(wnd, self.browser.sr.cacheContainer) startup = getattr(self, 'Startup_%s' % attrs.type.lower(), None) if startup: startup(wnd, attrs) obj.width = wnd.width + 5 obj.height = wnd.height + 5 obj.valign = 1 if add: obj.control = wnd wnd.loaded = 1 else: wnd.Close() return obj
def LinkExit(self, link, *args): browser = uiutil.GetBrowser(self) if browser and browser.sr.window and hasattr(browser.sr.window, 'ShowHint'): browser.sr.window.ShowHint('') for each in self.sr.hiliteLinks: uiutil.Flush(each)
def GetFixedURL(parent, url): browser = uiutil.GetBrowser(parent) currentURL = None if browser and hasattr(browser.sr, 'currentURL'): currentURL = browser.sr.currentURL return urlparse.urljoin(currentURL, url)