예제 #1
0
    def __init__(self, *args, **kwds):

        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)

        self.ack = ExpandoTextCtrl(self,
                                   style=wx.TE_LEFT | wx.TE_MULTILINE
                                   | wx.TE_BESTWRAP | wx.TE_READONLY
                                   | wx.TE_NO_VSCROLL)
        self.ack.SetValue(config._acknowledgement_publications)
        #self.ack.SetMinSize((-1, 55))
        self.citation = ExpandoTextCtrl(self,
                                        style=wx.TE_LEFT | wx.TE_MULTILINE
                                        | wx.TE_BESTWRAP | wx.TE_READONLY
                                        | wx.TE_NO_VSCROLL)
        self.citation.SetValue(config._acknowledgement_citation)
        self.preamble = wx.StaticText(self, -1,
                                      config._acknowledgement_preamble)
        items = [
            config._acknowledgement_preamble_bullet1,
            config._acknowledgement_preamble_bullet2,
            config._acknowledgement_preamble_bullet3,
            config._acknowledgement_preamble_bullet4
        ]
        self.list1 = wx.StaticText(self, -1, "(1) " + items[0])
        self.list2 = wx.StaticText(self, -1, "(2) " + items[1])
        self.list3 = wx.StaticText(self, -1, "(3) " + items[2])
        self.list4 = wx.StaticText(self, -1, "(4) " + items[3])
        self.static_line = wx.StaticLine(self, 0)
        self.__set_properties()
        self.__do_layout()
예제 #2
0
    def __init__(self, parent, log):

        wx.Panel.__init__(self, parent)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        sizer = wx.FlexGridSizer(3, 2, 10, 10)

        btn1 = wx.Button(self, -1, "Example 1")
        text1 = ExpandoTextCtrl(self,
                                -1,
                                _sampleText1,
                                size=(300, -1),
                                style=wx.TE_READONLY)

        btn2 = wx.Button(self, -1, "Example 2")
        text2 = ExpandoTextCtrl(self,
                                -1,
                                _sampleText2,
                                size=(300, -1),
                                style=wx.TE_READONLY)

        sizer.Add(btn1, 0, wx.ALIGN_CENTER)
        sizer.Add(text1, 1, wx.EXPAND)

        sizer.Add(btn2, 0, wx.ALIGN_CENTER)
        sizer.Add(text2, 1, wx.EXPAND)

        sizer.AddGrowableCol(1)
        mainSizer.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
        self.SetSizer(mainSizer)
        mainSizer.Layout()

        btn1.Bind(wx.EVT_BUTTON, self.OnExample1)
        btn2.Bind(wx.EVT_BUTTON, self.OnExample2)
예제 #3
0
class SummaryPage(parentpage):
    def __init__(self, parent):
        super(SummaryPage, self).__init__(parent, 'Selection Summary')

    def GetMyControls(self):
        vbs = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Selection Summary:'),
                                wx.VERTICAL)
        self.summary = ExpandoTextCtrl(self, -1, '')
        self.summary.SetBackgroundColour(self.GetBackgroundColour())
        vbs.Add(self.summary, 0, wx.EXPAND | wx.ALL, 5)
        self._box = vbs
        return vbs

    def set(self, data):
        text = ['Name:\t%s' % data.get('name', '')]
        text.append('Dir:\t%s' % data.get('path', ''))
        if data.get('currentsettings', False):
            text.append('Use current BitPim settings.')
        else:
            text.append('Use default BitPim settings.')
        if guihelper.IsMSWindows():
            if data.get('desktop', False):
                text.append('Create a shortcut on your Desktop.')
            if data.get('startmenu', False):
                text.append('Create a shortcut in your Start Menu.')
        self.summary.SetValue('\n\n'.join(text))
예제 #4
0
    def makeSettings(self, settingsSizer):
        settingsSizerHelper = guiHelper.BoxSizerHelper(self,
                                                       sizer=settingsSizer)
        # Translators: A label for the engines on the engine panel.
        engineLabel = self.title + _("&Engines")
        engineBox = wx.StaticBox(self, label=engineLabel)
        engineGroup = guiHelper.BoxSizerHelper(self,
                                               sizer=wx.StaticBoxSizer(
                                                   engineBox, wx.HORIZONTAL))
        settingsSizerHelper.addItem(engineGroup)

        # Use a ExpandoTextCtrl because even when readonly it accepts focus from keyboard, which
        # standard readonly TextCtrl does not. ExpandoTextCtrl is a TE_MULTILINE control, however
        # by default it renders as a single line. Standard TextCtrl with TE_MULTILINE has two lines,
        # and a vertical scroll bar. This is not necessary for the single line of text we wish to
        # display here.
        engineDesc = self.handler.getCurrentEngine().description
        self.descEngineNameCtrl = ExpandoTextCtrl(self,
                                                  size=(self.scaleSize(250),
                                                        -1),
                                                  value=engineDesc,
                                                  style=wx.TE_READONLY)
        self.descEngineNameCtrl.Bind(wx.EVT_CHAR_HOOK,
                                     self._enterTriggersOnChangeEngine)

        # Translators: This is the label for the button used to change engines,
        # it appears in the context of a engine group on the Online OCR settings panel.
        changeEngineBtn = wx.Button(self, label=_("C&hange..."))
        engineGroup.addItem(
            guiHelper.associateElements(self.descEngineNameCtrl,
                                        changeEngineBtn))
        changeEngineBtn.Bind(wx.EVT_BUTTON, self.onChangeEngine)
        self.engineSettingPanel = SpecificEnginePanel(self, self.handler)
        settingsSizerHelper.addItem(self.engineSettingPanel)
        self.makeGeneralSettings(settingsSizerHelper)
예제 #5
0
 def __init__(self, parent, plugin, controller):
     ExpandoTextCtrl.__init__(self,
                              parent,
                              size=wx.DefaultSize,
                              style=wx.WANTS_CHARS)
     _ContentAssistTextCtrlBase.__init__(
         self, SuggestionSource(plugin, controller))
예제 #6
0
 def __init__(self, parent, plugin, controller):
     ExpandoTextCtrl.__init__(self, parent, size=wx.DefaultSize,
                              style=wx.WANTS_CHARS|wx.TE_NOHIDESEL)
     _ContentAssistTextCtrlBase.__init__(self, SuggestionSource(plugin, controller))
     self.SetBackgroundColour(context.POPUP_BACKGROUND)
     # self.SetOwnBackgroundColour(Colour(200, 222, 40))
     self.SetForegroundColour(context.POPUP_FOREGROUND)
예제 #7
0
 def GetMyControls(self):
     vbs = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Selection Summary:'),
                             wx.VERTICAL)
     self.summary = ExpandoTextCtrl(self, -1, '')
     self.summary.SetBackgroundColour(self.GetBackgroundColour())
     vbs.Add(self.summary, 0, wx.EXPAND | wx.ALL, 5)
     self._box = vbs
     return vbs
예제 #8
0
파일: dialogs.py 프로젝트: jomason/omnivore
 def create_expando(self, key, label, choices=None):
     sizer = self.GetSizer()
     status = ExpandoTextCtrl(self,
                              style=wx.ALIGN_LEFT | wx.TE_READONLY
                              | wx.NO_BORDER)
     attr = self.GetDefaultAttributes()
     status.SetBackgroundColour(attr.colBg)
     sizer.Add(status, 1, wx.ALL | wx.EXPAND, self.border)
     return status
예제 #9
0
 def GetMyControls(self):
     vbs = wx.BoxSizer(wx.VERTICAL)
     vbs.Add(wx.StaticText(self, -1, 'Storage Dir:'), 0, wx.EXPAND | wx.ALL,
             5)
     self.path = ExpandoTextCtrl(self, -1, '', style=wx.TE_READONLY)
     self.path.SetBackgroundColour(self.GetBackgroundColour())
     vbs.Add(self.path, 0, wx.EXPAND | wx.ALL, 5)
     btn = wx.Button(self, -1, 'Browse')
     wx.EVT_BUTTON(self, btn.GetId(), self.OnBrowse)
     vbs.Add(btn, 0, wx.ALL, 5)
     return vbs
예제 #10
0
    def GetMyControls(self):
        vbs = wx.BoxSizer(wx.VERTICAL)
        vbs.Add(wx.StaticText(self, -1, 'Source of data:'), 0,
                wx.ALL | wx.EXPAND, 5)
        self._source_lbl = ExpandoTextCtrl(self, -1, '', style=wx.TE_READONLY)
        self._source_lbl.SetBackgroundColour(self.GetBackgroundColour())
        vbs.Add(self._source_lbl, 0, wx.ALL | wx.EXPAND, 5)

        _btn = wx.Button(self, -1, 'Browse')
        wx.EVT_BUTTON(self, _btn.GetId(), self._OnBrowse)
        vbs.Add(_btn, 0, wx.ALL, 5)
        return vbs
예제 #11
0
    def __init__(self,
                 parent,
                 id=-1,
                 value="",
                 style=wx.TE_READONLY | wx.BORDER_NONE,
                 name=u"BodyText"):
        ExpandoTextCtrl.__init__(self, parent, id, value, wx.DefaultPosition,
                                 wx.DefaultSize, style, wx.DefaultValidator,
                                 name)
        # self.SetBackgroundColour(wx.GREEN)
        # self.UseExtraHeight(False)

        self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvent)
        self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
