コード例 #1
0
ファイル: repl.py プロジェクト: mdcutone/psychopy
        def __init__(self, parent):
            wx.Panel.__init__(self, parent, size=(30, -1))
            self.parent = parent

            # Setup sizer
            self.borderBox = wx.BoxSizer(wx.VERTICAL)
            self.SetSizer(self.borderBox)
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.borderBox.Add(self.sizer, border=3, flag=wx.ALL)
            # Start button
            self.startBtn = wx.Button(self, size=(16, 16), style=wx.BORDER_NONE)
            self.startBtn.SetToolTip(_translate(
                "Close the current shell."
            ))
            self.startBtn.SetBitmap(
                icons.ButtonIcon(stem="start", size=16).bitmap
            )
            self.sizer.Add(self.startBtn, border=3, flag=wx.ALL)
            self.startBtn.Bind(wx.EVT_BUTTON, self.parent.start)
            # Restart button
            self.restartBtn = wx.Button(self, size=(16, 16), style=wx.BORDER_NONE)
            self.restartBtn.SetToolTip(_translate(
                "Close the current shell and start a new one, this will clear any variables."
            ))
            self.restartBtn.SetBitmap(
                icons.ButtonIcon(stem="restart", size=16).bitmap
            )
            self.sizer.Add(self.restartBtn, border=3, flag=wx.ALL)
            self.restartBtn.Bind(wx.EVT_BUTTON, self.parent.restart)
            # Stop button
            self.stopBtn = wx.Button(self, size=(16, 16), style=wx.BORDER_NONE)
            self.stopBtn.SetToolTip(_translate(
                "Close the current shell."
            ))
            self.stopBtn.SetBitmap(
                icons.ButtonIcon(stem="stop", size=16).bitmap
            )
            self.sizer.Add(self.stopBtn, border=3, flag=wx.ALL)
            self.stopBtn.Bind(wx.EVT_BUTTON, self.parent.close)
            # Clear button
            self.clrBtn = wx.Button(self, size=(16, 16), style=wx.BORDER_NONE)
            self.clrBtn.SetToolTip(_translate(
                "Clear all previous output."
            ))
            self.clrBtn.SetBitmap(
                icons.ButtonIcon(stem="clear", size=16).bitmap
            )
            self.sizer.Add(self.clrBtn, border=3, flag=wx.ALL)
            self.clrBtn.Bind(wx.EVT_BUTTON, self.parent.clear)

            self.update()
            self.Layout()
コード例 #2
0
        def __init__(self, parent):
            wx.Panel.__init__(self, parent, size=(30, 90))
            self.parent = parent

            # Setup sizer
            self.borderBox = wx.BoxSizer(wx.VERTICAL)
            self.SetSizer(self.borderBox)
            self.sizer = wx.BoxSizer(wx.VERTICAL)
            self.borderBox.Add(self.sizer, border=3, flag=wx.ALL)

            # Clear button
            self.clrBtn = wx.Button(self, size=(16, 16), style=wx.BORDER_NONE)
            self.clrBtn.SetToolTip(_translate("Clear all previous output."))
            self.clrBtn.SetBitmap(
                icons.ButtonIcon(stem="clear", size=16).bitmap)
            self.sizer.Add(self.clrBtn, border=3, flag=wx.ALL)
            self.clrBtn.Bind(wx.EVT_BUTTON, self.parent.ctrl.clear)

            self.Layout()
コード例 #3
0
    def test_button_icons(self, get_app):
        exemplars = [
            # File open, 32px
            (icons.ButtonIcon("fileopen",
                              size=32), icons.ButtonIcon("fileopen", size=32)),
            # Clear, 16px
            (icons.ButtonIcon("clear",
                              size=32), icons.ButtonIcon("clear", size=32)),
        ]
        tykes = [
            # File open, no size
            (icons.ButtonIcon("fileopen",
                              size=32), icons.ButtonIcon("fileopen", size=32)),
            # File open, wrong size
            (icons.ButtonIcon("fileopen",
                              size=48), icons.ButtonIcon("fileopen", size=48)),
        ]

        for case in exemplars + tykes:
            # Ensure that the underlying bitmap of each button is the same object
            assert case[0].bitmap is case[1].bitmap
