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()