예제 #12
0
    def __init__(self, parent, pos=wx.DefaultPosition):
        ExpandoTextCtrl.__init__(self, parent, pos = pos, style = wx.BORDER_NONE)

        # Set Font Syle
        self.SetFontStyle(fontColor=wx.Colour(0, 0, 0),
                          fontFace=u'微软雅黑',
                          fontSize=13,
                          fontBold=False, fontItalic=False, fontUnderline=False)

        # Set Height (8 lines)
        height = 8 * self.charHeight
        self.InitHeight = height
        self.SetMinSize((-1, self.InitHeight))
        self.SetSize((-1, self.InitHeight))

        self.SetFocus()
예제 #13
0
    def createFontPanel(self):
        fcp = wx.Panel(self.book)

        font = wx.Font(prefs.get('font'))

        fgcolour = prefs.get('fgcolour')
        bgcolour = prefs.get('bgcolour')

        # output sample/controls
        fcp.sample = ExpandoTextCtrl(fcp,
                                     style=wx.TE_READONLY | wx.TE_RICH
                                     | wx.TE_MULTILINE,
                                     size=wx.Size(400, -1))
        fcp.font_ctrl = wx.FontPickerCtrl(fcp,
                                          style=wx.FNTP_FONTDESC_AS_LABEL
                                          | wx.FNTP_USEFONT_FOR_LABEL,
                                          font=font)

        fcp.theme_picker = wx.Choice(fcp, choices=Theme.all_theme_names())

        fcp.ansi_checkbox = wx.CheckBox(fcp, -1, 'Use ANSI colors')
        # TODO - get and set these two at display time not create time
        fcp.theme = prefs.get('theme')
        fcp.theme_picker.SetSelection(fcp.theme_picker.FindString(fcp.theme))

        if prefs.get('use_ansi'):
            fcp.ansi_checkbox.SetValue(True)
            fcp.theme_picker.Enable()
        else:
            fcp.ansi_checkbox.SetValue(False)
            fcp.theme_picker.Disable()

        ansi_sizer = wx.BoxSizer(wx.HORIZONTAL)
        ansi_sizer.Add(fcp.ansi_checkbox, 0,
                       wx.ALL | wx.EXPAND | wx.ALIGN_CENTER)
        ansi_sizer.Add(fcp.theme_picker, 0,
                       wx.ALL | wx.EXPAND | wx.ALIGN_CENTER)

        panel_sizer = wx.BoxSizer(wx.VERTICAL)
        panel_sizer.Add(fcp.sample, 0, wx.RIGHT | wx.LEFT | wx.EXPAND | wx.TOP,
                        10)
        panel_sizer.AddSpacer(10)
        panel_sizer.Add(fcp.font_ctrl, 0, wx.EXPAND, 0)
        panel_sizer.AddSpacer(10)
        panel_sizer.Add(ansi_sizer, 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 10)

        self.Bind(wx.EVT_FONTPICKER_CHANGED, self.update_sample_text,
                  fcp.font_ctrl)
        self.Bind(wx.EVT_CHOICE, self.update_sample_text, fcp.theme_picker)
        self.Bind(wx.EVT_CHECKBOX, self.update_sample_text, fcp.ansi_checkbox)

        self.Bind(EVT_ETC_LAYOUT_NEEDED, self.resize_everything, fcp.sample)

        fcp.SetSizer(panel_sizer)

        fcp.Layout()

        return fcp
예제 #14
0
class ImportSourcePage(setphone_wizard.MyPage):
    def __init__(self, parent):
        self._source = None
        super(ImportSourcePage, self).__init__(parent, 'Select Import Source')

    def GetMyControls(self):
        vbs = wx.BoxSizer(wx.VERTICAL)
        vbs.Add(wx.StaticText(self, -1, 'Source of data:'), 0,
                wx.ALL | wx.EXPAND, 5)
        self._source_lbl = ExpandoTextCtrl(self, -1, '', style=wx.TE_READONLY)
        self._source_lbl.SetBackgroundColour(self.GetBackgroundColour())
        vbs.Add(self._source_lbl, 0, wx.ALL | wx.EXPAND, 5)

        _btn = wx.Button(self, -1, 'Browse')
        wx.EVT_BUTTON(self, _btn.GetId(), self._OnBrowse)
        vbs.Add(_btn, 0, wx.ALL, 5)
        return vbs

    def setlabel(self):
        self._source_lbl.SetValue(self._source.name())

    @guihelper.BusyWrapper
    def _OnBrowse(self, _=None):
        if not self._source:
            return
        self._source.browse(self)
        self.setlabel()

    def ok(self):
        return self._source and self._source.get()

    def get(self, data):
        data['source_obj'] = self._source
        data['source_id'] = self._source.id
        data['imported'] = False

    def set(self, data):
        self._source = data['source_obj']
        if self._source:
            if data.has_key('source_id'):
                self._source.id = data['source_id']
            self.setlabel()

    def GetActiveDatabase(self):
        return self.GetParent().GetActiveDatabase()
예제 #15
0
    def _OnPopupItemSelected(self, event):
        ID = event.Int

        if ID == 0:
            self._Draw_Cursor(0, -1)
            self._Draw_Cursor(1, -1)

        elif ID == 1:
            if not (self.Memo_Extra):
                self.Memo_Extra = ExpandoTextCtrl(self,
                                                  size=(100, -1),
                                                  pos=self.Hit_Pos,
                                                  value=self.Memo_Extra_Text)
            else:
                #print 'YTRFGJKOP',self.Hit_Pos,event.GetId(),self.Memo_Extra.GetId()
                self.Memo_Extra_Text = self.Memo_Extra.GetValue()
                self.Memo_Extra.Destroy()
                self.Memo_Extra = None

        elif ID == 2:
            if not (self.Memo_Extra):
                self.Memo_Extra = ExpandoTextCtrl(self,
                                                  size=(100, -1),
                                                  pos=self.Hit_Pos,
                                                  value=self.Memo_Extra_Text)
            else:
                self.Memo_Extra.SetPosition(self.Hit_Pos)

        elif ID == 3:
            import SendKeys
            SendKeys.SendKeys('%{PRTSC}')

        elif ID == 4:
            self.Linear_Interpolation = not (self.Linear_Interpolation)
            self.Set_Data(self.Data)  # _Redraw_Data ()
            #self._Redraw()

        elif ID in range(5, 10):
            self.Transparancy = ID - 5
            val = 5 + 50 * (5 - self.Transparancy)
            self.TopFrame.SetTransparent(val)
예제 #16
0
	def __init__(self, parent, id, title):
		wx.Frame.__init__(self,parent,id,title,size=(800,800), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)

		self.number_of_buttons = 2

		self.vbox = wx.BoxSizer(wx.VERTICAL)
		self.display = wx.TextCtrl(self, style=wx.TE_LEFT)
		# self.display.SetValue("http://yasirzaki.net")
		self.display.SetValue("http://www.irs.gov")
		self.vbox.Add(self.display, flag=wx.EXPAND|wx.TOP|wx.BOTTOM, border=4)

		my_btn = wx.Button(self, label='Analyze page')
		my_btn.Bind(wx.EVT_BUTTON, self.on_press)
		self.vbox.Add(my_btn, 0, wx.ALL | wx.CENTER, 5)

		self.textBox = ExpandoTextCtrl (self)
		self.vbox.Add(self.textBox, 0, wx.EXPAND, 5)
		self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textBox)
		self.number_of_buttons += 1

		self.SetSizer(self.vbox)
		self.url = ""