コード例 #4
0
ファイル: preferencesDlg.py プロジェクト: mdcutone/psychopy
    def addPage(self, label, name, sections=(), bitmap=None):
        """Add a page to the property grid manager."""

        if name in self.pages.keys():
            raise ValueError("Page already exists.")

        for s in sections:
            if s not in self.sections.keys():
                self.sections[s] = dict()

        nbBitmap = icons.ButtonIcon(stem=bitmap, size=(48, 48)).bitmap
        if nbBitmap.IsOk():
            self.prefsImages.Add(nbBitmap)

        self.pages[self.pageIdx] = (self.proPrefs.AddPage(name, wx.NullBitmap),
                                    list(sections))
        self.pageNames[name] = self.pageIdx
        self.lstPrefPages.InsertItem(self.lstPrefPages.GetItemCount(),
                                     _localized[label], self.pageIdx)

        self.pageIdx += 1
コード例 #5
0
ファイル: preferencesDlg.py プロジェクト: mdcutone/psychopy
    def populatePrefs(self):
        """Populate pages with property items for each preference."""
        # clear pages
        for sectionName in self.prefsSpec.keys():
            prefsSection = self.prefsCfg[sectionName]
            specSection = self.prefsSpec[sectionName]

            for prefName in specSection:
                if prefName in ['version']:  # any other prefs not to show?
                    continue
                # allowModuleImports pref is handled by generateSpec.py
                # NB if something is in prefs but not in spec then it won't be
                # shown (removes outdated prefs)
                thisPref = prefsSection[prefName]
                thisSpec = specSection[prefName]

                # for keybindings replace Ctrl with Cmd on Mac
                if platform.system() == 'Darwin' and \
                        sectionName == 'keyBindings':
                    if thisSpec.startswith('string'):
                        thisPref = thisPref.replace('Ctrl+', 'Cmd+')

                # can we translate this pref?
                try:
                    pLabel = _localized[prefName]
                except Exception:
                    pLabel = prefName

                # get tooltips from comment lines from the spec, as parsed by
                # configobj
                helpText = ''
                hints = self.prefsSpec[sectionName].comments[
                    prefName]  # a list
                if len(hints):
                    # use only one comment line, from right above the pref
                    hint = hints[-1].lstrip().lstrip('#').lstrip()
                    helpText = _translate(hint)

                if type(thisPref) == bool:
                    # only True or False - use a checkbox
                    self.proPrefs.addBoolItem(sectionName,
                                              pLabel,
                                              prefName,
                                              thisPref,
                                              helpText=helpText)

                # # properties for fonts, dropdown gives a list of system fonts
                elif prefName in ('codeFont', 'commentFont', 'outputFont'):
                    try:
                        default = self.fontList.index(thisPref)
                    except ValueError:
                        default = 0
                    labels = [_translate(font) for font in self.fontList]
                    self.proPrefs.addEnumItem(
                        sectionName,
                        pLabel,
                        prefName,
                        labels=labels,
                        values=[i for i in range(len(self.fontList))],
                        value=default,
                        helpText=helpText)
                elif prefName in ('theme', ):
                    try:
                        default = self.themeList.index(thisPref)
                    except ValueError:
                        default = self.themeList.index("PsychopyLight")
                    self.proPrefs.addEnumItem(
                        sectionName,
                        pLabel,
                        prefName,
                        labels=self.themeList,
                        values=[i for i in range(len(self.themeList))],
                        value=default,
                        helpText=helpText)
                elif prefName == 'locale':
                    thisPref = self.app.prefs.app['locale']
                    # '' corresponds to system locale
                    locales = [''] + self.app.localization.available
                    try:
                        default = locales.index(thisPref)
                    except ValueError:
                        # set default locale ''
                        default = locales.index('')
                    # '' must be appended after other labels are translated
                    labels = [_translate('system locale')] + [
                        _localized[i] for i in self.app.localization.available
                    ]
                    self.proPrefs.addEnumItem(
                        sectionName,
                        pLabel,
                        prefName,
                        labels=labels,
                        values=[i for i in range(len(locales))],
                        value=default,
                        helpText=helpText)
                # # single directory
                elif prefName in ('unpackedDemosDir', ):
                    self.proPrefs.addDirItem(sectionName,
                                             pLabel,
                                             prefName,
                                             thisPref,
                                             helpText=helpText)
                # single file
                elif prefName in (
                        'flac',
                        'appKeyGoogleCloud',
                ):
                    self.proPrefs.addFileItem(sectionName,
                                              pLabel,
                                              prefName,
                                              thisPref,
                                              helpText=helpText)
                # # audio latency mode for the PTB driver
                elif prefName == 'audioLatencyMode':
                    # get the labels from above
                    labels = []
                    for val, labl in audioLatencyLabels.items():
                        labels.append(u'{}: {}'.format(val, labl))

                    # get the options from the config file spec
                    vals = thisSpec.replace("option(", "").replace("'", "")
                    # item -1 is 'default=x' from spec
                    vals = vals.replace(", ", ",").split(',')

                    try:
                        # set the field to the value in the pref
                        default = int(thisPref)
                    except ValueError:
                        try:
                            # use first if default not in list
                            default = int(vals[-1].strip('()').split('=')[1])
                        except (IndexError, TypeError, ValueError):
                            # no default
                            default = 0

                    self.proPrefs.addEnumItem(
                        sectionName,
                        pLabel,
                        prefName,
                        labels=labels,
                        values=[i for i in range(len(labels))],
                        value=default,
                        helpText=helpText)
                # # option items are given a dropdown, current value is shown
                # # in the box
                elif thisSpec.startswith(
                        'option') or prefName == 'audioDevice':
                    if prefName == 'audioDevice':
                        options = self.audioDevNames
                        try:
                            default = self.audioDevNames.index(
                                self.audioDevDefault)
                        except ValueError:
                            default = 0
                    else:
                        vals = thisSpec.replace("option(", "").replace("'", "")
                        # item -1 is 'default=x' from spec
                        vals = vals.replace(", ", ",").split(',')
                        options = vals[:-1]
                        try:
                            # set the field to the value in the pref
                            default = options.index(thisPref)
                        except ValueError:
                            try:
                                # use first if default not in list
                                default = vals[-1].strip('()').split('=')[1]
                            except IndexError:
                                # no default
                                default = 0

                    labels = []  # display only
                    for opt in options:
                        try:
                            labels.append(_localized[opt])
                        except Exception:
                            labels.append(opt)

                    self.proPrefs.addEnumItem(
                        sectionName,
                        pLabel,
                        prefName,
                        labels=labels,
                        values=[i for i in range(len(labels))],
                        value=default,
                        helpText=helpText)
                    if prefName == 'builderLayout':
                        item = self.proPrefs.sections[sectionName][prefName]
                        for i in range(len(item.GetChoices())):
                            choice = item.GetChoices()[i]
                            icon = icons.ButtonIcon(stem=choice.Text).bitmap
                            choice.SetBitmap(icon)
                # # lists are given a property that can edit and reorder items
                elif thisSpec.startswith('list'):  # list
                    self.proPrefs.addStringArrayItem(
                        sectionName, pLabel, prefName,
                        [str(i) for i in thisPref], helpText)
                # integer items
                elif thisSpec.startswith('integer'):  # integer
                    self.proPrefs.addIntegerItem(sectionName, pLabel, prefName,
                                                 thisPref, helpText)
                # # all other items just use a string field
                else:
                    self.proPrefs.addStringItem(sectionName, pLabel, prefName,
                                                thisPref, helpText)

        self.proPrefs.populateGrid()