Esempio n. 1
0
 def ApplyAttributes(self, attributes):
     Window.ApplyAttributes(self, attributes)
     self.MakeUnResizeable()
     self.controller = attributes.controller
     self.btnGroup = ButtonGroup(parent=self.sr.main, idx=0, line=True)
     self.btnGroup.AddButton(GetByLabel(self.confirmLabelPath),
                             self.OnConfirmClicked)
     self.btnGroup.AddButton(GetByLabel('UI/Commands/Cancel'), self.Cancel)
     self.groupNameField = SinglelineEdit(parent=self.sr.main,
                                          align=uiconst.TOTOP,
                                          label=GetByLabel(
                                              self.nameLabelPath),
                                          padding=4,
                                          top=10,
                                          maxLength=30)
     EveLabelSmall(name='titleHeader',
                   parent=self.sr.main,
                   text=GetByLabel(self.descriptionLabelPath),
                   align=uiconst.TOTOP,
                   top=6,
                   padLeft=4)
     self.groupDescField = EditPlainText(parent=self.sr.main,
                                         padding=(4, 0, 4, 4),
                                         maxLength=200)
     self.PopulateFields()
Esempio n. 2
0
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     self.bioClient = None
     self.edit = EditPlainText(parent=self,
                               maxLength=MAXBIOLENGTH,
                               showattributepanel=1,
                               padding=(0, const.defaultPadding, 0,
                                        const.defaultPadding))
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     self.infoType = attributes.infoType
     self.itemID = attributes.itemID
     self.initialized = False
     self.oldText = None
     self.edit = EditPlainText(parent=self,
                               padding=const.defaultPadding,
                               align=uiconst.TOALL,
                               maxLength=5000,
                               showattributepanel=True)
Esempio n. 4
0
class BioPanel(Container):
    default_name = 'BioPanel'

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.bioClient = None
        self.edit = EditPlainText(parent=self,
                                  maxLength=MAXBIOLENGTH,
                                  showattributepanel=1,
                                  padding=(0, const.defaultPadding, 0,
                                           const.defaultPadding))

    def LoadBioFromServer(self):
        self.bioServer = ''
        if not self.bioClient:
            bio = sm.RemoteSvc('charMgr').GetCharacterDescription(
                session.charid)
            if bio is not None:
                self.bioClient = bio
            else:
                self.bioClient = ''
        if self.bioClient:
            self.bioServer = self.bioClient

    def LoadPanel(self, *args):
        self.LoadBioFromServer()
        bio = self.bioServer or GetByLabel(
            'UI/CharacterSheet/CharacterSheetWindow/BioEdit/HereYouCanTypeBio')
        self.edit.SetValue(bio)

    def AutoSaveBio(self):
        newbio = self.edit.GetValue()
        defaultBioString = GetByLabel(
            'UI/CharacterSheet/CharacterSheetWindow/BioEdit/HereYouCanTypeBio')
        newbio = newbio.replace(defaultBioString, '')
        if not len(StripTags(newbio)):
            newbio = ''
        self.bioClient = newbio
        if newbio.strip() != self.bioServer:
            uthread.new(self._AutoSaveBio, newbio)
            self.bioServer = newbio

    def _AutoSaveBio(self, newbio):
        sm.RemoteSvc('charMgr').SetCharacterDescription(newbio)

    def UnloadPanel(self):
        self.AutoSaveBio()

    def Close(self):
        if self.display:
            self.AutoSaveBio()
        Container.Close(self)
Esempio n. 5
0
 def CreateLocationSelector(self):
     EveLabelSmall(
         parent=self.sr.main,
         text=
         '<color=orange>This is a tool for automating visits to solar systems and locations within them. There are several actions available while visiting each location.',
         align=uiconst.TOTOP,
         padding=4)
     EveLabelSmall(parent=self.sr.main,
                   text='Systems, Constellations or Regions',
                   align=uiconst.TOTOP,
                   padding=4)
     self.locationsEdit = EditPlainText(parent=self.sr.main,
                                        align=uiconst.TOTOP,
                                        height=50,
                                        padding=4)
class PanelNotes(Container):
    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.infoType = attributes.infoType
        self.itemID = attributes.itemID
        self.initialized = False
        self.oldText = None
        self.edit = EditPlainText(parent=self,
                                  padding=const.defaultPadding,
                                  align=uiconst.TOALL,
                                  maxLength=5000,
                                  showattributepanel=True)

    def Close(self, *args):
        self.SaveNote()
        Container.Close(self)

    def Load(self):
        if self.initialized:
            return
        self.initialized = True
        text = ''
        if self.itemID:
            text = sm.RemoteSvc('charMgr').GetNote(self.itemID)
        self.edit.SetValue(text, scrolltotop=1)
        self.oldText = text

    def SaveNote(self, closing=0, *args):
        if not self.itemID:
            return
        if self.oldText is None:
            return
        text = self.edit.GetValue()
        if text is None:
            return
        toSave = None
        if len(uiutil.StripTags(text)):
            if self.oldText != text:
                toSave = text[:5000]
        elif self.oldText:
            toSave = ''
        if toSave is not None:
            uthread.new(sm.RemoteSvc('charMgr').SetNote, self.itemID, toSave)
Esempio n. 7
0
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     padding = 30
     self.termHeaderLabel = EveCaptionLarge(name='termHeaderLabel',
                                            parent=self,
                                            align=uiconst.TOTOP,
                                            text='',
                                            padLeft=padding + 4,
                                            padTop=20)
     self.contentRightCont = Container(name='contentRightCont',
                                       parent=self,
                                       align=uiconst.TORIGHT,
                                       width=128,
                                       padRight=36)
     self.height = 300
     self.longTextEdit = EditPlainText(name='longTextEdit',
                                       parent=self,
                                       align=uiconst.TOTOP,
                                       readonly=True,
                                       setvalue='abc',
                                       padding=(padding, 0, padding, 0))
     self.longTextEdit.sr.maincontainer.padding = 0
     self.longTextEdit.DisableScrolling()
     self.longTextEdit.EnableAutoSize()
     self.longTextEdit.OnContentSizeChanged = self.OnContentChanged
     self.longTextEdit.HideBackground()
     self.longTextEdit.RemoveActiveFrame()
     self.termSpriteCont = Container(name='termSpriteCont',
                                     parent=self.contentRightCont,
                                     pos=(0, 0, 128, 128),
                                     align=uiconst.TOTOP)
     self.termSprite = Sprite(
         name='termSprite',
         parent=self.termSpriteCont,
         pos=(0, 0, 128, 128),
         texturePath=
         'res:/UI/Texture/Classes/ShipTree/groupIcons/frigate.png',
         align=uiconst.CENTER)
     self.loreTextLabel = EveLabelMedium(name='termNameLabel',
                                         text='',
                                         parent=self.contentRightCont,
                                         align=uiconst.TOTOP)
Esempio n. 8
0
 def ApplyAttributes(self, attributes):
     Window.ApplyAttributes(self, attributes)
     self.default_caption = attributes.Get('caption', self.default_caption)
     bodyText = attributes.bodyText
     parent = self.sr.main
     EditPlainText(name='myTextEdit',
                   parent=parent,
                   align=uiconst.TOALL,
                   setvalue=bodyText)
     textWidth, textHeight = Label.MeasureTextSize(bodyText)
     self.width, self.height = textWidth + 20, textHeight + 40
Esempio n. 9
0
class NameAndDescBaseWnd(Window):
    default_name = 'nameAndDescBaseWnd'
    default_windowID = 'NameAndDescBaseWnd'
    default_width = 200
    default_height = 200
    default_topParentHeight = 0
    confirmLabelPath = ''
    nameLabelPath = ''
    descriptionLabelPath = ''

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.MakeUnResizeable()
        self.controller = attributes.controller
        self.btnGroup = ButtonGroup(parent=self.sr.main, idx=0, line=True)
        self.btnGroup.AddButton(GetByLabel(self.confirmLabelPath),
                                self.OnConfirmClicked)
        self.btnGroup.AddButton(GetByLabel('UI/Commands/Cancel'), self.Cancel)
        self.groupNameField = SinglelineEdit(parent=self.sr.main,
                                             align=uiconst.TOTOP,
                                             label=GetByLabel(
                                                 self.nameLabelPath),
                                             padding=4,
                                             top=10,
                                             maxLength=30)
        EveLabelSmall(name='titleHeader',
                      parent=self.sr.main,
                      text=GetByLabel(self.descriptionLabelPath),
                      align=uiconst.TOTOP,
                      top=6,
                      padLeft=4)
        self.groupDescField = EditPlainText(parent=self.sr.main,
                                            padding=(4, 0, 4, 4),
                                            maxLength=200)
        self.PopulateFields()

    def PopulateFields(self):
        pass

    def OnConfirmClicked(self, *args):
        name = self.groupNameField.GetValue().strip()
        desc = self.groupDescField.GetValue().strip()
        if name:
            self.Confirm(name, desc)
            self.CloseByUser()
        else:
            uicore.Message('uiwarning03')

    def Confirm(self, name, desc):
        pass

    def Cancel(self, *args):
        self.CloseByUser()