예제 #17
0
    def __init__(self, parent=None, *args, **kw):
        wx.Panel.__init__(self, parent, id=-1)
        self.parent = parent

        vBox = wx.BoxSizer(wx.VERTICAL)
        bookNameLabel = wx.StaticText(self, -1, "Title:")
        bookName = wx.TextCtrl(self, -1, "", size=(150, -1))

        booShortkNameLabel = wx.StaticText(self, -1, "Short Title:")
        bookShortName = ExpandoTextCtrl(self, -1, "", size=(150, -1))

        authorsLabel = wx.StaticText(self, -1, "Authors:")
        authorName = wx.TextCtrl(self, -1, "", size=(50, -1))

        numberOfPagesLabel = wx.StaticText(self, -1, "Number of pages:")
        numberOfPages = wx.TextCtrl(self, -1, "", size=(70, -1))

        hBox1 = wx.BoxSizer(wx.HORIZONTAL)
        hBox1.Add(bookNameLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        hBox1.Add(bookName, 0, wx.EXPAND | wx.ALL)

        hBox2 = wx.BoxSizer(wx.HORIZONTAL)
        hBox2.Add(authorsLabel, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        hBox2.Add(authorName, 0, wx.EXPAND | wx.ALL)

        hBox3 = wx.BoxSizer(wx.HORIZONTAL)
        hBox3.Add(booShortkNameLabel, 0,
                  wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        hBox3.Add(bookShortName, 0, wx.EXPAND | wx.ALL)

        hBox4 = wx.BoxSizer(wx.HORIZONTAL)
        hBox4.Add(numberOfPagesLabel, 0,
                  wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
        hBox4.Add(numberOfPages, 0, wx.EXPAND | wx.ALL)

        vBox.Add(hBox1, 1, wx.EXPAND | wx.ALL, 1)
        vBox.Add(hBox2, 1, wx.EXPAND | wx.ALL, 1)
        vBox.Add(hBox3, 1, wx.EXPAND | wx.ALL, 1)
        vBox.Add(hBox4, 1, wx.EXPAND | wx.ALL, 1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(vBox)
        self.SetSizer(sizer)
예제 #18
0
    def __init__(self, cls, panel, bg_colour, show_id):
        self._Label = ""
        window = panel.GetWindow()
        sizer = panel.GetSizer()

        line = self._StaticLine = wx.StaticLine(window)
        sizer.Add(line, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = G_Const.Sizer_StdBorder)

        checkbox = self._ShowColumnCheckBox = wx.CheckBox(window, id = show_id)
        combo = self._ColumnColourCombo = G_ColourCombo(window, show_id)
        self._RowSizer = cls.BuildRow(panel, checkbox, combo, "enabled-colour-row-{}".format(show_id))

        description = self._DescriptionCtrl = ExpandoTextCtrl(window, style = wx.TE_MULTILINE
            | wx.TE_NO_VSCROLL
            | wx.TE_READONLY
            | wx.TE_RICH2
            | wx.BORDER_NONE)
    
        description.SetBackgroundColour(bg_colour)
        sizer.Add(description, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = G_Const.Sizer_StdBorder, userData = "enabled-colour-description-{}".format(show_id))
예제 #19
0
class PathPage(parentpage):
    def __init__(self, parent):
        super(PathPage, self).__init__(parent, 'Select New Storage Dir')
        if guihelper.IsMSWindows():
            shell = client.Dispatch("WScript.Shell")
            self.defaultdir = os.path.join(shell.SpecialFolders("MyDocuments"),
                                           'Phones')
        else:
            self.defaultdir = os.path.expanduser('~/Phones')

    def GetMyControls(self):
        vbs = wx.BoxSizer(wx.VERTICAL)
        vbs.Add(wx.StaticText(self, -1, 'Storage Dir:'), 0, wx.EXPAND | wx.ALL,
                5)
        self.path = ExpandoTextCtrl(self, -1, '', style=wx.TE_READONLY)
        self.path.SetBackgroundColour(self.GetBackgroundColour())
        vbs.Add(self.path, 0, wx.EXPAND | wx.ALL, 5)
        btn = wx.Button(self, -1, 'Browse')
        wx.EVT_BUTTON(self, btn.GetId(), self.OnBrowse)
        vbs.Add(btn, 0, wx.ALL, 5)
        return vbs

    def ok(self):
        return bool(self.path.GetValue())

    def get(self, data):
        data['path'] = self.path.GetValue()

    def set(self, data):
        path = data.get('path', '')
        if not path:
            path = os.path.join(self.defaultdir, data.get('name', ''))
        self.path.SetValue(path)

    def OnBrowse(self, _):
        with guihelper.WXDialogWrapper(
                wx.DirDialog(self,
                             defaultPath=self.path.GetLabel(),
                             style=wx.DD_NEW_DIR_BUTTON),
                True) as (dlg, retcode):
            if retcode == wx.ID_OK:
                self.path.SetValue(dlg.GetPath())
예제 #20
0
 def __init__(self, parent, plugin, controller):
     ExpandoTextCtrl.__init__(self, parent, size=wx.DefaultSize,
                              style=wx.WANTS_CHARS)
     _ContentAssistTextCtrlBase.__init__(self,
                                         SuggestionSource(plugin,
                                                          controller))
예제 #21
0
class AbstractEngineSettingsPanel(SettingsPanel):
    """
	Settings panel of external services.
	ocrHandler must be specified before use.
	"""
    # Developers: Please also specify a comment for translators
    name = _("Engine")
    title = _("Engine")
    descEngineNameCtrl = None  # type: ExpandoTextCtrl
    engineSettingPanel = None  # type: SpecificEnginePanel
    handler = AbstractEngineHandler  # type: AbstractEngineHandler

    def makeGeneralSettings(self, settingsSizerHelper):
        """
		Generate general settings for engine ocrHandler
		@param settingsSizerHelper:
		@type settingsSizerHelper:
		"""
        pass

    def makeSettings(self, settingsSizer):
        settingsSizerHelper = guiHelper.BoxSizerHelper(self,
                                                       sizer=settingsSizer)
        # Translators: A label for the engines on the engine panel.
        engineLabel = self.title + _(" Engines")
        engineBox = wx.StaticBox(self, label=engineLabel)
        engineGroup = guiHelper.BoxSizerHelper(self,
                                               sizer=wx.StaticBoxSizer(
                                                   engineBox, wx.HORIZONTAL))
        settingsSizerHelper.addItem(engineGroup)

        # Use a ExpandoTextCtrl because even when readonly it accepts focus from keyboard, which
        # standard readonly TextCtrl does not. ExpandoTextCtrl is a TE_MULTILINE control, however
        # by default it renders as a single line. Standard TextCtrl with TE_MULTILINE has two lines,
        # and a vertical scroll bar. This is not necessary for the single line of text we wish to
        # display here.
        engine = self.handler.getCurrentEngine()
        engineDesc = engine.description
        msg = "Engine:\n{0}\nDescription:\n{1}\n".format(engine, engineDesc)
        log.debug(msg)
        self.descEngineNameCtrl = ExpandoTextCtrl(self,
                                                  size=(self.scaleSize(250),
                                                        -1),
                                                  value=engineDesc,
                                                  style=wx.TE_READONLY)
        self.descEngineNameCtrl.Bind(wx.EVT_CHAR_HOOK,
                                     self._enterTriggersOnChangeEngine)

        # Translators: This is the label for the button used to change engines,
        # it appears in the context of a engine group on the Online OCR settings panel.
        changeEngineBtn = wx.Button(self, label=_("C&hange..."))
        engineGroup.addItem(
            guiHelper.associateElements(self.descEngineNameCtrl,
                                        changeEngineBtn))
        changeEngineBtn.Bind(wx.EVT_BUTTON, self.onChangeEngine)
        self.engineSettingPanel = SpecificEnginePanel(self, self.handler)
        settingsSizerHelper.addItem(self.engineSettingPanel)
        self.makeGeneralSettings(settingsSizerHelper)

    def _enterTriggersOnChangeEngine(self, evt):
        if evt.KeyCode == wx.WXK_RETURN:
            self.onChangeEngine(evt)
        else:
            evt.Skip()

    def onChangeEngine(self, evt):
        change_engine = EnginesSelectionDialog(self,
                                               self.handler,
                                               multiInstanceAllowed=True)
        ret = change_engine.ShowModal()
        if ret == wx.ID_OK:
            self.Freeze()
            # trigger a refresh of the settings
            self.onPanelActivated()
            self._sendLayoutUpdatedEvent()
            self.Thaw()

    def updateCurrentEngine(self):
        engine_description = self.handler.getCurrentEngine().description
        self.descEngineNameCtrl.SetValue(engine_description)

    def onPanelActivated(self):
        # call super after all panel updates have been completed, we do not want the panel to show until this is complete.
        self.engineSettingPanel.onPanelActivated()
        super(AbstractEngineSettingsPanel, self).onPanelActivated()

    def onPanelDeactivated(self):
        self.engineSettingPanel.onPanelDeactivated()
        super(AbstractEngineSettingsPanel, self).onPanelDeactivated()

    def onDiscard(self):
        self.engineSettingPanel.onDiscard()

    def onSave(self):
        self.engineSettingPanel.onSave()
예제 #22
0
    def __init__(self, parent):
        super(RuleEditor, self).__init__(
            parent,
            style=wx.DEFAULT_DIALOG_STYLE | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER,
        )
        self.hasMoved = False

        # Dialog main sizer
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        # Form part
        columnsSizer = wx.GridBagSizer(8, 8)
        mainSizer.Add(columnsSizer,
                      proportion=1,
                      flag=wx.EXPAND | wx.ALL,
                      border=8)
        leftSizer = wx.FlexGridSizer(cols=1, vgap=8, hgap=8)
        rightSizer = wx.GridBagSizer(8, 8)
        columnsSizer.Add(leftSizer, pos=(0, 0), flag=wx.EXPAND)
        columnsSizer.Add(wx.StaticLine(self, style=wx.LI_VERTICAL),
                         pos=(0, 1),
                         flag=wx.EXPAND)
        columnsSizer.Add(rightSizer, pos=(0, 2), flag=wx.EXPAND)
        columnsSizer.AddGrowableCol(0)
        columnsSizer.AddGrowableCol(2)
        columnsSizer.AddGrowableRow(0)

        # Header section
        headerSizer = wx.FlexGridSizer(cols=2, vgap=8, hgap=8)
        leftSizer.Add(headerSizer, flag=wx.EXPAND)

        item = wx.StaticText(self, label=_(u"Rule &type:"))
        headerSizer.Add(item)
        item = self.ruleTypeCombo = wx.ComboBox(self, style=wx.CB_READONLY)
        item.Bind(wx.EVT_COMBOBOX, self.onRuleTypeChoice)
        for key, label in ruleTypes.ruleTypeLabels.items():
            self.ruleTypeCombo.Append(label, key)
        headerSizer.Add(item, flag=wx.EXPAND)

        item = wx.StaticText(self, label=_(u"Rule &name:"))
        headerSizer.Add(item)
        item = self.ruleNameText = wx.ComboBox(self)
        headerSizer.Add(item, flag=wx.EXPAND)

        headerSizer.AddGrowableCol(1)

        # Context Box
        contextBox = self.contextBox = wx.StaticBox(self, label=_("Context"))
        contextSizer = self.contextSizer = wx.GridBagSizer(8, 8)
        item = wx.StaticBoxSizer(contextBox, orient=wx.VERTICAL)
        item.Add(contextSizer, flag=wx.EXPAND | wx.ALL, border=4)
        leftSizer.Add(item, flag=wx.EXPAND)

        item = self.contextText = ExpandoTextCtrl(
            contextBox,
            size=(250, -1),
            style=wx.TE_PROCESS_ENTER | wx.TE_MULTILINE | wx.TE_READONLY,
        )
        item.Bind(wx.EVT_TEXT_ENTER, self.onOk)
        contextSizer.Add(item, pos=(0, 0), span=(2, 1), flag=wx.EXPAND)
        item = wx.Button(contextBox, label=_("Edit conte&xt"))
        item.Bind(wx.EVT_BUTTON, self.onContextBtn)
        contextSizer.Add(item, pos=(0, 1))
        contextSizer.AddGrowableCol(0)
        contextSizer.AddGrowableRow(1)

        # Criteria Box
        criteriaBox = wx.StaticBox(self, label=_("Criteria"))
        criteriaSizer = wx.GridBagSizer(8, 8)
        item = wx.StaticBoxSizer(criteriaBox, orient=wx.VERTICAL)
        item.Add(criteriaSizer, flag=wx.EXPAND | wx.ALL, border=4)
        leftSizer.Add(item, flag=wx.EXPAND)
        item = self.criteriaText = ExpandoTextCtrl(
            criteriaBox,
            size=(250, -1),
            style=wx.TE_PROCESS_ENTER | wx.TE_MULTILINE | wx.TE_READONLY,
        )
        item.Bind(wx.EVT_TEXT_ENTER, self.onOk)
        criteriaSizer.Add(item, pos=(0, 0), span=(2, 1), flag=wx.EXPAND)
        item = wx.Button(criteriaBox, label=_("Edit c&riteria"))
        item.Bind(wx.EVT_BUTTON, self.onCriteriaBtn)
        criteriaSizer.Add(item, pos=(0, 1))
        criteriaSizer.AddGrowableCol(0)
        criteriaSizer.AddGrowableRow(1)

        # Actions Box
        actionsBox = self.actionsBox = wx.StaticBox(self,
                                                    label=_("Actions"),
                                                    style=wx.SB_RAISED)
        actionsBox.Hide()  # Visibility depends on rule type
        actionsSizer = wx.GridBagSizer(8, 8)
        item = wx.StaticBoxSizer(actionsBox, orient=wx.VERTICAL)
        item.Add(actionsSizer, flag=wx.EXPAND | wx.ALL, border=4)
        leftSizer.Add(item, flag=wx.EXPAND)

        item = wx.StaticText(actionsBox, label=_("&Keyboard shortcut"))
        actionsSizer.Add(item, pos=(0, 0))
        item = self.gesturesList = wx.ListBox(actionsBox)
        item.Bind(wx.EVT_LISTBOX, self.onGesturesListChoice)
        actionsSizer.Add(item, pos=(0, 1), span=(3, 1), flag=wx.EXPAND)

        item = wx.Button(actionsBox, label=_("Add a keyboard shortcut"))
        item.Bind(wx.EVT_BUTTON, self.onAddGesture)
        actionsSizer.Add(item, pos=(0, 2), flag=wx.EXPAND)

        item = self.deleteGestureButton = wx.Button(
            actionsBox, label=_("Delete this shortcut"))
        item.Bind(wx.EVT_BUTTON, self.onDeleteGesture)
        actionsSizer.Add(item, pos=(1, 2), flag=wx.EXPAND)

        item = wx.StaticText(actionsBox,
                             label=_("&Automatic action at rule detection"))
        actionsSizer.Add(item, pos=(3, 0))
        item = self.autoActionList = wx.ComboBox(actionsBox,
                                                 style=wx.CB_READONLY)
        actionsSizer.Add(item, pos=(3, 1), flag=wx.EXPAND)

        actionsSizer.AddGrowableCol(1)
        actionsSizer.AddGrowableCol(2)
        actionsSizer.AddGrowableRow(2)

        # Properties Box
        propertiesBox = self.propertiesBox = wx.StaticBox(
            self, label=_("Properties"))
        propertiesBox.Hide()  # Visibility depends on rule type
        propertiesSizer = wx.GridBagSizer(8, 8)
        item = wx.StaticBoxSizer(propertiesBox, orient=wx.VERTICAL)
        item.Add(propertiesSizer, flag=wx.EXPAND | wx.ALL, border=4)
        leftSizer.Add(item, flag=wx.EXPAND)
        item = self.propertiesText = ExpandoTextCtrl(
            propertiesBox,
            size=(250, -1),
            style=wx.TE_PROCESS_ENTER | wx.TE_MULTILINE | wx.TE_READONLY,
        )
        item.Bind(wx.EVT_TEXT_ENTER, self.onOk)
        propertiesSizer.Add(item, pos=(0, 0), span=(2, 1), flag=wx.EXPAND)
        item = wx.Button(propertiesBox, label=_("Edit &properties"))
        item.Bind(wx.EVT_BUTTON, self.onPropertiesBtn)
        propertiesSizer.Add(item, pos=(0, 1))
        propertiesSizer.AddGrowableCol(0)
        propertiesSizer.AddGrowableRow(1)

        leftSizer.AddGrowableCol(0)

        # Comment section
        row = 0
        rightSizer.Add(wx.StaticText(self, label=_("&Comment")), pos=(row, 0))

        row += 1
        item = self.comment = wx.TextCtrl(self,
                                          size=(500, 300),
                                          style=wx.TE_MULTILINE)
        rightSizer.Add(item, pos=(row, 0), flag=wx.EXPAND)

        rightSizer.AddGrowableCol(0)
        rightSizer.AddGrowableRow(1)

        mainSizer.Add(self.CreateSeparatedButtonSizer(wx.OK | wx.CANCEL),
                      flag=wx.EXPAND | wx.BOTTOM,
                      border=8)
        self.Bind(wx.EVT_BUTTON, self.onOk, id=wx.ID_OK)
        self.Bind(wx.EVT_BUTTON, self.onCancel, id=wx.ID_CANCEL)
        self.Bind(wx.EVT_SIZE, self.onSize)
        self.Bind(wx.EVT_MOVE_END, self.onMoveEnd)
        self.SetSizerAndFit(mainSizer)
예제 #23
0
    def __init__(self, parent, messageData, nickname=u'王小明'):

        #计算合适的宽度
        border_width = 18
        parent_width, parent_height = parent.GetSize()
        max_width = parent_width * 0.5
        min_width = wxtl.GetTextDisplayLen(nickname) + border_width
        '''
        panel = wx.Panel(parent)
        panel_sizer = wx.BoxSizer()
        panel.SetSizer(panel_sizer)
        text = wx.StaticText(panel, wx.ID_ANY, label = messageData)
        panel_sizer.Add(text, 1, wx.EXPAND)
        text_width, text_height =  panel.GetBestSize()
        panel.Destroy()
        '''

        text_width = wxtl.GetTextDisplayLen(messageData)

        if text_width > max_width:
            width = max_width
        elif text_width < min_width:
            width = min_width
        else:
            width = text_width + border_width

        print text_width
        print min_width
        print width

        #开始初始化用于显示消息的panel
        wx.Panel.__init__(self,
                          parent,
                          id=wx.ID_ANY,
                          pos=wx.DefaultPosition,
                          size=(width, -1),
                          style=wx.TAB_TRAVERSAL)

        self.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT))
        self.SetBackgroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND))

        message_sizer = wx.StaticBoxSizer(
            wx.StaticBox(self, wx.ID_ANY, nickname), wx.VERTICAL)

        self.m_textCtrl7 = ExpandoTextCtrl(self,
                                           wx.ID_ANY,
                                           value=messageData,
                                           style=wx.TE_MULTILINE | wx.NO_BORDER
                                           | wx.TE_READONLY)
        self.m_textCtrl7.SetForegroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT))
        self.m_textCtrl7.SetBackgroundColour(
            wx.SystemSettings.GetColour(wx.SYS_COLOUR_BACKGROUND))
        #self.m_textCtrl7.Enable(False)

        message_sizer.Add(self.m_textCtrl7, 1, wx.ALL | wx.EXPAND, 7)

        self.SetSizer(message_sizer)
        self.Sizer.Fit(self)

        self.Layout()
