def __init__(self, parent, name, value, spec): """Create a set of ctrls for a particular preference entry """ super(PrefCtrls, self).__init__() self.pref = value self.parent = parent self.name = name valueWidth = 200 labelWidth = 200 self.nameCtrl = self.valueCtrl = None _style = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL self.nameCtrl = wx.StaticText(self.parent, -1, name, size=(labelWidth, -1), style=_style) if type(value) == bool: # only True or False - use a checkbox self.valueCtrl = wx.CheckBox(self.parent) self.valueCtrl.SetValue(value) elif spec.startswith('option') or name == 'audioDevice': if name == 'audioDevice': options = copy.copy(value) value = value[0] try: from psychopy import sound if hasattr(sound, 'getDevices'): devs = sound.getDevices('output') for thisDevName in devs: if thisDevName not in options: options.append(thisDevName) except DependencyError: pass else: options = spec.replace("option(", "").replace("'", "") # item -1 is 'default=x' from spec options = options.replace(", ", ",").split(',')[:-1] labels = [] # display only for opt in options: try: labels.append(_localized[opt]) except Exception: labels.append(opt) self.valueCtrl = wx.Choice(self.parent, choices=labels) self.valueCtrl._choices = copy.copy(options) # internal values self.valueCtrl.SetSelection(options.index(value)) elif spec.startswith('list'): # list valuestring = self.listToString(value) self.valueCtrl = wx.TextCtrl(self.parent, -1, valuestring, size=(valueWidth, -1)) else: # just use a string self.valueCtrl = wx.TextCtrl(self.parent, -1, str(value), size=(valueWidth, -1))
def __init__(self, parent, name, value, spec): """Create a set of ctrls for a particular preference entry """ super(PrefCtrls, self).__init__() self.pref = value self.parent = parent self.name = name valueWidth = 200 labelWidth = 200 self.nameCtrl = self.valueCtrl = None _style = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL self.nameCtrl = wx.StaticText(self.parent, -1, name, size=(labelWidth, -1), style=_style) if type(value) == bool: # only True or False - use a checkbox self.valueCtrl = wx.CheckBox(self.parent) self.valueCtrl.SetValue(value) elif spec.startswith('option') or name == 'audioDevice': if name == 'audioDevice': options = copy.copy(value) value = value[0] try: from psychopy import sound if hasattr(sound, 'getDevices'): devs = sound.getDevices('output') for thisDevName in devs: if thisDevName not in options: options.append(thisDevName) except (ValueError, OSError): pass else: options = spec.replace("option(", "").replace("'", "") # item -1 is 'default=x' from spec options = options.replace(", ", ",").split(',')[:-1] labels = [] # display only for opt in options: try: labels.append(_localized[opt]) except Exception: labels.append(opt) self.valueCtrl = wx.Choice(self.parent, choices=labels) self.valueCtrl._choices = copy.copy(options) # internal values try: self.valueCtrl.SetSelection(options.index(value)) except: pass elif spec.startswith('list'): # list valuestring = self.listToString(value) self.valueCtrl = wx.TextCtrl(self.parent, -1, valuestring, size=(valueWidth, -1)) else: # just use a string self.valueCtrl = wx.TextCtrl(self.parent, -1, str(value), size=(valueWidth, -1))
def __init__(self, app): wx.Dialog.__init__(self, None, id=wx.ID_ANY, title=_translate('PsychoPy Preferences'), pos=wx.DefaultPosition, size=wx.Size(800, 600), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.app = app self.prefsCfg = self.app.prefs.userPrefsCfg self.prefsSpec = self.app.prefs.prefsSpec self._pages = {} # property grids for each page self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) sbMain = wx.BoxSizer(wx.VERTICAL) self.pnlMain = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) sbPrefs = wx.BoxSizer(wx.VERTICAL) self.proPrefs = PrefPropGrid(self.pnlMain, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LB_DEFAULT) # add property pages to the manager self.proPrefs.addPage('General', 'general', ['general'], 'preferences-general48.png') self.proPrefs.addPage('Application', 'app', ['app', 'builder', 'coder'], 'preferences-app48.png') self.proPrefs.addPage('Key Bindings', 'keyBindings', ['keyBindings'], 'preferences-keyboard48.png') self.proPrefs.addPage('Hardware', 'hardware', ['hardware'], 'preferences-hardware48.png') self.proPrefs.addPage('Connections', 'connections', ['connections'], 'preferences-conn48.png') self.proPrefs.populateGrid() sbPrefs.Add(self.proPrefs, 1, wx.EXPAND) self.stlMain = wx.StaticLine(self.pnlMain, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) sbPrefs.Add(self.stlMain, 0, wx.EXPAND | wx.ALL, 5) # dialog controls, have builtin localization sdbControls = wx.BoxSizer(wx.HORIZONTAL) self.sdbControlsHelp = wx.Button(self.pnlMain, wx.ID_HELP) sdbControls.Add(self.sdbControlsHelp, 0, wx.LEFT | wx.ALL | wx.ALIGN_CENTER_VERTICAL, border=3) sdbControls.AddStretchSpacer() # Add Okay and Cancel buttons self.sdbControlsApply = wx.Button(self.pnlMain, wx.ID_APPLY) self.sdbControlsOK = wx.Button(self.pnlMain, wx.ID_OK) self.sdbControlsCancel = wx.Button(self.pnlMain, wx.ID_CANCEL) if sys.platform == "win32": btns = [ self.sdbControlsOK, self.sdbControlsApply, self.sdbControlsCancel ] else: btns = [ self.sdbControlsCancel, self.sdbControlsApply, self.sdbControlsOK ] sdbControls.Add(btns[0], 0, wx.ALL | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=3) sdbControls.Add(btns[1], 0, wx.ALL | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=3) sdbControls.Add(btns[2], 0, wx.ALL | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, border=3) sbPrefs.Add(sdbControls, flag=wx.ALL | wx.EXPAND, border=3) self.pnlMain.SetSizer(sbPrefs) self.pnlMain.Layout() sbPrefs.Fit(self.pnlMain) sbMain.Add(self.pnlMain, 1, wx.EXPAND | wx.ALL, 8) self.SetSizer(sbMain) self.Layout() self.Centre(wx.BOTH) # Connect Events self.sdbControlsApply.Bind(wx.EVT_BUTTON, self.OnApplyClicked) self.sdbControlsCancel.Bind(wx.EVT_BUTTON, self.OnCancelClicked) self.sdbControlsHelp.Bind(wx.EVT_BUTTON, self.OnHelpClicked) self.sdbControlsOK.Bind(wx.EVT_BUTTON, self.OnOKClicked) # system fonts for font properties self.fontList = ['From theme...'] + list( getSystemFonts(fixedWidthOnly=True)) # valid themes themePath = self.GetTopLevelParent().app.prefs.paths['themes'] self.themeList = [] for themeFile in os.listdir(themePath): try: # Load theme from json file with open(os.path.join(themePath, themeFile), "rb") as fp: theme = json.load(fp) # Add themes to list only if min spec is defined base = theme['base'] if all(key in base for key in ['bg', 'fg', 'font']): self.themeList += [themeFile.replace('.json', '')] except: pass # get sound devices for "audioDevice" property try: devnames = sorted(sound.getDevices('output')) except (ValueError, OSError, ImportError): devnames = [] audioConf = self.prefsCfg['hardware']['audioDevice'] self.audioDevDefault = audioConf \ if type(audioConf) != list else list(audioConf) self.audioDevNames = [ dev.replace('\r\n', '') for dev in devnames if dev != self.audioDevDefault ] self.populatePrefs()
def __init__(self, app): wx.Dialog.__init__( self, None, id=wx.ID_ANY, title=u"PsychoPy Preferences", pos=wx.DefaultPosition, size=wx.Size(800, 600), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) self.app = app self.prefsCfg = self.app.prefs.userPrefsCfg self.prefsSpec = self.app.prefs.prefsSpec self._pages = {} # property grids for each page self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) sbMain = wx.BoxSizer(wx.VERTICAL) self.pnlMain = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) sbPrefs = wx.BoxSizer(wx.VERTICAL) self.proPrefs = PrefPropGrid( self.pnlMain, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LB_DEFAULT) # add property pages to the manager self.proPrefs.addPage( 'General', 'general', ['general'], 'preferences-general48.png') self.proPrefs.addPage( 'Application', 'app', ['app', 'builder', 'coder'], 'preferences-app48.png') self.proPrefs.addPage( 'Key Bindings', 'keyBindings', ['keyBindings'], 'preferences-keyboard48.png') self.proPrefs.addPage( 'Hardware', 'hardware', ['hardware'], 'preferences-hardware48.png') self.proPrefs.addPage( 'Connections', 'connections', ['connections'], 'preferences-conn48.png') self.proPrefs.populateGrid() sbPrefs.Add(self.proPrefs, 1, wx.EXPAND) self.stlMain = wx.StaticLine( self.pnlMain, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) sbPrefs.Add(self.stlMain, 0, wx.EXPAND | wx.ALL, 5) # dialog controls, have builtin localization sdbControls = wx.StdDialogButtonSizer() self.sdbControlsHelp = wx.Button(self.pnlMain, wx.ID_HELP) sdbControls.AddButton(self.sdbControlsHelp) self.sdbControlsApply = wx.Button(self.pnlMain, wx.ID_APPLY) sdbControls.AddButton(self.sdbControlsApply) self.sdbControlsOK = wx.Button(self.pnlMain, wx.ID_OK) sdbControls.AddButton(self.sdbControlsOK) self.sdbControlsCancel = wx.Button(self.pnlMain, wx.ID_CANCEL) sdbControls.AddButton(self.sdbControlsCancel) sdbControls.Realize() sbPrefs.Add(sdbControls, 0, wx.ALL | wx.ALIGN_RIGHT, 0) self.pnlMain.SetSizer(sbPrefs) self.pnlMain.Layout() sbPrefs.Fit(self.pnlMain) sbMain.Add(self.pnlMain, 1, wx.EXPAND | wx.ALL, 8) self.SetSizer(sbMain) self.Layout() self.Centre(wx.BOTH) # Connect Events self.sdbControlsApply.Bind(wx.EVT_BUTTON, self.OnApplyClicked) self.sdbControlsCancel.Bind(wx.EVT_BUTTON, self.OnCancelClicked) self.sdbControlsHelp.Bind(wx.EVT_BUTTON, self.OnHelpClicked) self.sdbControlsOK.Bind(wx.EVT_BUTTON, self.OnOKClicked) # system fonts for font properties self.fontList = list(getSystemFonts(fixedWidthOnly=True)) # get sound devices for "audioDevice" property try: devnames = sorted(sound.getDevices('output')) except (ValueError, OSError, ImportError): devnames = [] audioConf = self.prefsCfg['hardware']['audioDevice'] self.audioDevDefault = audioConf \ if type(audioConf) != list else list(audioConf) self.audioDevNames = [ dev.replace('\r\n', '') for dev in devnames if dev != self.audioDevDefault] self.populatePrefs()
def __init__(self, parent, name, value, spec, plabel): """Create a set of ctrls for a particular preference entry """ super(PrefCtrls, self).__init__() self.pref = value self.parent = parent self.name = name valueWidth = 200 labelWidth = 200 self.nameCtrl = self.valueCtrl = None _style = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL self.nameCtrl = wx.StaticText(self.parent, -1, plabel, size=(labelWidth, -1), style=_style) if type(value) == bool: # only True or False - use a checkbox self.valueCtrl = wx.CheckBox(self.parent) self.valueCtrl.SetValue(value) elif name == '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 options = spec.replace("option(", "").replace("'", "") # item -1 is 'default=x' from spec options = options.replace(", ", ",").split(',')[:-1] self.valueCtrl = wx.Choice(self.parent, choices=labels) self.valueCtrl._choices = copy.copy(options) # internal values self.valueCtrl.SetSelection(options.index(value)) elif spec.startswith('option') or name == 'audioDevice': if name == 'audioDevice': devnames = sorted(sound.getDevices('output')) if type(value) == list: value = value[0] if value in devnames: options = [value] else: options = [] try: # TODO: this assumes that the driver loaded is current selected # we *could* fix that but hopefully PTB will soon dominate and # then we don't need to worry! for device in devnames: # newline characters must be removed thisDevName = device.replace('\r\n', '') if thisDevName not in options: options.append(thisDevName) except (ValueError, OSError, ImportError): pass else: options = spec.replace("option(", "").replace("'", "") # item -1 is 'default=x' from spec options = options.replace(", ", ",").split(',')[:-1] labels = [] # display only for opt in options: try: labels.append(_localized[opt]) except Exception: labels.append(opt) self.valueCtrl = wx.Choice(self.parent, choices=labels) self.valueCtrl._choices = copy.copy(options) # internal values try: self.valueCtrl.SetSelection(0) except: pass elif spec.startswith('list'): # list valuestring = self.listToString(value) self.valueCtrl = wx.TextCtrl(self.parent, -1, valuestring, size=(valueWidth, -1)) else: # just use a string self.valueCtrl = wx.TextCtrl(self.parent, -1, str(value), size=(valueWidth, -1))