Esempio n. 10
0
 def AddTextedit(self):
     """
          textedit (editable multi-line textbox)
          
          PARAMS:
             - height [int]            : text container height (not font height)
             - setvalue [str]          : initial text in edit
             - text [str]              : same as setvalue
             - label [str]             : text edit label. If set to "_hide", it gets hidden and the edit is moved accordingly
             - maxlength [int]         : maximum number of input characters
             - showAttribPanel [bool]  : the text attribute panel is shown (default False)
             - readonly [bool]         : text is read only (default False)
             - hidebackground [bool]   : hide textbox background (default False)
     """
     self.new = uiprimitives.Container(name='texteditField',
                                       parent=self.parent,
                                       align=uiconst.TOTOP,
                                       height=self.type.get('height', 68))
     self.code = EditPlainText(setvalue=self.type.get('setvalue', '')
                               or self.type.get('text', ''),
                               parent=self.new,
                               padding=(self.leftPush, 2, 0, 2),
                               readonly=self.type.get('readonly', 0),
                               showattributepanel=self.type.get(
                                   'showAttribPanel', 0),
                               maxLength=self.type.get('maxlength', None)
                               or self.type.get('maxLength', None))
     label = self.type.get('label', '')
     if label == '_hide':
         self.code.padLeft = 0
     elif label:
         uicontrols.EveLabelSmall(text=label,
                                  parent=self.new,
                                  name='label',
                                  left=7,
                                  width=self.leftPush - 6,
                                  top=5)
Esempio n. 11
0
 def AddTextedit(self):
     self.new = uiprimitives.Container(name='texteditField',
                                       parent=self.parent,
                                       align=uiconst.TOTOP,
                                       height=self.type.get('height', 68))
     self.code = EditPlainText(setvalue=self.type.get('setvalue', '')
                               or self.type.get('text', ''),
                               parent=self.new,
                               padding=(self.leftPush, 2, 0, 2),
                               readonly=self.type.get('readonly', 0),
                               showattributepanel=self.type.get(
                                   'showAttribPanel', 0),
                               maxLength=self.type.get('maxlength', None)
                               or self.type.get('maxLength', None))
     label = self.type.get('label', '')
     if label == '_hide':
         self.code.padLeft = 0
     elif label:
         uicontrols.EveLabelSmall(text=label,
                                  parent=self.new,
                                  name='label',
                                  left=7,
                                  width=self.leftPush - 6,
                                  top=5)
Esempio n. 12
0
 def ConstuctLayout(self):
     self.leftCont = DragResizeCont(name='leftCont', parent=self.sr.main, align=uiconst.TOLEFT_PROP, settingsID='ControlCatalogWindowLeftCont')
     self.infoCont = ContainerAutoSize(name='infoCont', parent=self.sr.main, align=uiconst.TOTOP, padding=6)
     self.topCont = DragResizeCont(name='topCont', parent=self.sr.main, align=uiconst.TOTOP_PROP, settingsID='ControlCatalogWindowSampleCont', minSize=0.3, maxSize=0.9, defaultSize=0.5, clipChildren=True)
     tabCont = ContainerAutoSize(name='tabCont', parent=self.topCont.mainCont, align=uiconst.TOBOTTOM)
     self.mainButtonGroup = ButtonGroup(name='mainButtonGroup', parent=self.sr.main)
     self.editCont = Container(name='editCont', parent=self.sr.main)
     GradientSprite(bgParent=self.leftCont, rotation=0, rgbData=[(0, (1.0, 1.0, 1.3))], alphaData=[(0.8, 0.0), (1.0, 0.05)])
     self.controlScroll = ScrollContainer(parent=self.leftCont)
     self.PopulateScroll()
     self.leftButtonGroup = ButtonGroup(name='leftButtonGroup', parent=self.leftCont, idx=0)
     self.ConstructLeftButtonGroup()
     self.classNameLabel = Label(parent=self.infoCont, align=uiconst.TOTOP, fontsize=15, bold=True)
     self.classDocLabel = EveLabelSmall(parent=self.infoCont, align=uiconst.TOTOP)
     GradientSprite(align=uiconst.TOTOP, parent=self.infoCont, rotation=-math.pi / 2, height=16, padding=(-4, -10, -4, 0), rgbData=[(0, (1.0, 1.0, 1.3))], alphaData=[(0.0, 0.0), (1.0, 0.03)])
     GradientSprite(align=uiconst.TOTOP, parent=tabCont, state=uiconst.UI_DISABLED, rotation=math.pi / 2, height=16, padding=(-4, 0, -4, -10), rgbData=[(0, (1.0, 1.0, 1.3))], alphaData=[(0.0, 0.0), (1.0, 0.03)])
     self.sampleNameLabel = EveLabelSmall(parent=tabCont, align=uiconst.TOTOP, padBottom=5)
     self.tabs = ToggleButtonGroup(parent=Container(parent=tabCont, align=uiconst.TOTOP, height=16), align=uiconst.CENTER, height=16, callback=self.OnTabSelected)
     sampleParent = Container(name='sampleParent', parent=self.topCont.mainCont, clipChildren=True)
     self.sampleCont = ContainerAutoSize(name='sampleCont', parent=sampleParent, align=uiconst.CENTER)
     self.codeEdit = EditPlainText(parent=self.editCont, align=uiconst.TOALL, fontcolor=(1, 1, 1, 1), ignoreTags=True)
     self.codeEdit.OnKeyDown = self.OnCodeEditKeyDown
     self.ConstructMainButtonGroup()
     uthread.new(self._SpyOnSampleCodeReloadThread)
Esempio n. 13
0
 def OnCodeEditKeyDown(self, key, flag):
     if uicore.uilib.Key(uiconst.VK_CONTROL) and key == uiconst.VK_S:
         self.ReloadSamples()
     else:
         return EditPlainText.OnKeyDown(self.codeEdit, key, flag)