예제 #24
0
class TestFrame(wx.Frame):
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
        self.log = log
        self.pnl = p = wx.Panel(self)
        self.eom = ExpandoTextCtrl(
            p, size=(250, -1), value="This control will expand as you type")
        self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom)

        # create some buttons and sizers to use in testing some
        # features and also the layout
        vBtnSizer = wx.BoxSizer(wx.VERTICAL)

        btn = wx.Button(p, -1, "Set MaxHeight")
        self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Font")
        self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Write Text")
        self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Append Text")
        self.Bind(wx.EVT_BUTTON, self.OnAppendText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Value")
        self.Bind(wx.EVT_BUTTON, self.OnSetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Get Value")
        self.Bind(wx.EVT_BUTTON, self.OnGetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        for x in range(3):
            btn = wx.Button(p, -1, " ")
            vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
        for x in range(3):
            btn = wx.Button(p, -1, " ")
            hBtnSizer.Add(btn, 0, wx.ALL, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        col1 = wx.BoxSizer(wx.VERTICAL)
        col1.Add(self.eom, 0, wx.ALL, 10)
        col1.Add(hBtnSizer)
        sizer.Add(col1)
        sizer.Add(vBtnSizer)
        p.SetSizer(sizer)

        # Put the panel in a sizer for the frame so we can use self.Fit()
        frameSizer = wx.BoxSizer()
        frameSizer.Add(p, 1, wx.EXPAND)
        self.SetSizer(frameSizer)

        self.Fit()

    def OnRefit(self, evt):
        # The Expando control will redo the layout of the
        # sizer it belongs to, but sometimes this may not be
        # enough, so it will send us this event so we can do any
        # other layout adjustments needed.  In this case we'll
        # just resize the frame to fit the new needs of the sizer.
        self.Fit()

    def OnSetMaxHeight(self, evt):
        mh = self.eom.GetMaxHeight()
        dlg = wx.NumberEntryDialog(self, "", "Enter new max height:",
                                   "MaxHeight", mh, -1, 1000)
        if dlg.ShowModal() == wx.ID_OK:
            self.eom.SetMaxHeight(dlg.GetValue())
        dlg.Destroy()

    def OnSetFont(self, evt):
        dlg = wx.FontDialog(self, wx.FontData())
        dlg.GetFontData().SetInitialFont(self.eom.GetFont())
        if dlg.ShowModal() == wx.ID_OK:
            self.eom.SetFont(dlg.GetFontData().GetChosenFont())
        dlg.Destroy()

    def OnWriteText(self, evt):
        self.eom.WriteText("\nThis is a test...  Only a test.  If this had "
                           "been a real emergency you would have seen the "
                           "quick brown fox jump over the lazy dog.\n")

    def OnAppendText(self, evt):
        self.eom.AppendText("\nAppended text.")

    def OnSetValue(self, evt):
        self.eom.SetValue("A new value.")

    def OnGetValue(self, evt):
        self.log.write("-----------------\n" + self.eom.GetValue())

    def OnOtherBtn(self, evt):
        # just for testing...
        #print(self.eom.numLines)
        self.eom._adjustCtrl()
예제 #25
0
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
        self.log = log
        self.pnl = p = wx.Panel(self)
        self.eom = ExpandoTextCtrl(p, size=(250,-1),
                                   value="This control will expand as you type")
        self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom)

        # create some buttons and sizers to use in testing some
        # features and also the layout
        vBtnSizer = wx.BoxSizer(wx.VERTICAL)

        btn = wx.Button(p, -1, "Set MaxHeight")
        self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Font")
        self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Write Text")
        self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Append Text")
        self.Bind(wx.EVT_BUTTON, self.OnAppendText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Value")
        self.Bind(wx.EVT_BUTTON, self.OnSetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Get Value")
        self.Bind(wx.EVT_BUTTON, self.OnGetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        for x in range(3):
            btn = wx.Button(p, -1, " ")
            vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
        for x in range(3):
            btn = wx.Button(p, -1, " ")
            hBtnSizer.Add(btn, 0, wx.ALL, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        col1 = wx.BoxSizer(wx.VERTICAL)
        col1.Add(self.eom, 0, wx.ALL, 10)
        col1.Add(hBtnSizer)
        sizer.Add(col1)
        sizer.Add(vBtnSizer)
        p.SetSizer(sizer)

        # Put the panel in a sizer for the frame so we can use self.Fit()
        frameSizer = wx.BoxSizer()
        frameSizer.Add(p, 1, wx.EXPAND)
        self.SetSizer(frameSizer)

        self.Fit()
예제 #26
0
class TestFrame(wx.Frame):
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
        self.log = log
        self.pnl = p = wx.Panel(self)
        self.eom = ExpandoTextCtrl(p, size=(250,-1),
                                   value="This control will expand as you type")
        self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom)

        # create some buttons and sizers to use in testing some
        # features and also the layout
        vBtnSizer = wx.BoxSizer(wx.VERTICAL)

        btn = wx.Button(p, -1, "Set MaxHeight")
        self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Font")
        self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Write Text")
        self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Append Text")
        self.Bind(wx.EVT_BUTTON, self.OnAppendText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Value")
        self.Bind(wx.EVT_BUTTON, self.OnSetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Get Value")
        self.Bind(wx.EVT_BUTTON, self.OnGetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)

        for x in range(3):
            btn = wx.Button(p, -1, " ")
            vBtnSizer.Add(btn, 0, wx.ALL|wx.EXPAND, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
        for x in range(3):
            btn = wx.Button(p, -1, " ")
            hBtnSizer.Add(btn, 0, wx.ALL, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        col1 = wx.BoxSizer(wx.VERTICAL)
        col1.Add(self.eom, 0, wx.ALL, 10)
        col1.Add(hBtnSizer)
        sizer.Add(col1)
        sizer.Add(vBtnSizer)
        p.SetSizer(sizer)

        # Put the panel in a sizer for the frame so we can use self.Fit()
        frameSizer = wx.BoxSizer()
        frameSizer.Add(p, 1, wx.EXPAND)
        self.SetSizer(frameSizer)

        self.Fit()


    def OnRefit(self, evt):
        # The Expando control will redo the layout of the
        # sizer it belongs to, but sometimes this may not be
        # enough, so it will send us this event so we can do any
        # other layout adjustments needed.  In this case we'll
        # just resize the frame to fit the new needs of the sizer.
        self.Fit()


    def OnSetMaxHeight(self, evt):
        mh = self.eom.GetMaxHeight()
        dlg = wx.NumberEntryDialog(self, "", "Enter new max height:",
                                   "MaxHeight", mh, -1, 1000)
        if dlg.ShowModal() == wx.ID_OK:
            self.eom.SetMaxHeight(dlg.GetValue())
        dlg.Destroy()


    def OnSetFont(self, evt):
        dlg = wx.FontDialog(self, wx.FontData())
        dlg.GetFontData().SetInitialFont(self.eom.GetFont())
        if dlg.ShowModal() == wx.ID_OK:
            self.eom.SetFont(dlg.GetFontData().GetChosenFont())
        dlg.Destroy()


    def OnWriteText(self, evt):
        self.eom.WriteText("\nThis is a test...  Only a test.  If this had "
                           "been a real emergency you would have seen the "
                           "quick brown fox jump over the lazy dog.\n")

    def OnAppendText(self, evt):
        self.eom.AppendText("\nAppended text.")

    def OnSetValue(self, evt):
        self.eom.SetValue("A new value.")

    def OnGetValue(self, evt):
        self.log.write("-----------------\n" + self.eom.GetValue())

    def OnOtherBtn(self, evt):
        # just for testing...
        #print(self.eom.numLines)
        self.eom._adjustCtrl()
예제 #27
0
class spellCheckerDialog(wx.Dialog):
	# A dialog  to show spellchecker
	_instance = None
	def __new__(cls, *args, **kwargs):
		if spellCheckerDialog._instance is None:
			return wx.Dialog.__new__(cls)
		return spellCheckerDialog._instance

	def __init__ (self, parent):
		spellCheckerDialog._instance = self
		# Translators: Title of the dialog.
		super (spellCheckerDialog, self).__init__(parent, wx.ID_ANY, title = _("Spell checker"))
		title = _("Spell checker")
		self.title = title
		self.makeSettings()

	def makeSettings(self):
		mainSizer = wx.BoxSizer(wx.VERTICAL)
		tasksSizer = wx.BoxSizer(wx.VERTICAL)
		# Translators: A label for the the Not in dictionary field
		NotInDictionLabel = _("&Not in dictionary")
		notDictBox = wx.StaticBox(self, label = NotInDictionLabel)
		self.misspelledCtrl = ExpandoTextCtrl(self, size = (250, -1), value = misspelled, style=wx.TE_READONLY)

		# Translators: A label for the paragraph field
		NotInDiction1Label = _("in the following paragraph:")
		notDict1Box = wx.StaticBox(self, label = NotInDiction1Label)
		self.msParagraphCtrl = ExpandoTextCtrl(self, size = (250, -1), value = msParagraph, style=wx.TE_READONLY)
		# Translators: The label for the list of suggestions.
		sHelper = guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL)
		entriesLabelText=_("&Suggestions")
		self.dictList = sHelper.addLabeledControl(entriesLabelText, wx.ListBox, id = wx.ID_ANY, choices = candidates, style = wx.LB_SINGLE, size = (700,580))
		#self.editingIndex=-1

		# Create buttons.
		# Buttons are in a horizontal row
		buttonsSizer = wx.BoxSizer(wx.HORIZONTAL)

		addButtonID = wx.Window.NewControlId()
		# Translators: Label of button to add the misspelled word to the personal dictionary.
		self.addButton = wx.Button(self, addButtonID, _('&Add'))
		buttonsSizer.Add (self.addButton)

		ignoreButtonID = wx.Window.NewControlId()
		# Translators: Label of button to ignore the misspelled word once.
		self.ignoreButton = wx.Button (self, ignoreButtonID, _('Ignore &once'))
		buttonsSizer.Add(self.ignoreButton)

		ignoreAllButtonID = wx.Window.NewControlId()
		# Translators: Label of button to ignore all cases of the misspelled word.
		self.ignoreAllButton = wx.Button(self, ignoreAllButtonID, _('&Ignore all'))
		buttonsSizer.Add (self.ignoreAllButton)

		substituteButtonID = wx.Window.NewControlId()
		# Translators: Label of button to replace the misspelled word by the suggestion.
		self.substituteButton = wx.Button(self, substituteButtonID, _('&Substitute'))
		buttonsSizer.Add (self.substituteButton)

		substituteAllButtonID = wx.Window.NewControlId()
		# Translators: Label of button to replace all occurrences of the misspelled word by the suggestion.
		self.substituteAllButton = wx.Button(self, substituteAllButtonID, _('Su&bstitute all'))
		buttonsSizer.Add (self.substituteAllButton)

		editButtonID = wx.Window.NewControlId()
		# Translators: Label of button to allow edition of the text.
		self.editButton = wx.Button (self, editButtonID, _('&Edit'))
		buttonsSizer.Add (self.editButton)

		cancelButtonID = wx.Window.NewControlId()
		# Translators: Button Label that closes the add-on.
		self.cancelButton = wx.Button(self, cancelButtonID, _('&Close'))
		buttonsSizer.Add(self.cancelButton)

		tasksSizer.Add(buttonsSizer)
		mainSizer.Add(tasksSizer)

		# Bind the buttons.
		self.Bind(wx.EVT_BUTTON, self.onAdd, id = addButtonID)
		self.Bind (wx.EVT_BUTTON, self.onIgnoreOnce, id = ignoreButtonID )
		self.Bind(wx.EVT_BUTTON, self.onIgnoreAll, id = ignoreAllButtonID)
		self.Bind(wx.EVT_BUTTON, self.onSubstitute, id = substituteButtonID)
		self.Bind(wx.EVT_BUTTON, self.onSubstituteAll, id = substituteAllButtonID)
		self.Bind(wx.EVT_BUTTON, self.onEdit, id = editButtonID)
		self.cancelButton.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
		self.SetEscapeId(wx.ID_CLOSE)
		self.dictList.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
		self.misspelledCtrl.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
		self.msParagraphCtrl.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)

		mainSizer.Fit(self)
		self.SetSizer(mainSizer)
		# Show the window if it is hidden
		if not self.IsShown():
			gui.mainFrame.prePopup()
			self.Show()
			gui.mainFrame.postPopup()

	def onAdd(self,evt):
		global vocabulary, misspelled
		# Create or open a personal dictionary to add our words or words not in main dictionary...
		with open (os.path.join (os.path.dirname(__file__), "personal.txt"), "a", encoding = "UTF-8") as g:
			g.write(misspelled +"\n")
			g.close()
		# Temporarily add this word to Vocabulary to allow the added word to be considered as correct...
		vocabulary.append(misspelled)
		# Clean the variable...
		misspelled = ""
		# Close the dialog...
		self.Close()
		# Resume the spellchecking...
		checkVocabulary()

	def onIgnoreOnce(self,evt):
		global misspelled
		# Just clean the variable and do nothing since the process restart on next word...
		misspelled = ""
		self.Close()
		checkVocabulary()

	def onIgnoreAll(self,evt):
		global vocabulary, misspelled
		# Temporarily add the word to the dictionary to make it considered correct...
		vocabulary.append(misspelled)
		misspelled = ""
		self.Close()
		checkVocabulary()

	def onSubstitute(self,evt):
		global allText, misspelled, candidates, misspelledWord
		# Get the selected word from the candidates list...
		index = self.dictList.GetSelection()
		# Add to replacement word the character before and after the misspelled word to maintain possible punctuations...
		replacementWord = misspelledWord[0]+str (candidates[index])+misspelledWord[-1]
		# Replace the misspelled by the candidate word selected...
		allText = allText.replace (str(misspelledWord), replacementWord, 1)
		misspelled = ""
		self.Close()
		checkVocabulary()

	def onSubstituteAll(self,evt):
		global allText, misspelled, candidates, misspelledWord, wordsList
		# Get the selected word from the candidates list...
		index = self.dictList.GetSelection()
		# Add to replacement word the character before and after the misspelled word to maintain possible punctuations...
		replacementWord = misspelledWord[0]+str (candidates[index])+misspelledWord[-1]
		# Replace the misspelled by the candidate word selected...
		allText = allText.replace (str(misspelledWord), replacementWord)
		# Remove the misspelled word from the list of words...
		wordsList = list(filter(lambda a: a != misspelled, wordsList))
		misspelled = ""
		self.Close()
		checkVocabulary()

	def onEdit(self,evt):
		global allText, msParagraph
		# Translators: Message dialog box to change a block of text.
		dlg = wx.TextEntryDialog(gui.mainFrame, _("Enter the new block of text or press Enter to confirm"), self.title, style = wx.OK | wx.CANCEL | wx.TE_MULTILINE)
		dlg.SetValue(msParagraph)
		if dlg.ShowModal() == wx.ID_OK:
			corParagraph = dlg.GetValue()
			allText = allText.replace(msParagraph, corParagraph)
			misspelled = ""
		else:
			dlg.Destroy()
			return
		misspelled = ""
		self.Close()
		checkVocabulary()

	def onKeyPress(self, evt):
		# Sets enter key  to replace the misspelled word by the suggestion and Escape to close.
		evt.Skip()
		keycode = evt.GetKeyCode()
		if keycode == wx.WXK_RETURN and self.dictList.GetSelection():
			self.onSubstitute(evt)
		elif keycode == wx.WXK_ESCAPE:
			self.Destroy()

	def Destroy(self):
		self = spellCheckerDialog._instance
		if gui.messageBox(_("Do you want to apply the changes?"), _("Spell checker"), style=wx.ICON_QUESTION|wx.YES_NO) == wx.YES:
			self.applyCorrections()

		spellCheckerDialog._instance = None
		super (spellCheckerDialog, self).Destroy()

	def applyCorrections(self):
		self.Close()
		KeyboardInputGesture.fromName("Control+home").send()
		KeyboardInputGesture.fromName("Control+Shift+end").send()
		api.copyToClip(str(allText))
		time.sleep(2.0)
		KeyboardInputGesture.fromName("Control+v").send()

		spellCheckerDialog._instance = None
		super (spellCheckerDialog, self).Destroy()
예제 #28
0
	def makeSettings(self):
		mainSizer = wx.BoxSizer(wx.VERTICAL)
		tasksSizer = wx.BoxSizer(wx.VERTICAL)
		# Translators: A label for the the Not in dictionary field
		NotInDictionLabel = _("&Not in dictionary")
		notDictBox = wx.StaticBox(self, label = NotInDictionLabel)
		self.misspelledCtrl = ExpandoTextCtrl(self, size = (250, -1), value = misspelled, style=wx.TE_READONLY)

		# Translators: A label for the paragraph field
		NotInDiction1Label = _("in the following paragraph:")
		notDict1Box = wx.StaticBox(self, label = NotInDiction1Label)
		self.msParagraphCtrl = ExpandoTextCtrl(self, size = (250, -1), value = msParagraph, style=wx.TE_READONLY)
		# Translators: The label for the list of suggestions.
		sHelper = guiHelper.BoxSizerHelper(self, orientation=wx.VERTICAL)
		entriesLabelText=_("&Suggestions")
		self.dictList = sHelper.addLabeledControl(entriesLabelText, wx.ListBox, id = wx.ID_ANY, choices = candidates, style = wx.LB_SINGLE, size = (700,580))
		#self.editingIndex=-1

		# Create buttons.
		# Buttons are in a horizontal row
		buttonsSizer = wx.BoxSizer(wx.HORIZONTAL)

		addButtonID = wx.Window.NewControlId()
		# Translators: Label of button to add the misspelled word to the personal dictionary.
		self.addButton = wx.Button(self, addButtonID, _('&Add'))
		buttonsSizer.Add (self.addButton)

		ignoreButtonID = wx.Window.NewControlId()
		# Translators: Label of button to ignore the misspelled word once.
		self.ignoreButton = wx.Button (self, ignoreButtonID, _('Ignore &once'))
		buttonsSizer.Add(self.ignoreButton)

		ignoreAllButtonID = wx.Window.NewControlId()
		# Translators: Label of button to ignore all cases of the misspelled word.
		self.ignoreAllButton = wx.Button(self, ignoreAllButtonID, _('&Ignore all'))
		buttonsSizer.Add (self.ignoreAllButton)

		substituteButtonID = wx.Window.NewControlId()
		# Translators: Label of button to replace the misspelled word by the suggestion.
		self.substituteButton = wx.Button(self, substituteButtonID, _('&Substitute'))
		buttonsSizer.Add (self.substituteButton)

		substituteAllButtonID = wx.Window.NewControlId()
		# Translators: Label of button to replace all occurrences of the misspelled word by the suggestion.
		self.substituteAllButton = wx.Button(self, substituteAllButtonID, _('Su&bstitute all'))
		buttonsSizer.Add (self.substituteAllButton)

		editButtonID = wx.Window.NewControlId()
		# Translators: Label of button to allow edition of the text.
		self.editButton = wx.Button (self, editButtonID, _('&Edit'))
		buttonsSizer.Add (self.editButton)

		cancelButtonID = wx.Window.NewControlId()
		# Translators: Button Label that closes the add-on.
		self.cancelButton = wx.Button(self, cancelButtonID, _('&Close'))
		buttonsSizer.Add(self.cancelButton)

		tasksSizer.Add(buttonsSizer)
		mainSizer.Add(tasksSizer)

		# Bind the buttons.
		self.Bind(wx.EVT_BUTTON, self.onAdd, id = addButtonID)
		self.Bind (wx.EVT_BUTTON, self.onIgnoreOnce, id = ignoreButtonID )
		self.Bind(wx.EVT_BUTTON, self.onIgnoreAll, id = ignoreAllButtonID)
		self.Bind(wx.EVT_BUTTON, self.onSubstitute, id = substituteButtonID)
		self.Bind(wx.EVT_BUTTON, self.onSubstituteAll, id = substituteAllButtonID)
		self.Bind(wx.EVT_BUTTON, self.onEdit, id = editButtonID)
		self.cancelButton.Bind(wx.EVT_BUTTON, lambda evt: self.Destroy())
		self.SetEscapeId(wx.ID_CLOSE)
		self.dictList.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
		self.misspelledCtrl.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)
		self.msParagraphCtrl.Bind(wx.EVT_KEY_DOWN, self.onKeyPress)

		mainSizer.Fit(self)
		self.SetSizer(mainSizer)
		# Show the window if it is hidden
		if not self.IsShown():
			gui.mainFrame.prePopup()
			self.Show()
			gui.mainFrame.postPopup()
예제 #29
0
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, title="Test ExpandoTextCtrl")
        self.log = log
        self.pnl = p = wx.Panel(self)
        self.eom = ExpandoTextCtrl(
            p, size=(250, -1), value="This control will expand as you type")
        self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.eom)

        # create some buttons and sizers to use in testing some
        # features and also the layout
        vBtnSizer = wx.BoxSizer(wx.VERTICAL)

        btn = wx.Button(p, -1, "Set MaxHeight")
        self.Bind(wx.EVT_BUTTON, self.OnSetMaxHeight, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Font")
        self.Bind(wx.EVT_BUTTON, self.OnSetFont, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Write Text")
        self.Bind(wx.EVT_BUTTON, self.OnWriteText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Append Text")
        self.Bind(wx.EVT_BUTTON, self.OnAppendText, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Set Value")
        self.Bind(wx.EVT_BUTTON, self.OnSetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        btn = wx.Button(p, -1, "Get Value")
        self.Bind(wx.EVT_BUTTON, self.OnGetValue, btn)
        vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)

        for x in range(3):
            btn = wx.Button(p, -1, " ")
            vBtnSizer.Add(btn, 0, wx.ALL | wx.EXPAND, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        hBtnSizer = wx.BoxSizer(wx.HORIZONTAL)
        for x in range(3):
            btn = wx.Button(p, -1, " ")
            hBtnSizer.Add(btn, 0, wx.ALL, 5)
            self.Bind(wx.EVT_BUTTON, self.OnOtherBtn, btn)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        col1 = wx.BoxSizer(wx.VERTICAL)
        col1.Add(self.eom, 0, wx.ALL, 10)
        col1.Add(hBtnSizer)
        sizer.Add(col1)
        sizer.Add(vBtnSizer)
        p.SetSizer(sizer)

        # Put the panel in a sizer for the frame so we can use self.Fit()
        frameSizer = wx.BoxSizer()
        frameSizer.Add(p, 1, wx.EXPAND)
        self.SetSizer(frameSizer)

        self.Fit()
예제 #30
0
class JSCleaner(wx.Frame):
	def __init__(self, parent, id, title):
		wx.Frame.__init__(self,parent,id,title,size=(800,800), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER)

		self.number_of_buttons = 2

		self.vbox = wx.BoxSizer(wx.VERTICAL)
		self.display = wx.TextCtrl(self, style=wx.TE_LEFT)
		# self.display.SetValue("http://yasirzaki.net")
		self.display.SetValue("http://www.irs.gov")
		self.vbox.Add(self.display, flag=wx.EXPAND|wx.TOP|wx.BOTTOM, border=4)

		my_btn = wx.Button(self, label='Analyze page')
		my_btn.Bind(wx.EVT_BUTTON, self.on_press)
		self.vbox.Add(my_btn, 0, wx.ALL | wx.CENTER, 5)

		self.textBox = ExpandoTextCtrl (self)
		self.vbox.Add(self.textBox, 0, wx.EXPAND, 5)
		self.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit, self.textBox)
		self.number_of_buttons += 1

		self.SetSizer(self.vbox)
		self.url = ""

	def on_script_press(self, event):
		try:
			name = event.GetEventObject().myname
			toggle = event.GetEventObject().GetValue()
		except:
			name = "script0"
			toggle = True

		if toggle:
			self.textBox.SetValue(self.JavaScripts[name][0])

			print("\n")
			print("-"*20)
			os.system("clear")
			print (jsbeautifier.beautify(self.JavaScripts[name][1]))
			# print (self.JavaScripts[name][2])

			self.html = self.html.replace("<!--"+name+"-->",self.JavaScripts[name][2])
			self.encode_save_index (self.html, "irs.gov", os.getcwd() + "/../proxy/data/")
			driver.get(self.url + "/js.html")

		else:
			self.selectAll.SetValue(False)
			self.textBox.SetValue("")

			os.system("clear")
			
			self.html = self.html.replace(self.JavaScripts[name][2], "<!--"+name+"-->")
			self.encode_save_index (self.html, "irs.gov", os.getcwd() + "/../proxy/data/")
			driver.get(self.url + "/js.html")

	def on_all_press(self, event):
		try:
			toggle = event.GetEventObject().GetValue()
		except:
			toggle = True

		if toggle:
			# Insert all scripts
			for name in self.JavaScripts:
				if "<!--"+name+"-->" in self.html:
					self.html = self.html.replace("<!--"+name+"-->", self.JavaScripts[name][2])
			
			self.encode_save_index (self.html, "irs.gov", os.getcwd() + "/../proxy/data/")
			driver.get(self.url + "/js.html")
			
			# Toggle all script buttons
			for btn in self.scriptButtons:
				btn.SetValue(True)

		else:
			# Remove all scripts
			for name in self.JavaScripts:
				if self.JavaScripts[name][2] in self.html:
					self.html = self.html.replace(self.JavaScripts[name][2], "<!--"+name+"-->")

			self.encode_save_index (self.html, "irs.gov", os.getcwd() + "/../proxy/data/")
			driver.get(self.url + "/js.html")

			# Untoggle all script buttons
			for btn in self.scriptButtons:
				btn.SetValue(False)


	def on_press(self, event):
		self.url = self.display.GetValue()
		if not self.url:
			return

		self.JavaScripts = {}
		self.scriptButtons = []

		driver.get(self.url)
		html_source = driver.page_source

		self.html = str(BeautifulSoup(html_source, 'html.parser'))

		#Here is the part which extracts Scripts
		scripts = driver.find_elements_by_tag_name("script")
		scriptsCount = self.html.count("<script")

		self.selectAll = wx.ToggleButton(self, label='Select All')
		self.selectAll.Bind(wx.EVT_TOGGLEBUTTON, self.on_all_press)
		self.vbox.Add(self.selectAll, 0, wx.ALIGN_LEFT | wx.ALL, 5)
		self.number_of_buttons += 1

		self.panel = wx.lib.scrolledpanel.ScrolledPanel(self,-1, size=(600,700), style=wx.SIMPLE_BORDER) #pos=(20,100)
		self.panel.SetupScrolling()
		self.panel.SetBackgroundColour('#FFFFFF')
		
		self.vbox.Add(self.panel, 0, wx.EXPAND, 5)
		self.SetSizer(self.vbox)

		self.gs = wx.GridSizer(scriptsCount,4,5,5)

		cnt = 0

		firstButton = False

		while "<script" in self.html:
			sIndex = self.html.find("<script")
			eIndex = self.html.find("</script>")
			text = self.html[sIndex:eIndex+9]

			if ' src="' in text:
				src = text.split(' src=')[1].split('"')[1].replace("http://","").replace("https://","")
				src = src.split("?")[0]
				contentText = ""

				# Connect to the database.
				conn = pymysql.connect(db=db_name,user=db_user,passwd=db_password,host='localhost',autocommit=True)
				d = conn.cursor()

				sql = "SELECT filename FROM caching WHERE url LIKE '%{0}%'".format(src)
				d.execute(sql)

				if d.rowcount > 0:
					filename = d.fetchone()[0]
					contentText = getScriptText(filename)
				else:
					src = src.strip("/").split("/")
					src[0] = src[0]+":443"
					src = "/".join(src)

					sql = "SELECT filename FROM caching WHERE url LIKE '%{0}%'".format(src)
					d.execute(sql)

					if d.rowcount > 0:
						filename = d.fetchone()[0]
						contentText = getScriptText(filename)
					else:
						print (d.rowcount, src)

				print (text)
				print (contentText[:200])
				print ("---"*20)

				d.close()
				conn.close()

			else:
				contentText = text

			self.html = self.html.replace(text,"\n<!--script"+str(cnt)+"-->\n")
			self.scriptButtons.append(wx.ToggleButton(self.panel, label="script"+str(cnt), size=(100,50)))
			self.scriptButtons[cnt].Bind(wx.EVT_TOGGLEBUTTON, self.on_script_press)
			self.scriptButtons[cnt].myname = "script"+str(cnt)
			self.gs.Add(self.scriptButtons[cnt], 0, wx.ALL, 0)

			if firstButton == False:
				firstButton = self.scriptButtons[cnt]

			labels = ["critical","non-critical","translatable"]
			colors = [wx.Colour(255, 0, 0),wx.Colour(0, 255, 0),wx.Colour(0, 0, 255)]

			for i in range(3):
				textBox = wx.ToggleButton(self.panel, label=labels[i], size=(100,25))
				textBox.SetBackgroundColour(colors[i])
				textBox.SetForegroundColour(colors[i])
				self.gs.Add(textBox, 0, wx.ALL,0)

			tmp = {}
			for feature in features:
				if feature in contentText:
					tmp[feature] = contentText.count(feature)
			tmp_sorted = OrderedDict(sorted(tmp.items(), key=lambda x: x[1], reverse=True))
			tmp = ""
			for k, v in tmp_sorted.items():
				tmp += "{0}: {1}\n".format(k,v) 

			self.JavaScripts["script"+str(cnt)] = [tmp, contentText, text]
			self.number_of_buttons += 1
			cnt += 1

		self.panel.SetSizer(self.gs)
		self.textBox.SetValue("Feature display will be here\n\n\n\n\n")

		self.encode_save_index (self.html, "irs.gov", os.getcwd() + "/../proxy/data/")

		driver.get(self.url + "/js.html")

	def encode_save_index(self, content, name, path):
		with gzip.open(path + name + ".c", "wb") as f:
			f.write(content.encode())
			f.close
			print ("HTML is encoded and saved!")

		content_size = os.path.getsize(path + name + ".c")

		with open(path + name + ".h") as f:
			new_text = ""
			existing_size = ""
			for line in f:
				if "Content-Length:" in line:
					existing_size = line.split(' ',1)[1]
		
		if(existing_size != ""):
			with open(path + name + ".h") as f:
				atext = f.read().replace(existing_size, str(content_size)+ "\n")

			with open(path + name + ".h", "w") as f:
				f.write(atext)

	def OnRefit(self, evt):
		self.panel.SetSizer(self.gs)
예제 #31
0
class DialogAcknowledge(wx.Dialog):
    """
    "Acknowledgement" Dialog Box

    Shows the current method for acknowledging SasView in
    scholarly publications.
    """

    def __init__(self, *args, **kwds):

        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
        wx.Dialog.__init__(self, *args, **kwds)

        self.ack = ExpandoTextCtrl(self, style=wx.TE_LEFT|wx.TE_MULTILINE|wx.TE_BESTWRAP|wx.TE_READONLY|wx.TE_NO_VSCROLL)
        self.ack.SetValue(config._acknowledgement_publications)
        #self.ack.SetMinSize((-1, 55))
        self.citation = ExpandoTextCtrl(self, style=wx.TE_LEFT|wx.TE_MULTILINE|wx.TE_BESTWRAP|wx.TE_READONLY|wx.TE_NO_VSCROLL)
        self.citation.SetValue(config._acknowledgement_citation)
        self.preamble = wx.StaticText(self, -1, config._acknowledgement_preamble)
        items = [config._acknowledgement_preamble_bullet1,
                 config._acknowledgement_preamble_bullet2,
                 config._acknowledgement_preamble_bullet3,
                 config._acknowledgement_preamble_bullet4]
        self.list1 = wx.StaticText(self, -1, "(1) " + items[0])
        self.list2 = wx.StaticText(self, -1, "(2) " + items[1])
        self.list3 = wx.StaticText(self, -1, "(3) " + items[2])
        self.list4 = wx.StaticText(self, -1, "(4) " + items[3])
        self.static_line = wx.StaticLine(self, 0)
        self.__set_properties()
        self.__do_layout()

    def __set_properties(self):
        """
        :TODO - add method documentation
        """
        # begin wxGlade: DialogAbout.__set_properties
        self.preamble.SetFont(wx.Font(11, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.preamble.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.SetTitle("Acknowledging SasView")
        #Increased size of box from (525, 225), SMK, 04/10/16
        self.SetClientSize((600, 320))
        # end wxGlade

    def __do_layout(self):
        """
        :TODO - add method documentation
        """
        # begin wxGlade: DialogAbout.__do_layout
        sizer_main = wx.BoxSizer(wx.VERTICAL)
        sizer_titles = wx.BoxSizer(wx.VERTICAL)
        sizer_titles.Add(self.preamble, 0, wx.ALL|wx.EXPAND, 5)
        sizer_titles.Add(self.list1, 0, wx.ALL|wx.EXPAND, 5)
        sizer_titles.Add(self.ack, 0, wx.ALL|wx.EXPAND, 5)
        sizer_titles.Add(self.list2, 0, wx.ALL|wx.EXPAND, 5)
        sizer_titles.Add(self.citation, 0, wx.ALL|wx.EXPAND, 5)
        sizer_titles.Add(self.list3, 0, wx.ALL|wx.EXPAND, 5)
        #sizer_titles.Add(self.static_line, 0, wx.ALL|wx.EXPAND, 0)
        sizer_titles.Add(self.list4, 0, wx.ALL|wx.EXPAND, 5)
        sizer_main.Add(sizer_titles, -1, wx.ALL|wx.EXPAND, 5)
        self.SetAutoLayout(True)
        self.SetSizer(sizer_main)
        self.Layout()
        self.Centre()
예제 #32
0
    def addRow(self, row, rowLabel=None):
        """Add one row of info, either header (col names) or normal data

        Adds items sequentially; FlexGridSizer moves to next row automatically
        """
        labelBox = wx.BoxSizer(wx.HORIZONTAL)
        if not rowLabel:
            if sys.platform == 'darwin':
                self.SetWindowVariant(variant=wx.WINDOW_VARIANT_SMALL)
            label = _translate('cond %s:') % str(row + 1 -
                                                 int(self.hasHeader)).zfill(2)
            rowLabel = wx.StaticText(self, -1, label=label)
            rowLabel.SetForegroundColour(darkgrey)
            if sys.platform == 'darwin':
                self.SetWindowVariant(variant=wx.WINDOW_VARIANT_NORMAL)
        labelBox.Add(rowLabel, 1, flag=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM)
        self.sizer.Add(labelBox, 1, flag=wx.ALIGN_CENTER)
        lastRow = []
        for col in range(self.cols):
            # get the item, as unicode for display purposes:
            if len(str(self.grid[row][col])):  # want 0, for example
                item = str(self.grid[row][col])
            else:
                item = u''
            # make a textbox:
            field = ExpandoTextCtrl(self,
                                    -1,
                                    item,
                                    size=(self.colSizes[col], 20))
            field.Bind(EVT_ETC_LAYOUT_NEEDED, self.onNeedsResize)
            field.SetMaxHeight(100)  # ~ 5 lines
            if self.hasHeader and row == 0:
                # add a default column name (header) if none provided
                header = self.grid[0]
                if item.strip() == '':
                    c = col
                    while self.colName(c) in header:
                        c += 1
                    field.SetValue(self.colName(c))
                field.SetForegroundColour(darkblue)  # dark blue
                # or (self.parent and
                if not valid_var_re.match(field.GetValue()):
                    # self.parent.exp.namespace.exists(field.GetValue()) ):
                    # was always red when preview .xlsx file -- in
                    # namespace already is fine
                    if self.fixed:
                        field.SetForegroundColour("Red")
                field.SetToolTip(
                    wx.ToolTip(
                        _translate(
                            'Should be legal as a variable name (alphanumeric)'
                        )))
                field.Bind(wx.EVT_TEXT, self.checkName)
            elif self.fixed:
                field.SetForegroundColour(darkgrey)
                field.SetBackgroundColour(white)

            # warn about whitespace unless will be auto-removed. invisible,
            # probably spurious:
            if (self.fixed or not self.clean) and item != item.strip():
                field.SetForegroundColour('Red')
                # also used in show():
                self.warning = _translate('extra white-space')
                field.SetToolTip(wx.ToolTip(self.warning))
            if self.fixed:
                field.Disable()
            lastRow.append(field)
            self.sizer.Add(field, 1)
        self.inputFields.append(lastRow)
        if self.hasHeader and row == 0:
            self.header = lastRow
예제 #33
0
 def create_control(self):
     c = ExpandoTextCtrl(self.parent,
                         style=wx.ALIGN_LEFT | wx.TE_READONLY
                         | wx.NO_BORDER)
     return c