Esempio n. 14
0
class Form(service.Service):
    """
        Code that creates UI elements from the format structure passed to a hybrid window.
        
        A sample format structure: 
        format = [
            {"type": "header", "text": "The amazing heading"},
            {"type": "edit", "setvalue": "Hell yeah!", "key":"theEdit", "label":"Put text here", "required":True, "maxlength":100},
            {"type": "data", "data" : {"thisIs": ["some extra data returned by the form"], "and": "thenSome"}},
            {"type": "errorcheck", "errorcheck" : self.ErrorCheckFunctionThatReturnsErrorStringOrEmptyString},
            {"type": "btline"},
        ]
        
        The supported types are:
        - errorcheck (validation function for form data)
        - data (additional data that will be sent by the form)
        - tab (create a tab in a tabbed form)
        - push (vertical spacing)
        - btline / bbline (horizontal line)
        - header (text heading)
        - labeltext (label text)
        - text (normal single- or multiline non-editable text)
        - edit (a single line text edit)
        - textedit (editable multi-line textbox)
        - checkbox (Checkbox field) 
        - combo (combo box)
        - btnonly (a button)
        
        There are a few parameters that work for all types such as "setfocus" (see below)
    """
    __guid__ = 'svc.form'
    __exportedcalls__ = {'GetForm': [], 'ProcessForm': []}
    __servicename__ = 'form'
    __displayname__ = 'Form Service'
    __dependencies__ = []

    def __init__(self):
        service.Service.__init__(self)

    def GetForm(self, format, parent):
        _form, retfields, reqresult, panels, errorcheck, refresh = self._GetForm(
            format, parent)
        if _form.align == uiconst.TOALL:
            _form.SetSize(0, 0)
            _form.SetPosition(0, 0)
            _form.padding = const.defaultPadding
        elif _form.align in (uiconst.TOTOP, uiconst.TOBOTTOM):
            _form.SetPosition(0, 0)
            _form.width = 0
            _form.padding = const.defaultPadding
        elif _form.align in (uiconst.TOLEFT, uiconst.TORIGHT):
            _form.SetPosition(0, 0)
            _form.height = 0
            _form.padding = const.defaultPadding
        else:
            _form.left = _form.top = const.defaultPadding
        return (_form, retfields, reqresult, panels, errorcheck, refresh)

    def _GetForm(self,
                 format,
                 parent,
                 retfields=[],
                 reqresult=[],
                 errorcheck=None,
                 tabpanels=[],
                 tabgroup=[],
                 refresh=[],
                 wipe=1):
        if not uiutil.IsUnder(parent, uicore.desktop):
            log.LogTraceback(
                'Form parent MUST be hooked on the desktop; it is impossible to know the real dimensions of stuff within otherwise.'
            )
        self.retfields = retfields
        self.reqresult = reqresult
        self.errorcheck = errorcheck
        self.tabpanels = tabpanels
        self.tabgroup = tabgroup
        self.refresh = refresh
        if not isinstance(parent, FormWnd):
            log.LogTraceback(
                'Incompatible formparent, please change it to xtriui.FormWnd')
        self.parent = parent
        self.parent.sr.panels = {}
        self.parent.sr.focus = None
        if wipe:
            self.retfields = []
            self.reqresult = []
            self.tabpanels = []
            self.tabgroup = []
            self.refresh = []
        for each in format:
            self.type = each
            typeName = self.type['type']
            self.leftPush = self.type.get('labelwidth', 0) or 80
            self.code = None
            if typeName == 'errorcheck':
                self.AddErrorcheck()
                continue
            elif typeName == 'data':
                self.AddData()
                continue
            elif typeName == 'tab':
                self.AddTab()
                continue
            elif typeName in ('btline', 'bbline'):
                self.AddLine()
                continue
            elif typeName == 'push':
                self.AddPush()
            elif typeName == 'header':
                self.AddHeader()
            elif typeName == 'labeltext':
                self.AddLabeltext()
            elif typeName == 'text':
                self.AddText()
            elif typeName == 'edit':
                self.AddEdit()
            elif typeName == 'textedit':
                self.AddTextedit()
            elif typeName == 'checkbox':
                self.AddCheckbox()
            elif typeName == 'combo':
                self.AddCombo()
            elif typeName == 'btnonly':
                self.AddBtnonly()
            else:
                log.LogWarn('Unknown fieldtype in form generator')
                continue
            if self.type.has_key('key'):
                if self.code:
                    self.retfields.append([self.code, self.type])
                    self.parent.sr.Set(self.type['key'], self.code)
                else:
                    self.parent.sr.Set(self.type['key'], self.new)
            if self.type.get('required', 0) == 1:
                self.reqresult.append([self.code, self.type])
            if self.type.get('selectall', 0) == 1 and getattr(
                    self.code, 'SelectAll', None):
                self.code.SelectAll()
            if self.type.get('setfocus', 0) == 1:
                self.parent.sr.focus = self.code
            if self.type.has_key('stopconfirm') and hasattr(
                    self.code, 'stopconfirm'):
                self.code.stopconfirm = self.type['stopconfirm']
            if self.type.get('frame', 0) == 1:
                idx = 0
                for child in self.new.children:
                    if child.name.startswith('Line'):
                        idx += 1

                uiprimitives.Container(name='leftpush',
                                       parent=self.new,
                                       align=uiconst.TOLEFT,
                                       width=6,
                                       idx=idx)
                uiprimitives.Container(name='rightpush',
                                       parent=self.new,
                                       align=uiconst.TORIGHT,
                                       width=6,
                                       idx=idx)
                uiprimitives.Line(parent=self.new,
                                  align=uiconst.TOLEFT,
                                  idx=idx)
                uiprimitives.Line(parent=self.new,
                                  align=uiconst.TORIGHT,
                                  idx=idx)

        if wipe and len(self.tabgroup):
            tabs = uicontrols.TabGroup(name='tabparent',
                                       parent=self.parent,
                                       idx=0)
            tabs.Startup(self.tabgroup, 'hybrid')
            maxheight = 0
            for panel in self.tabpanels:
                maxheight = max(maxheight, panel.height)

            self.parent.height = maxheight + tabs.height
        else:
            if len(self.tabpanels):
                for each in self.tabpanels:
                    each.state = uiconst.UI_HIDDEN

                self.tabpanels[0].state = uiconst.UI_PICKCHILDREN
            uix.RefreshHeight(self.parent)
        uicore.registry.SetFocus(self)
        return (self.parent, self.retfields, self.reqresult, self.tabpanels,
                self.errorcheck, self.refresh)

    def AddErrorcheck(self):
        """
             errorcheck (validation function for form data)
            
             PARAMS:
                - errorcheck [func]: an error check function that should return en empty string on OK,
                  or an error message string otherwise
        """
        self.errorcheck = self.type['errorcheck']

    def AddData(self):
        """
             data (additional data that will be sent by the form)
             
             PARAMS:
                - data [any] : the additional data sent by the form
        """
        self.retfields.append(self.type['data'])

    def AddTab(self):
        """
             tab (create a tab in a tabbed form)
             
             PARAMS:
                - tabtext [str]        : tab label
                - format [list]        : a format list such as those passed to a form
                - key [str]            : a unique name for the tab panel, passed on to it's parent
                - panelvisible [bool]  : is the tab panel visible (default False)
                - tabvisible [bool]    : is the tab visible (default False)
        """
        _form, _retfield, _required, _tabpanels, _errorcheck, _refresh = self._GetForm(
            self.type['format'],
            FormWnd(name='form', align=uiconst.TOTOP,
                    parent=self.parent), self.retfields, self.reqresult,
            self.errorcheck, self.tabpanels, self.tabgroup, self.refresh, 0)
        if self.type.has_key('key'):
            self.parent.sr.panels[self.type['key']] = _form
        if self.type.get('panelvisible', 0):
            _form.state = uiconst.UI_PICKCHILDREN
        else:
            _form.state = uiconst.UI_HIDDEN
        if self.type.has_key('tabvisible'):
            if self.type['tabvisible'] == 1:
                self.tabgroup.append([self.type['tabtext'], _form, self, None])
        else:
            self.tabgroup.append([self.type['tabtext'], _form, self, None])

    def AddPush(self):
        """
             push (vertical spacing)
             
             PARAMS:
                - height [int]: The height of the spacing
        """
        self.new = uiprimitives.Container(name='push',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 6))

    def AddLine(self):
        """
             btline / bbline (horizontal line)
            
             PARAMS:
                - None
        """
        uiprimitives.Line(parent=self.parent, align=uiconst.TOTOP)

    def AddHeader(self):
        """
             header (text heading)
            
             PARAMS:
                - height [int]    : text container height (not font height)
                - text [str]      : heading text
                - hideLine [bool] : if True, heading line is hidden
        """
        self.new = uiprimitives.Container(name='headerField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP)
        header = uicontrols.EveLabelSmall(text=self.type.get('text', ''),
                                          parent=self.new,
                                          name='header',
                                          padding=(7, 3, 7, 3),
                                          align=uiconst.TOTOP,
                                          state=uiconst.UI_NORMAL,
                                          bold=True)
        self.new.height = max(self.type.get('height', 17),
                              header.textheight + header.padTop * 2)
        self.refresh.append((self.new, header))
        if not self.type.get('hideLine', False):
            uiprimitives.Line(parent=self.new,
                              align=uiconst.TOTOP,
                              padLeft=-6,
                              padRight=-6,
                              idx=0)
            uiprimitives.Line(parent=self.new,
                              align=uiconst.TOBOTTOM,
                              padLeft=-6,
                              padRight=-6,
                              idx=0)

    def AddLabeltext(self):
        """
             labeltext (label text)
             
             PARAMS:
                - height [int]    : text container height (not font height)
                - label [str]     : label text 
                - text [str]      : same as label
        """
        self.new = uiprimitives.Container(name='labeltextField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20))
        text = uicontrols.EveLabelMedium(text=self.type.get('text', ''),
                                         parent=self.new,
                                         align=uiconst.TOTOP,
                                         name='text',
                                         padding=(self.leftPush, 3, 0, 0),
                                         state=uiconst.UI_NORMAL)
        label = self.type.get('label', '')
        if label and label != '_hide':
            label = uicontrols.EveLabelSmall(text=label,
                                             parent=self.new,
                                             name='label',
                                             left=7,
                                             width=self.leftPush - 6,
                                             top=5)
            self.refresh.append((self.new, text, label))
        else:
            self.refresh.append((self.new, text))

    def AddText(self):
        """
             text (normal single- or multiline text)
             
             PARAMS:
                - height [int]    : text container height (not font height)
                - text [str]      : the actual text
                - fontsize [int]  : font size
                - tabstops [list] : list of tab stops for tab aligned text
                - left [int]      : left of the text
        """
        left = self.type.get('left', 0)
        self.new = uiprimitives.Container(name='textField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20),
                                          padding=(left, 0, 0, 0))
        fontsize = self.type.get('fontsize', 12)
        text = uicontrols.Label(
            text=self.type.get('text', ''),
            parent=self.new,
            align=uiconst.TOTOP,
            name='text',
            padding=(0, 3, 0, 3),
            fontsize=fontsize,
            maxLines=1 if bool(self.type.get('tabstops', [])) else None,
            state=uiconst.UI_NORMAL,
            tabs=self.type.get('tabstops', []))
        self.new.height = max(self.new.height, int(text.textheight + 6))
        self.refresh.append((self.new, text))

    def AddEdit(self):
        """    
             edit (a single line text edit)
             
             PARAMS:
                - width [int]                  : edit width
                - setvalue [str]               : initial default text
                - label [str]                  : edit box label
                - text [str]                   : same as label (depreciated)
                - intonly [bool]               : if true, only integers can be input
                - floatonly [bool]             : if true, only float numbers can be input
                - maxlength [int]              : maximum number of characters
                - passwordChar [bool]          : if true, characters are replaced by password characters
                - readOnly [bool]              : if true, input is disabled
                - autoselect [bool]            : if true, the whole input gets selected when the edit gets focus
                - OnReturn [func]              : a callback for when RETURN is pressed
                - unusedkeydowncallback [func] : a callback for when an unused global key is pressed (depreciated)
                - onanychar [func]             : a callback for when any character is input
        """
        self.new = uiprimitives.Container(name='editField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP)
        config = 'edit_%s' % self.type['key']
        self.code = uicontrols.SinglelineEdit(
            name=config,
            parent=self.new,
            setvalue=self.type.get('setvalue', ''),
            padding=(self.leftPush, 2, 0, 2),
            ints=self.type.get('intonly', None),
            floats=self.type.get('floatonly', None),
            align=uiconst.TOTOP,
            maxLength=self.type.get('maxlength', None)
            or self.type.get('maxLength', None),
            passwordCharacter=self.type.get('passwordChar', None),
            readonly=self.type.get('readonly', 0),
            autoselect=self.type.get('autoselect', 0),
            isTypeField=self.type.get('isTypeField', False),
            isCharacterField=self.type.get('isCharacterField', False))
        self.new.height = self.code.height + self.code.padTop * 4
        width = self.type.get('width', None)
        if width:
            self.code.SetAlign(uiconst.TOLEFT)
            self.code.width = width
        if self.type.has_key('OnReturn'):
            self.code.data = {'key': self.type['key']}
            self.code.OnReturn = self.type['OnReturn']
        if self.type.has_key('unusedkeydowncallback'):
            self.code.OnUnusedKeyDown = self.type['unusedkeydowncallback']
        if self.type.has_key('onanychar'):
            self.code.OnAnyChar = self.type['onanychar']
        label = self.type.get('label', '')
        text = self.type.get('text', None)
        caption = text or label
        if label == '_hide':
            self.code.padLeft = 0
        elif caption:
            l = uicontrols.EveLabelSmall(text=caption,
                                         align=uiconst.CENTERLEFT,
                                         parent=self.new,
                                         name='label',
                                         left=7,
                                         width=self.leftPush - 6)

    def AddTextedit(self):
        """
             textedit (editable multi-line textbox)
             
             PARAMS:
                - height [int]            : text container height (not font height)
                - setvalue [str]          : initial text in edit
                - text [str]              : same as setvalue
                - label [str]             : text edit label. If set to "_hide", it gets hidden and the edit is moved accordingly
                - maxlength [int]         : maximum number of input characters
                - showAttribPanel [bool]  : the text attribute panel is shown (default False)
                - readonly [bool]         : text is read only (default False)
                - hidebackground [bool]   : hide textbox background (default False)
        """
        self.new = uiprimitives.Container(name='texteditField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 68))
        self.code = EditPlainText(setvalue=self.type.get('setvalue', '')
                                  or self.type.get('text', ''),
                                  parent=self.new,
                                  padding=(self.leftPush, 2, 0, 2),
                                  readonly=self.type.get('readonly', 0),
                                  showattributepanel=self.type.get(
                                      'showAttribPanel', 0),
                                  maxLength=self.type.get('maxlength', None)
                                  or self.type.get('maxLength', None))
        label = self.type.get('label', '')
        if label == '_hide':
            self.code.padLeft = 0
        elif label:
            uicontrols.EveLabelSmall(text=label,
                                     parent=self.new,
                                     name='label',
                                     left=7,
                                     width=self.leftPush - 6,
                                     top=5)

    def AddCheckbox(self):
        """
             checkbox (Checkbox field) 
             
             PARAMS:
                - text [str]       : label text
                - setvalue [bool]  : sets the checkbox to checked/unchecked
                - group [str]      : creates a group of checkboxes, turning them into radiobuttons
                - onchange [func]  : an OnChange callback
                - showpanel [bool] : ???
                - hidden [bool]    : if true, the checkbox is hidden
                - name             : name of the checkbox
        """
        self.new = uiprimitives.Container(name='checkboxCont',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          pos=(0, 0, 0, 18))
        self.code = uicontrols.Checkbox(text=self.type.get('text', ''),
                                        parent=self.new,
                                        configName=self.type.get(
                                            'name', 'none'),
                                        retval=self.type['key'],
                                        checked=self.type.get('setvalue', 0),
                                        groupname=self.type.get('group', None),
                                        callback=self.parent.OnCheckboxChange)
        self.code.data = {}
        onchange = self.type.get('OnChange', None) or self.type.get(
            'onchange', None)
        if onchange:
            self.code.data = {'key': self.type['key'], 'callback': onchange}
        if self.type.has_key('showpanel'):
            self.code.data['showpanel'] = self.type['showpanel']
        if self.code.sr.label:
            self.refresh.append((self.code, self.code.sr.label))
        if self.type.get('hidden', 0):
            self.code.state = uiconst.UI_HIDDEN

    def AddCombo(self):
        """
            combo (combo box)
            
            PARAMS:
               - height [int]       : container height
               - width [int]        : combo box width
               - label [str]        : combo label text (if set to "_hide", it's hidden)
               - options [list]     : a list of combo options as accepted by uicontrols.Combo()
               - key [str]          : config name of the combo (default "combo")
               - select [str]       : default selected option
               - callback [func]    : callback function when a new option is selected
        """
        self.new = uiprimitives.Container(name='comboField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20))
        options = self.type.get(
            'options', [(localization.GetByLabel('UI/Common/None'), None)])
        self.code = uicontrols.Combo(label='',
                                     parent=self.new,
                                     options=options,
                                     name=self.type.get('key', 'combo'),
                                     select=self.type.get('setvalue', ''),
                                     padding=(self.leftPush, 2, 0, 2),
                                     align=uiconst.TOTOP,
                                     callback=self.type.get('callback', None),
                                     labelleft=self.leftPush)
        self.new.height = self.code.height + self.code.padTop * 4
        width = self.type.get('width', None)
        if width:
            self.code.SetAlign(uiconst.TOLEFT)
            self.code.width = width
        label = self.type.get('label', '')
        if label == '_hide':
            self.code.padLeft = 0
        else:
            uicontrols.EveLabelSmall(text=label,
                                     parent=self.new,
                                     name='label',
                                     left=7,
                                     width=self.leftPush - 6,
                                     align=uiconst.CENTERLEFT)

    def AddBtnonly(self):
        """
             btnonly (button field)
             
             PARAMS:
                - height [int]      : container height (default 20)
                - uniSize [bool]    : if true, all buttons have same size (default True)
                - buttons [list]    : a list of dictionaries, each describing a button (params documented below)
            
                BUTTON PARAMS:
                    - align [str]            : can be either "left" or "right" (default "right")
                    - caption [str]          : button caption
                    - function [func]        : button OnClick callback
                    - btn_modalresult [bool] : does this button generate a modal window result (default False)
                    - btn_default [bool]     : if true, this button is the default value (when RETURN is pressed) (default False)
                    - btn_cancel [bool]      : if true, this button cancels the current form (default False)
        """
        self.new = uiprimitives.Container(name='btnonly',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20))
        btns = []
        align = uiconst.TORIGHT
        for wantedbtn in self.type['buttons']:
            if wantedbtn.has_key('align'):
                al = {'left': uiconst.CENTERLEFT, 'right': uiconst.CENTERRIGHT}
                align = al.get(wantedbtn['align'], uiconst.CENTERRIGHT)
            btns.append([
                wantedbtn['caption'], wantedbtn['function'],
                wantedbtn.get('args', 'self'), None,
                wantedbtn.get('btn_modalresult', 0),
                wantedbtn.get('btn_default', 0),
                wantedbtn.get('btn_cancel', 0)
            ])

        btns = uicontrols.ButtonGroup(btns=btns,
                                      subalign=align,
                                      line=0,
                                      parent=self.new,
                                      align=uiconst.TOTOP,
                                      unisize=self.type.get('uniSize', 1))

    def ProcessForm(self, retfields, required, errorcheck=None):
        result = {}
        for each in retfields:
            if type(each) == dict:
                result.update(each)
                continue
            value = each[0].GetValue()
            if each[1]['type'] == 'checkbox' and each[1].has_key(
                    'group') and value == 1:
                result[each[1]['group']] = each[1]['key']
            else:
                result[each[1]['key']] = value

        if errorcheck:
            hint = errorcheck(result)
            if hint == 'silenterror':
                return
            if hint:
                eve.Message('CustomInfo', {'info': hint})
                return
        if len(required):
            for each in required:
                retval = each[0].GetValue()
                if retval is None or retval == '' or type(
                        retval) in types.StringTypes and retval.strip() == '':
                    fieldname = ''
                    if each[1].has_key('label'):
                        fieldname = each[1]['label']
                        if fieldname == '_hide':
                            fieldname = each[1]['key']
                    else:
                        fieldname = each[1]['key']
                    eve.Message('MissingRequiredField',
                                {'fieldname': fieldname})
                    return
                if each[1]['type'] == 'checkbox' and each[1].has_key('group'):
                    if each[1]['group'] not in result:
                        eve.Message('MissingRequiredField',
                                    {'fieldname': each[1]['group']})
                        return

        return result
Esempio n. 15
0
class AutoBotWindow(Window):
    """ An Insider window which makes it easy to debug UI containers """
    default_windowID = 'AutoBotWindow'
    default_width = 360
    default_height = 300
    default_topParentHeight = 0
    default_minSize = (default_width, default_height)
    default_caption = 'AutoBot Control Box'

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.CreateLocationSelector()
        self.CreateSecurityFilter()
        self.CreateShipSelector()
        self.CreatePasses()
        self.CreateButtons()
        self.CreateLogDisplay()

    def CreateButtons(self):
        buttonCont = FlowContainer(name='SubCategoryButtons',
                                   parent=self.sr.main,
                                   centerContent=True,
                                   align=uiconst.TOBOTTOM,
                                   contentSpacing=(2, 1),
                                   state=uiconst.UI_PICKCHILDREN,
                                   padding=(0, 4, 0, 4))
        Button(parent=buttonCont,
               label='Roll out!!',
               func=self.StartBot,
               align=uiconst.NOALIGN,
               padding=2)
        Button(parent=buttonCont,
               label='Stop',
               func=self.StopBot,
               align=uiconst.NOALIGN,
               padding=2)
        Button(parent=buttonCont,
               label='Clear Log',
               func=self.ClearLogs,
               align=uiconst.NOALIGN,
               padding=2)

    def CreateLocationSelector(self):
        EveLabelSmall(
            parent=self.sr.main,
            text=
            '<color=orange>This is a tool for automating visits to solar systems and locations within them. There are several actions available while visiting each location.',
            align=uiconst.TOTOP,
            padding=4)
        EveLabelSmall(parent=self.sr.main,
                      text='Systems, Constellations or Regions',
                      align=uiconst.TOTOP,
                      padding=4)
        self.locationsEdit = EditPlainText(parent=self.sr.main,
                                           align=uiconst.TOTOP,
                                           height=50,
                                           padding=4)

    def CreateSecurityFilter(self):
        secCont = Container(parent=self.sr.main,
                            height=20,
                            padding=2,
                            align=uiconst.TOTOP)
        EveLabelSmall(parent=secCont,
                      text='Security Band:',
                      align=uiconst.TOLEFT,
                      padding=4)
        EveLabelSmall(parent=secCont,
                      text='Min Security',
                      align=uiconst.TOLEFT,
                      padding=4)
        self.minSecEdit = SinglelineEdit(parent=secCont,
                                         name='minSec',
                                         width=30,
                                         floats=(-1.0, 1.0, 1),
                                         align=uiconst.TOLEFT,
                                         padTop=-3,
                                         setvalue='-1.0')
        EveLabelSmall(parent=secCont,
                      text='Max Security',
                      align=uiconst.TOLEFT,
                      padding=4)
        self.maxSecEdit = SinglelineEdit(parent=secCont,
                                         name='maxSec',
                                         width=30,
                                         floats=(-1.0, 1.0, 1),
                                         align=uiconst.TOLEFT,
                                         padTop=-3,
                                         setvalue='1.0')

    def CreateShipSelector(self):
        cont = Container(parent=self.sr.main,
                         name='ship_options',
                         align=uiconst.TOTOP,
                         height=20)
        self.spawnShipCheckbox = Checkbox(parent=cont,
                                          align=uiconst.TOLEFT,
                                          text='Spawn new ship',
                                          checked=False,
                                          padLeft=8,
                                          callback=self.OnChangeSpawnShip,
                                          width=150)
        Container(parent=cont, width=16, align=uiconst.TOLEFT)
        EveLabelSmall(parent=cont, text='DNA', align=uiconst.TOLEFT, padding=4)
        self.dnaEdit = SinglelineEdit(parent=cont,
                                      setvalue='DNA:593:2528:20197',
                                      align=uiconst.TOLEFT,
                                      width=200)

    def CreatePasses(self):
        EveLabelSmall(parent=self.sr.main,
                      text='Actions for each system visited',
                      align=uiconst.TOTOP,
                      padding=4)
        self.CreateSystemPass(1)
        self.CreateSystemPass(2)

    def CreateSystemPass(self, passNumber):
        def GetLocationsMenu(menuParent):
            passConfig = GetPassConfig()[passNumber]
            menuParent.AddHeader(text='Locations to visit')
            for groupId in (const.groupAsteroidBelt, const.groupStargate,
                            const.groupStation):
                menuParent.AddCheckBox(
                    text=cfg.invgroups.Get(groupId).groupName,
                    checked=groupId in passConfig['locations'],
                    callback=(ToggleLocationGroupForPass, passNumber, groupId))

            menuParent.AddDivider()
            menuParent.AddHeader(text='Actions')
            menuParent.AddCheckBox(text='Nuke location',
                                   checked=passConfig['nuke'],
                                   callback=(ToggleNuke, passNumber))

        passConfig = {
            'locations': {const.groupAsteroidBelt},
            'nuke': False,
            'enabled': passNumber == 1,
            'minTime': 1
        }
        GetPassConfig()[passNumber] = passConfig
        menuCont = Container(name='pass%d' % passNumber,
                             parent=self.sr.main,
                             align=uiconst.TOTOP,
                             height=20,
                             padLeft=4)
        cont = Container(parent=menuCont, width=100, align=uiconst.TOLEFT)
        Checkbox(parent=cont,
                 text='Enable Pass %s' % passNumber,
                 align=uiconst.CENTERLEFT,
                 checked=passConfig['enabled'],
                 callback=lambda checkbox: SetPass(checkbox, passNumber),
                 width=200)
        cont = Container(parent=menuCont, width=100, align=uiconst.TOLEFT)
        EveLabelSmall(parent=cont,
                      text='Min time (sec)',
                      align=uiconst.CENTERRIGHT,
                      left=4)
        SinglelineEdit(
            parent=menuCont,
            ints=(1, 999),
            OnChange=lambda textValue: SetPassMinTime(textValue, passNumber),
            setvalue=passConfig['minTime'],
            align=uiconst.TOLEFT,
            width=50)
        UtilMenu(menuAlign=uiconst.TOPRIGHT,
                 parent=menuCont,
                 align=uiconst.TOLEFT,
                 GetUtilMenu=GetLocationsMenu,
                 label='Options',
                 texturePath='res:/UI/Texture/Icons/38_16_229.png',
                 closeTexturePath='res:/UI/Texture/Icons/38_16_230.png')

    def CreateLogDisplay(self):
        self.logEdit = EditPlainText(parent=self.sr.main,
                                     align=uiconst.TOALL,
                                     readonly=True,
                                     padTop=4)

    def OnChangeSpawnShip(self, checkbox):
        if checkbox.GetValue():
            self.dnaEdit.SetReadOnly(False)
            self.dnaEdit.opacity = 1.0
        else:
            self.dnaEdit.SetReadOnly(True)
            self.dnaEdit.opacity = 0.5

    def StartBot(self, *args):
        config = GetConfig()
        locations = SplitLocationsText(self.locationsEdit.GetValue())
        config['locations'] = locations
        config['minSecurity'] = self.minSecEdit.GetValue()
        config['maxSecurity'] = self.maxSecEdit.GetValue()
        if self.spawnShipCheckbox.GetValue():
            config['shipDna'] = self.dnaEdit.GetValue()
        else:
            config['shipDna'] = None
        sm.GetService('autobot').StartBot()
        self.logUpdated = AutoTimer(2000, self.UpdateLogText)

    def PauseBot(self, *args):
        sm.GetService('autobot').PauseBot()

    def StopBot(self, *args):
        sm.GetService('autobot').StopBot()
        self.logUpdated = None

    def ClearLogs(self, *args):
        sm.GetService('autobot').ClearLogs()

    def UpdateLogText(self):
        logLines = sm.GetService('autobot').logLines
        self.logEdit.SetValue('\n'.join([str(x) for x in reversed(logLines)]))
Esempio n. 16
0
 def CreateLogDisplay(self):
     self.logEdit = EditPlainText(parent=self.sr.main,
                                  align=uiconst.TOALL,
                                  readonly=True,
                                  padTop=4)
Esempio n. 17
0
class PodGuideContent(Container):
    MIN_RIGHT_SIDE_WIDTH = 100

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        padding = 30
        self.termHeaderLabel = EveCaptionLarge(name='termHeaderLabel',
                                               parent=self,
                                               align=uiconst.TOTOP,
                                               text='',
                                               padLeft=padding + 4,
                                               padTop=20)
        self.contentRightCont = Container(name='contentRightCont',
                                          parent=self,
                                          align=uiconst.TORIGHT,
                                          width=128,
                                          padRight=36)
        self.height = 300
        self.longTextEdit = EditPlainText(name='longTextEdit',
                                          parent=self,
                                          align=uiconst.TOTOP,
                                          readonly=True,
                                          setvalue='abc',
                                          padding=(padding, 0, padding, 0))
        self.longTextEdit.sr.maincontainer.padding = 0
        self.longTextEdit.DisableScrolling()
        self.longTextEdit.EnableAutoSize()
        self.longTextEdit.OnContentSizeChanged = self.OnContentChanged
        self.longTextEdit.HideBackground()
        self.longTextEdit.RemoveActiveFrame()
        self.termSpriteCont = Container(name='termSpriteCont',
                                        parent=self.contentRightCont,
                                        pos=(0, 0, 128, 128),
                                        align=uiconst.TOTOP)
        self.termSprite = Sprite(
            name='termSprite',
            parent=self.termSpriteCont,
            pos=(0, 0, 128, 128),
            texturePath=
            'res:/UI/Texture/Classes/ShipTree/groupIcons/frigate.png',
            align=uiconst.CENTER)
        self.loreTextLabel = EveLabelMedium(name='termNameLabel',
                                            text='',
                                            parent=self.contentRightCont,
                                            align=uiconst.TOTOP)

    def LoadContent(self, termInfo):
        self.termHeaderLabel.text = GetByMessageID(termInfo.termTitleID)
        self.loreTextLabel.text = '<i>%s</i>' % GetByMessageID(
            termInfo.loreTextID)
        self.LoadAndWaitForIconSizeChange(termInfo.texturePath)
        self.longTextEdit.SetValue('<font size=14>%s</font>' %
                                   GetByMessageID(termInfo.longTextID))

    def OnContentChanged(self, width, height, *args):
        self.height = self.termHeaderLabel.padTop + self.termHeaderLabel.textheight + max(
            height, self.termSprite.height + self.loreTextLabel.textheight)

    def LoadAndWaitForIconSizeChange(self, texturePath):
        self.termSprite.LoadTexture(texturePath)
        if not texturePath:
            return
        import blue
        counter = 0
        while self.termSprite.renderObject.texturePrimary.atlasTexture.width == 0 and counter < 20:
            counter += 1
            blue.synchro.Yield()

        atlasTexture = self.termSprite.renderObject.texturePrimary.atlasTexture
        self.termSprite.width = atlasTexture.width
        self.termSprite.height = atlasTexture.height
        self.termSpriteCont.height = atlasTexture.height
        self.contentRightCont.width = max(self.MIN_RIGHT_SIDE_WIDTH,
                                          atlasTexture.width)
Esempio n. 18
0
 def ApplyAttributes(self, attributes):
     Window.ApplyAttributes(self, attributes)
     self.updateChatFiltersFunc = attributes.get('updateChatFiltersFunc')
     bannedWordsList = attributes.get('bannedWords', [])
     highlightWordsList = attributes.get('highlightWords', [])
     blinkOnHighlightWords = attributes.get('blinkOnHighlightWords', False)
     self.SetTopparentHeight(0)
     self.SetCaption(
         localization.GetByLabel('UI/Chat/ChannelWindow/ChatWordFilters'))
     self.SetMinSize([self.default_width, self.default_height])
     btnGroup = ButtonGroup(btns=[], parent=self.sr.main, idx=0, line=True)
     btnGroup.AddButton(
         label=localization.GetByLabel('UI/Common/Buttons/Save'),
         func=self.Save,
         args=(),
         isDefault=True)
     btnGroup.AddButton(
         label=localization.GetByLabel('UI/Common/Buttons/Cancel'),
         func=self.Cancel,
         isDefault=False)
     padding = 4
     bannedWordsCont = DragResizeCont(name='bannedWordsCont',
                                      parent=self.sr.main,
                                      align=uiconst.TOTOP_PROP,
                                      minSize=0.3,
                                      maxSize=0.7,
                                      defaultSize=0.45,
                                      padding=padding)
     Line(parent=bannedWordsCont.dragArea,
          align=uiconst.TOTOP,
          padLeft=-3,
          padRight=-3,
          color=(1, 1, 1, 0.15))
     Line(parent=bannedWordsCont.dragArea,
          align=uiconst.TOBOTTOM,
          padLeft=-3,
          padRight=-3,
          color=(1, 1, 1, 0.15))
     self.bannedWordsLabel = EveLabelMedium(
         parent=bannedWordsCont,
         name='bannedWordsLabel',
         align=uiconst.TOTOP,
         state=uiconst.UI_DISABLED,
         text=localization.GetByLabel(
             'UI/Chat/ChannelWindow/BannedWordText'),
         padTop=2,
         padLeft=2)
     bannedWords = SPLITTER.join(bannedWordsList)
     self.bannedWordsField = EditPlainText(
         name='bannedWordsField',
         parent=bannedWordsCont,
         align=uiconst.TOALL,
         ignoreTags=True,
         setvalue=bannedWords,
         padBottom=8,
         hintText=localization.GetByLabel(
             'UI/Chat/ChannelWindow/WordSeparatorText'))
     lowerCont = Container(parent=self.sr.main,
                           name='lowerCont',
                           align=uiconst.TOALL,
                           padLeft=padding,
                           padRight=padding,
                           padTop=8,
                           padBottom=6)
     self.highlightWordsLabel = EveLabelMedium(
         parent=lowerCont,
         name='highlightWordsLabel',
         align=uiconst.TOTOP,
         state=uiconst.UI_DISABLED,
         text=localization.GetByLabel(
             'UI/Chat/ChannelWindow/HighlightWordText'),
         padLeft=2)
     self.blinkOnHighlightWordsCb = Checkbox(
         parent=lowerCont,
         name='blinkCb',
         checked=blinkOnHighlightWords,
         align=uiconst.TOBOTTOM,
         text=localization.GetByLabel('UI/Chat/ChannelWindow/AlwaysBlink'))
     highlightWords = SPLITTER.join(highlightWordsList)
     self.highlightWordsField = EditPlainText(
         name='highlightWordsField',
         parent=lowerCont,
         align=uiconst.TOALL,
         ignoreTags=True,
         setvalue=highlightWords,
         hintText=localization.GetByLabel(
             'UI/Chat/ChannelWindow/WordSeparatorText'))
Esempio n. 19
0
class Form(service.Service):
    __guid__ = 'svc.form'
    __exportedcalls__ = {'GetForm': [], 'ProcessForm': []}
    __servicename__ = 'form'
    __displayname__ = 'Form Service'
    __dependencies__ = []

    def __init__(self):
        service.Service.__init__(self)

    def GetForm(self, format, parent):
        _form, retfields, reqresult, panels, errorcheck, refresh = self._GetForm(
            format, parent)
        if _form.align == uiconst.TOALL:
            _form.SetSize(0, 0)
            _form.SetPosition(0, 0)
            _form.padding = const.defaultPadding
        elif _form.align in (uiconst.TOTOP, uiconst.TOBOTTOM):
            _form.SetPosition(0, 0)
            _form.width = 0
            _form.padding = const.defaultPadding
        elif _form.align in (uiconst.TOLEFT, uiconst.TORIGHT):
            _form.SetPosition(0, 0)
            _form.height = 0
            _form.padding = const.defaultPadding
        else:
            _form.left = _form.top = const.defaultPadding
        return (_form, retfields, reqresult, panels, errorcheck, refresh)

    def _GetForm(self,
                 format,
                 parent,
                 retfields=[],
                 reqresult=[],
                 errorcheck=None,
                 tabpanels=[],
                 tabgroup=[],
                 refresh=[],
                 wipe=1):
        if not uiutil.IsUnder(parent, uicore.desktop):
            log.LogTraceback(
                'Form parent MUST be hooked on the desktop; it is impossible to know the real dimensions of stuff within otherwise.'
            )
        self.retfields = retfields
        self.reqresult = reqresult
        self.errorcheck = errorcheck
        self.tabpanels = tabpanels
        self.tabgroup = tabgroup
        self.refresh = refresh
        if not isinstance(parent, FormWnd):
            log.LogTraceback(
                'Incompatible formparent, please change it to xtriui.FormWnd')
        self.parent = parent
        self.parent.sr.panels = {}
        self.parent.sr.focus = None
        if wipe:
            self.retfields = []
            self.reqresult = []
            self.tabpanels = []
            self.tabgroup = []
            self.refresh = []
        for each in format:
            self.type = each
            typeName = self.type['type']
            self.leftPush = self.type.get('labelwidth', 0) or 80
            self.code = None
            if typeName == 'errorcheck':
                self.AddErrorcheck()
                continue
            elif typeName == 'data':
                self.AddData()
                continue
            elif typeName == 'tab':
                self.AddTab()
                continue
            elif typeName in ('btline', 'bbline'):
                self.AddLine()
                continue
            elif typeName == 'push':
                self.AddPush()
            elif typeName == 'header':
                self.AddHeader()
            elif typeName == 'labeltext':
                self.AddLabeltext()
            elif typeName == 'text':
                self.AddText()
            elif typeName == 'edit':
                self.AddEdit()
            elif typeName == 'textedit':
                self.AddTextedit()
            elif typeName == 'checkbox':
                self.AddCheckbox()
            elif typeName == 'combo':
                self.AddCombo()
            elif typeName == 'btnonly':
                self.AddBtnonly()
            else:
                log.LogWarn('Unknown fieldtype in form generator')
                continue
            if self.type.has_key('key'):
                if self.code:
                    self.retfields.append([self.code, self.type])
                    self.parent.sr.Set(self.type['key'], self.code)
                else:
                    self.parent.sr.Set(self.type['key'], self.new)
            if self.type.get('required', 0) == 1:
                self.reqresult.append([self.code, self.type])
            if self.type.get('selectall', 0) == 1 and getattr(
                    self.code, 'SelectAll', None):
                self.code.SelectAll()
            if self.type.get('setfocus', 0) == 1:
                self.parent.sr.focus = self.code
            if self.type.has_key('stopconfirm') and hasattr(
                    self.code, 'stopconfirm'):
                self.code.stopconfirm = self.type['stopconfirm']
            if self.type.get('frame', 0) == 1:
                idx = 0
                for child in self.new.children:
                    if child.name.startswith('Line'):
                        idx += 1

                uiprimitives.Container(name='leftpush',
                                       parent=self.new,
                                       align=uiconst.TOLEFT,
                                       width=6,
                                       idx=idx)
                uiprimitives.Container(name='rightpush',
                                       parent=self.new,
                                       align=uiconst.TORIGHT,
                                       width=6,
                                       idx=idx)
                uiprimitives.Line(parent=self.new,
                                  align=uiconst.TOLEFT,
                                  idx=idx)
                uiprimitives.Line(parent=self.new,
                                  align=uiconst.TORIGHT,
                                  idx=idx)

        if wipe and len(self.tabgroup):
            tabs = uicontrols.TabGroup(name='tabparent',
                                       parent=self.parent,
                                       idx=0)
            tabs.Startup(self.tabgroup, 'hybrid')
            maxheight = 0
            for panel in self.tabpanels:
                maxheight = max(maxheight, panel.height)

            self.parent.height = maxheight + tabs.height
        else:
            if len(self.tabpanels):
                for each in self.tabpanels:
                    each.state = uiconst.UI_HIDDEN

                self.tabpanels[0].state = uiconst.UI_PICKCHILDREN
            uix.RefreshHeight(self.parent)
        uicore.registry.SetFocus(self)
        return (self.parent, self.retfields, self.reqresult, self.tabpanels,
                self.errorcheck, self.refresh)

    def AddErrorcheck(self):
        self.errorcheck = self.type['errorcheck']

    def AddData(self):
        self.retfields.append(self.type['data'])

    def AddTab(self):
        _form, _retfield, _required, _tabpanels, _errorcheck, _refresh = self._GetForm(
            self.type['format'],
            FormWnd(name='form', align=uiconst.TOTOP,
                    parent=self.parent), self.retfields, self.reqresult,
            self.errorcheck, self.tabpanels, self.tabgroup, self.refresh, 0)
        if self.type.has_key('key'):
            self.parent.sr.panels[self.type['key']] = _form
        if self.type.get('panelvisible', 0):
            _form.state = uiconst.UI_PICKCHILDREN
        else:
            _form.state = uiconst.UI_HIDDEN
        if self.type.has_key('tabvisible'):
            if self.type['tabvisible'] == 1:
                self.tabgroup.append([self.type['tabtext'], _form, self, None])
        else:
            self.tabgroup.append([self.type['tabtext'], _form, self, None])

    def AddPush(self):
        self.new = uiprimitives.Container(name='push',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 6))

    def AddLine(self):
        uiprimitives.Line(parent=self.parent, align=uiconst.TOTOP)

    def AddHeader(self):
        self.new = uiprimitives.Container(name='headerField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP)
        header = uicontrols.EveLabelSmall(text=self.type.get('text', ''),
                                          parent=self.new,
                                          name='header',
                                          padding=(7, 3, 7, 3),
                                          align=uiconst.TOTOP,
                                          state=uiconst.UI_NORMAL,
                                          bold=True)
        self.new.height = max(self.type.get('height', 17),
                              header.textheight + header.padTop * 2)
        self.refresh.append((self.new, header))
        if not self.type.get('hideLine', False):
            uiprimitives.Line(parent=self.new,
                              align=uiconst.TOTOP,
                              padLeft=-6,
                              padRight=-6,
                              idx=0)
            uiprimitives.Line(parent=self.new,
                              align=uiconst.TOBOTTOM,
                              padLeft=-6,
                              padRight=-6,
                              idx=0)

    def AddLabeltext(self):
        self.new = uiprimitives.Container(name='labeltextField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20))
        text = uicontrols.EveLabelMedium(text=self.type.get('text', ''),
                                         parent=self.new,
                                         align=uiconst.TOTOP,
                                         name='text',
                                         padding=(self.leftPush, 3, 0, 0),
                                         state=uiconst.UI_NORMAL)
        label = self.type.get('label', '')
        if label and label != '_hide':
            label = uicontrols.EveLabelSmall(text=label,
                                             parent=self.new,
                                             name='label',
                                             left=7,
                                             width=self.leftPush - 6,
                                             top=5)
            self.refresh.append((self.new, text, label))
        else:
            self.refresh.append((self.new, text))

    def AddText(self):
        left = self.type.get('left', 0)
        self.new = uiprimitives.Container(name='textField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20),
                                          padding=(left, 0, 0, 0))
        fontsize = self.type.get('fontsize', 12)
        text = uicontrols.Label(
            text=self.type.get('text', ''),
            parent=self.new,
            align=uiconst.TOTOP,
            name='text',
            padding=(0, 3, 0, 3),
            fontsize=fontsize,
            maxLines=1 if bool(self.type.get('tabstops', [])) else None,
            state=uiconst.UI_NORMAL,
            tabs=self.type.get('tabstops', []))
        self.new.height = max(self.new.height, int(text.textheight + 6))
        self.refresh.append((self.new, text))

    def AddEdit(self):
        self.new = uiprimitives.Container(name='editField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP)
        config = 'edit_%s' % self.type['key']
        self.code = uicontrols.SinglelineEdit(
            name=config,
            parent=self.new,
            setvalue=self.type.get('setvalue', ''),
            padding=(self.leftPush, 2, 0, 2),
            ints=self.type.get('intonly', None),
            floats=self.type.get('floatonly', None),
            align=uiconst.TOTOP,
            maxLength=self.type.get('maxlength', None)
            or self.type.get('maxLength', None),
            passwordCharacter=self.type.get('passwordChar', None),
            readonly=self.type.get('readonly', 0),
            autoselect=self.type.get('autoselect', 0),
            isTypeField=self.type.get('isTypeField', False),
            isCharacterField=self.type.get('isCharacterField', False))
        self.new.height = self.code.height + self.code.padTop * 4
        width = self.type.get('width', None)
        if width:
            self.code.SetAlign(uiconst.TOLEFT)
            self.code.width = width
        if self.type.has_key('OnReturn'):
            self.code.data = {'key': self.type['key']}
            self.code.OnReturn = self.type['OnReturn']
        if self.type.has_key('unusedkeydowncallback'):
            self.code.OnUnusedKeyDown = self.type['unusedkeydowncallback']
        if self.type.has_key('onanychar'):
            self.code.OnAnyChar = self.type['onanychar']
        label = self.type.get('label', '')
        text = self.type.get('text', None)
        caption = text or label
        if label == '_hide':
            self.code.padLeft = 0
        elif caption:
            l = uicontrols.EveLabelSmall(text=caption,
                                         align=uiconst.CENTERLEFT,
                                         parent=self.new,
                                         name='label',
                                         left=7,
                                         width=self.leftPush - 6)

    def AddTextedit(self):
        self.new = uiprimitives.Container(name='texteditField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 68))
        self.code = EditPlainText(setvalue=self.type.get('setvalue', '')
                                  or self.type.get('text', ''),
                                  parent=self.new,
                                  padding=(self.leftPush, 2, 0, 2),
                                  readonly=self.type.get('readonly', 0),
                                  showattributepanel=self.type.get(
                                      'showAttribPanel', 0),
                                  maxLength=self.type.get('maxlength', None)
                                  or self.type.get('maxLength', None))
        label = self.type.get('label', '')
        if label == '_hide':
            self.code.padLeft = 0
        elif label:
            uicontrols.EveLabelSmall(text=label,
                                     parent=self.new,
                                     name='label',
                                     left=7,
                                     width=self.leftPush - 6,
                                     top=5)

    def AddCheckbox(self):
        self.new = uiprimitives.Container(name='checkboxCont',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          pos=(0, 0, 0, 18))
        self.code = uicontrols.Checkbox(text=self.type.get('text', ''),
                                        parent=self.new,
                                        configName=self.type.get(
                                            'name', 'none'),
                                        retval=self.type['key'],
                                        checked=self.type.get('setvalue', 0),
                                        groupname=self.type.get('group', None),
                                        callback=self.parent.OnCheckboxChange)
        self.code.data = {}
        onchange = self.type.get('OnChange', None) or self.type.get(
            'onchange', None)
        if onchange:
            self.code.data = {'key': self.type['key'], 'callback': onchange}
        if self.type.has_key('showpanel'):
            self.code.data['showpanel'] = self.type['showpanel']
        if self.code.sr.label:
            self.refresh.append((self.code, self.code.sr.label))
        if self.type.get('hidden', 0):
            self.code.state = uiconst.UI_HIDDEN

    def AddCombo(self):
        self.new = uiprimitives.Container(name='comboField',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20))
        options = self.type.get(
            'options', [(localization.GetByLabel('UI/Common/None'), None)])
        self.code = uicontrols.Combo(label='',
                                     parent=self.new,
                                     options=options,
                                     name=self.type.get('key', 'combo'),
                                     select=self.type.get('setvalue', ''),
                                     padding=(self.leftPush, 2, 0, 2),
                                     align=uiconst.TOTOP,
                                     callback=self.type.get('callback', None),
                                     labelleft=self.leftPush,
                                     prefskey=self.type.get('prefskey', None))
        self.new.height = self.code.height + self.code.padTop * 4
        width = self.type.get('width', None)
        if width:
            self.code.SetAlign(uiconst.TOLEFT)
            self.code.width = width
        label = self.type.get('label', '')
        if label == '_hide':
            self.code.padLeft = 0
        else:
            uicontrols.EveLabelSmall(text=label,
                                     parent=self.new,
                                     name='label',
                                     left=7,
                                     width=self.leftPush - 6,
                                     align=uiconst.CENTERLEFT)

    def AddBtnonly(self):
        self.new = uiprimitives.Container(name='btnonly',
                                          parent=self.parent,
                                          align=uiconst.TOTOP,
                                          height=self.type.get('height', 20))
        btns = []
        align = uiconst.TORIGHT
        for wantedbtn in self.type['buttons']:
            if wantedbtn.has_key('align'):
                al = {'left': uiconst.CENTERLEFT, 'right': uiconst.CENTERRIGHT}
                align = al.get(wantedbtn['align'], uiconst.CENTERRIGHT)
            btns.append([
                wantedbtn['caption'], wantedbtn['function'],
                wantedbtn.get('args', 'self'), None,
                wantedbtn.get('btn_modalresult', 0),
                wantedbtn.get('btn_default', 0),
                wantedbtn.get('btn_cancel', 0)
            ])

        btns = uicontrols.ButtonGroup(btns=btns,
                                      subalign=align,
                                      line=0,
                                      parent=self.new,
                                      align=uiconst.TOTOP,
                                      unisize=self.type.get('uniSize', 1))

    def ProcessForm(self, retfields, required, errorcheck=None):
        result = {}
        for each in retfields:
            if type(each) == dict:
                result.update(each)
                continue
            value = each[0].GetValue()
            if each[1]['type'] == 'checkbox' and each[1].has_key(
                    'group') and value == 1:
                result[each[1]['group']] = each[1]['key']
            else:
                result[each[1]['key']] = value

        if errorcheck:
            hint = errorcheck(result)
            if hint == 'silenterror':
                return
            if hint:
                eve.Message('CustomInfo', {'info': hint})
                return
        if len(required):
            for each in required:
                retval = each[0].GetValue()
                if retval is None or retval == '' or type(
                        retval) in types.StringTypes and retval.strip() == '':
                    fieldname = ''
                    if each[1].has_key('label'):
                        fieldname = each[1]['label']
                        if fieldname == '_hide':
                            fieldname = each[1]['key']
                    else:
                        fieldname = each[1]['key']
                    eve.Message('MissingRequiredField',
                                {'fieldname': fieldname})
                    return
                if each[1]['type'] == 'checkbox' and each[1].has_key('group'):
                    if each[1]['group'] not in result:
                        eve.Message('MissingRequiredField',
                                    {'fieldname': each[1]['group']})
                        return

        return result
Esempio n. 20
0
class ControlCatalogWindow(Window):
    default_windowID = 'ControlCatalogWindow'
    default_topParentHeight = 0
    default_caption = 'UI Control Catalog'
    default_width = 900
    default_height = 800

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        self.entriesByID = {}
        self.currClassData = None
        self.currSampleNum = 1
        self.numSamples = 0
        uthread.new(self.ConstuctLayout)

    def ConstuctLayout(self):
        self.leftCont = DragResizeCont(
            name='leftCont',
            parent=self.sr.main,
            align=uiconst.TOLEFT_PROP,
            settingsID='ControlCatalogWindowLeftCont')
        self.infoCont = ContainerAutoSize(name='infoCont',
                                          parent=self.sr.main,
                                          align=uiconst.TOTOP,
                                          padding=6)
        self.topCont = DragResizeCont(
            name='topCont',
            parent=self.sr.main,
            align=uiconst.TOTOP_PROP,
            settingsID='ControlCatalogWindowSampleCont',
            minSize=0.3,
            maxSize=0.9,
            defaultSize=0.5,
            clipChildren=True)
        tabCont = ContainerAutoSize(name='tabCont',
                                    parent=self.topCont.mainCont,
                                    align=uiconst.TOBOTTOM)
        self.mainButtonGroup = ButtonGroup(name='mainButtonGroup',
                                           parent=self.sr.main)
        self.editCont = Container(name='editCont', parent=self.sr.main)
        GradientSprite(bgParent=self.leftCont,
                       rotation=0,
                       rgbData=[(0, (1.0, 1.0, 1.3))],
                       alphaData=[(0.8, 0.0), (1.0, 0.05)])
        self.controlScroll = ScrollContainer(parent=self.leftCont)
        self.PopulateScroll()
        self.leftButtonGroup = ButtonGroup(name='leftButtonGroup',
                                           parent=self.leftCont,
                                           idx=0)
        self.ConstructLeftButtonGroup()
        self.classNameLabel = Label(parent=self.infoCont,
                                    align=uiconst.TOTOP,
                                    fontsize=15,
                                    bold=True)
        self.classDocLabel = EveLabelSmall(parent=self.infoCont,
                                           align=uiconst.TOTOP)
        GradientSprite(align=uiconst.TOTOP,
                       parent=self.infoCont,
                       rotation=-math.pi / 2,
                       height=16,
                       padding=(-4, -10, -4, 0),
                       rgbData=[(0, (1.0, 1.0, 1.3))],
                       alphaData=[(0.0, 0.0), (1.0, 0.03)])
        GradientSprite(align=uiconst.TOTOP,
                       parent=tabCont,
                       state=uiconst.UI_DISABLED,
                       rotation=math.pi / 2,
                       height=16,
                       padding=(-4, 0, -4, -10),
                       rgbData=[(0, (1.0, 1.0, 1.3))],
                       alphaData=[(0.0, 0.0), (1.0, 0.03)])
        self.sampleNameLabel = EveLabelSmall(parent=tabCont,
                                             align=uiconst.TOTOP,
                                             padBottom=5)
        self.tabs = ToggleButtonGroup(parent=Container(parent=tabCont,
                                                       align=uiconst.TOTOP,
                                                       height=16),
                                      align=uiconst.CENTER,
                                      height=16,
                                      callback=self.OnTabSelected)
        sampleParent = Container(name='sampleParent',
                                 parent=self.topCont.mainCont,
                                 clipChildren=True)
        self.sampleCont = ContainerAutoSize(name='sampleCont',
                                            parent=sampleParent,
                                            align=uiconst.CENTER)
        self.codeEdit = EditPlainText(parent=self.editCont,
                                      align=uiconst.TOALL,
                                      fontcolor=(1, 1, 1, 1),
                                      ignoreTags=True)
        self.codeEdit.OnKeyDown = self.OnCodeEditKeyDown
        self.ConstructMainButtonGroup()
        uthread.new(self._SpyOnSampleCodeReloadThread)

    def OnSampleFileReload(self, path):
        self.PopulateScroll()
        self.SetSelectedControl(self.currClassData)

    def _SpyOnSampleCodeReloadThread(self):
        try:
            from eve.common.modules.sake.platform.win32.win32api import Waitables
            from eve.common.modules.sake.autocompile import SpyFolder

            class ControlCatalogSpyFolder(SpyFolder):
                def __init__(self, callback, *args, **kw):
                    SpyFolder.__init__(self, *args, **kw)
                    self.callback = callback

                def process_folder(self, path):
                    try:
                        self.callback(path)
                    except Exception as e:
                        log.LogException(e)

            spy = ControlCatalogSpyFolder(
                self.OnSampleFileReload, Waitables(),
                (os.path.abspath(os.path.dirname(__file__)), ))
            while not self.destroyed:
                spy.waitables.Wait(0)
                blue.pyos.synchro.Sleep(50)

        except ImportError:
            pass

    def ConstructLeftButtonGroup(self):
        for label, func in (('Browse', self.BrowseControls), ):
            self.leftButtonGroup.AddButton(label, func)

    def ConstructMainButtonGroup(self):
        for label, func, hint in (('Reload', self.ReloadSamples,
                                   'Reload all sample code [ctrl+s]'),
                                  ('Edit module', self.OpenModuleCodeInEditor,
                                   'Open module containing class in editor'),
                                  ('Edit samples', self.OpenSampleCodeInEditor,
                                   'Open sample code in editor')):
            self.mainButtonGroup.AddButton(label, func, hint=hint)

    def OpenSampleCodeInEditor(self, *args):
        self.currClassData.OpenSampleCodeInEditor()

    def BrowseControls(self, *args):
        controlData.BrowseControls()

    def OpenModuleCodeInEditor(self, *args):
        self.currClassData.OpenModuleCodeInEditor()

    def PopulateScroll(self):
        self.controlScroll.Flush()
        for data in controlData.GetControlData():
            TreeViewEntry(parent=self.controlScroll,
                          data=data,
                          eventListener=self)
            if self.currClassData and self.currClassData.GetID() == data.GetID(
            ):
                self.currClassData = data

    def RegisterID(self, entry, entryID):
        if entryID in self.entriesByID:
            raise ValueError('Same entry registered again: %s' % entryID)
        self.entriesByID[entryID] = entry

    def UnregisterID(self, entryID):
        self.entriesByID.pop(entryID)

    def OnTreeViewClick(self, selected):
        if selected.data.HasChildren():
            selected.ToggleChildren()
        else:
            for entry in self.entriesByID.values():
                entry.UpdateSelectedState((selected.data.GetID(), ))

            self.currSampleNum = 1
            self.SetSelectedControl(selected.data)

    def SetSelectedControl(self, data):
        self.codeEdit.Clear()
        self.sampleCont.Flush()
        self.codeEdit.SetText(data.GetCode(), html=False)
        self.currClassData = data
        self.UpdateInfoCont()
        self.ReloadSamples()

    def UpdateInfoCont(self):
        cls = self.currClassData.GetBaseClass()
        if not hasattr(cls, '__module__'):
            raise RuntimeError(
                'Unable to identify sample class. IMPORTANT: Make sure the first line in the example imports the example class itself.'
            )
        self.classNameLabel.text = '<center>' + cls.__module__ + '.' + cls.__name__
        doc = cls.__doc__ or ''
        self.classDocLabel.text = '<center>' + doc.strip()
        if 'depricated' in doc.lower():
            self.classNameLabel.text = '<color=red>' + self.classNameLabel.text
            self.classDocLabel.text = '<color=red>' + self.classDocLabel.text

    def GetCodeText(self):
        return self.codeEdit.GetAllText()

    def ReloadSamples(self, *args):
        numSamples = controlData.GetNumSamples(self.GetCodeText())
        if numSamples != self.numSamples:
            self.numSamples = numSamples
            self.ReconstructTabs()
        self.tabs.SelectByID(self.currSampleNum)

    def ReconstructTabs(self):
        self.tabs.ClearButtons()
        for i in xrange(1, self.numSamples + 1):
            self.tabs.AddButton(i, 'Sample %s' % i)

        self.tabs.width = self.numSamples * 65

    def OnTabSelected(self, sampleNum):
        self.currSampleNum = sampleNum
        self.ReloadCurrentSample()

    def ReloadCurrentSample(self):
        self.sampleCont.Flush()
        uicore.animations.FadeTo(self.sampleCont, 0.0, 1.0, 0.1)
        if self.numSamples:
            exec(self.GetCodeText() + '\n', globals())
            exec 'Sample%s(parent=self.sampleCont)' % self.currSampleNum
            sampleName = None
            exec 'sampleName = Sample%s.__doc__' % self.currSampleNum
            if sampleName:
                self.sampleNameLabel.Show()
                self.sampleNameLabel.text = '<center>' + sampleName
            else:
                self.sampleNameLabel.Hide()
                self.sampleNameLabel.text = ''

    def OnCodeEditKeyDown(self, key, flag):
        if uicore.uilib.Key(uiconst.VK_CONTROL) and key == uiconst.VK_S:
            self.ReloadSamples()
        else:
            return EditPlainText.OnKeyDown(self.codeEdit, key, flag)