def __init__(self, parent): wx.Menu.__init__(self) self.parent = parent self.app = parent.app self.itemFrames = {} # Listen for window switch self.next = self.Append(wx.ID_MDI_WINDOW_NEXT, _translate("&Next Window\t%s") % self.app.keys['cycleWindows'], _translate("&Next Window\t%s") % self.app.keys['cycleWindows']) self.Bind(wx.EVT_MENU, self.nextWindow, self.next) self.AppendSeparator() # Add creator options self.minItemSpec = [ {'label': "Builder", 'class': psychopy.app.builder.BuilderFrame, 'method': self.app.showBuilder}, {'label': "Coder", 'class': psychopy.app.coder.CoderFrame, 'method': self.app.showCoder}, {'label': "Runner", 'class': psychopy.app.runner.RunnerFrame, 'method': self.app.showRunner}, ] for spec in self.minItemSpec: if not isinstance(self.Window, spec['class']): item = self.Append( wx.ID_ANY, spec['label'], spec['label'] ) self.Bind(wx.EVT_MENU, spec['method'], item) self.AppendSeparator() self.updateFrames()
def __init__(self, parent, project): wx.Dialog.__init__(self, parent, title=_translate("Syncing project...")) self.project = project # Setup sizer self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) # Create status panel self.status = InfoStream(self, id=wx.ID_ANY, size=(-1, -1), value=_translate("Synchronising..."), style=wx.TE_READONLY | wx.TE_MULTILINE) self.sizer.Add(self.status, border=6, proportion=1, flag=wx.ALL | wx.EXPAND) # Setup button sizer self.btnSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.btnSizer, border=6, flag=wx.ALL | wx.EXPAND) self.btnSizer.AddStretchSpacer(1) # Add buttons self.OKbtn = wx.Button(self, label=_translate("OK"), id=wx.ID_OK) self.OKbtn.Disable() self.btnSizer.Add(self.OKbtn, border=3, flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL) # Layout self.Layout() self.Show()
def AddPsychopyTool(self, fName, label, shortcut, tooltip, func): # Load in graphic resource rc = self.frame.app.prefs.paths['resources'] if isinstance(fName, str): # If one stimulus is supplied, read bitmap bmp = wx.Bitmap(os.path.join(rc, fName + '%i.png' % self.iconSize), wx.BITMAP_TYPE_PNG) elif isinstance(fName, tuple) and len(fName) == 2: # If two are supplied, create combined bitmap bmp = combineImageEmblem(os.path.join( rc, fName[0] + '%i.png' % self.iconSize), os.path.join(rc, fName[1] + '16.png'), pos='bottom_right') else: return # Create tool object if 'phoenix' in wx.PlatformInfo: item = self.AddTool( wx.ID_ANY, _translate(label + " [%s]") % self.keys[shortcut], bmp, _translate(tooltip)) else: item = self.AddSimpleTool( wx.ID_ANY, bmp, _translate(label + " [%s]") % self.keys[shortcut], _translate(tooltip)) # Bind function self.Bind(wx.EVT_TOOL, func, item) return item
def __init__(self, coder): msg = _translate('PyShell in PsychoPy - type some commands!') wx.py.shell.Shell.__init__(self, coder.shelf, -1, introText=msg + '\n\n', style=wx.BORDER_NONE) self.prefs = coder.prefs self.paths = coder.paths self.app = coder.app # Set theme to match code editor self.theme = self.prefs['theme']
def Update(self): """Set items according to which windows are open""" for item in self.GetMenuItems(): self.DestroyItem(item) # Determine whether to show standard buttons based on open state showBuilder = not any( isinstance(frame, psychopy.app.builder.BuilderFrame) and hasattr(frame, 'filename') for frame in self.parent.app.getAllFrames()) showCoder = not any( isinstance(frame, psychopy.app.coder.CoderFrame) and hasattr(frame, 'filename') for frame in self.parent.app.getAllFrames()) showRunner = not any( isinstance(frame, psychopy.app.runner.RunnerFrame) and hasattr(frame, 'filename') for frame in self.parent.app.getAllFrames()) # Add standard buttons if showBuilder and not isinstance(self.parent, psychopy.app.builder.BuilderFrame): self.builderBtn = self.Append(wx.ID_ANY, _translate("Builder"), _translate("Builder View")) self.Bind(wx.EVT_MENU, self.parent.app.showBuilder, self.builderBtn) if showCoder and not isinstance(self.parent, psychopy.app.coder.CoderFrame): self.coderBtn = self.Append(wx.ID_ANY, _translate("Coder"), _translate("Coder View")) self.Bind(wx.EVT_MENU, self.parent.app.showCoder, self.coderBtn) if showRunner and not isinstance(self.parent, psychopy.app.runner.RunnerFrame): self.runnerBtn = self.Append(wx.ID_ANY, _translate("Runner"), _translate("Runner View")) self.Bind(wx.EVT_MENU, self.parent.app.showRunner, self.runnerBtn) # Make buttons for each open file for frame in self.frames: if hasattr(frame, "filename") and frame != self.parent: if frame.filename: label = type(frame).__name__.replace( "Frame", "") + ": " + os.path.basename(frame.filename) else: label = type(frame).__name__.replace("Frame", "") item = self.Append(wx.ID_ANY, _translate(label), _translate(label)) self.itemFrames[item.GetId()] = frame self.Bind(wx.EVT_MENU, self.showFrame, item)
def addPsychopyTool(self, name, label, shortcut, tooltip, func, emblem=None): if not name.endswith('.png'): name += '.png' item = self.app.iconCache.makeBitmapButton(parent=self, filename=name, name=label, label=_translate( label + " [%s]") % self.keys[shortcut], emblem=emblem, toolbar=self, tip=tooltip, size=self.iconSize) # Bind function self.Bind(wx.EVT_TOOL, func, item) return item
def __init__(self, parent, user, name="", path=""): wx.Dialog.__init__(self, parent=parent, title=_translate("New project..."), size=(500, 200), style=wx.DEFAULT_DIALOG_STYLE | wx.CLOSE_BOX) # If there's no user yet, login if user is None: user = functions.logInPavlovia(self) self.user = user self.session = parent.session self.project = None # Setup sizer self.frame = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.frame) self.sizer = wx.BoxSizer(wx.VERTICAL) self.frame.Add(self.sizer, border=6, proportion=1, flag=wx.ALL | wx.EXPAND) # Name label self.nameLbl = wx.StaticText(self, label=_translate("Project name:")) self.sizer.Add(self.nameLbl, border=3, flag=wx.ALL | wx.EXPAND) # Name ctrls self.nameSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.nameSizer, border=3, flag=wx.ALL | wx.EXPAND) # URL prefix self.nameRootLbl = wx.StaticText(self, label="pavlovia.org /") self.nameSizer.Add(self.nameRootLbl, border=3, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) # Namespace ctrl self.namespaceCtrl = wx.Choice( self, choices=[user['username']] + user.session.listUserGroups(namesOnly=True)) self.namespaceCtrl.SetStringSelection(user['username']) self.nameSizer.Add(self.namespaceCtrl, border=3, flag=wx.ALL | wx.EXPAND) # Slash self.slashLbl = wx.StaticText(self, label="/") self.nameSizer.Add(self.slashLbl, border=3, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) # Name ctrl self.nameCtrl = wx.TextCtrl(self, value=str(name)) self.nameCtrl.Bind(wx.EVT_TEXT, self.validate) self.nameSizer.Add(self.nameCtrl, border=3, proportion=1, flag=wx.ALL | wx.EXPAND) # Local root label self.rootLbl = wx.StaticText(self, label=_translate("Project folder:")) self.sizer.Add(self.rootLbl, border=3, flag=wx.ALL | wx.EXPAND) # Local root ctrl self.rootCtrl = utils.FileCtrl(self, value=str(path), dlgtype="dir") self.rootCtrl.Bind(wx.EVT_FILEPICKER_CHANGED, self.validate) self.sizer.Add(self.rootCtrl, border=3, flag=wx.ALL | wx.EXPAND) # Add dlg buttons self.sizer.AddStretchSpacer(1) self.btnSizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.btnSizer, border=3, flag=wx.ALL | wx.EXPAND) self.btnSizer.AddStretchSpacer(1) # OK button self.OKbtn = wx.Button(self, id=wx.ID_OK, label=_translate("OK")) self.OKbtn.Bind(wx.EVT_BUTTON, self.submit) # CANCEL button self.CANCELbtn = wx.Button(self, id=wx.ID_CANCEL, label=_translate("Cancel")) # Add dlg buttons in OS appropriate order if sys.platform == "win32": btns = [self.OKbtn, self.CANCELbtn] else: btns = [self.CANCELbtn, self.OKbtn] self.btnSizer.Add(btns[0], border=3, flag=wx.ALL) self.btnSizer.Add(btns[1], border=3, flag=wx.ALL) self.Layout() self.validate()
def makeTools(self): frame = self.frame # Create tools cl = frame.__class__.__name__ pavButtons = pavlovia_ui.toolbar.PavloviaButtons(frame, toolbar=self, tbSize=self.iconSize) if frame.__class__.__name__ == 'BuilderFrame': self.addPsychopyTool( name='filenew', label=_translate('New'), shortcut='new', tooltip=_translate("Create new experiment file"), func=self.frame.app.newBuilderFrame) # New self.addPsychopyTool( name='fileopen', label=_translate('Open'), shortcut='open', tooltip=_translate("Open an existing experiment file"), func=self.frame.fileOpen) # Open self.frame.bldrBtnSave = self.addPsychopyTool( name='filesave', label=_translate('Save'), shortcut='save', tooltip=_translate("Save current experiment file"), func=self.frame.fileSave) # Save self.addPsychopyTool( name='filesaveas', label=_translate('Save As...'), shortcut='saveAs', tooltip=_translate("Save current experiment file as..."), func=self.frame.fileSaveAs) # SaveAs self.frame.bldrBtnUndo = self.addPsychopyTool( name='undo', label=_translate('Undo'), shortcut='undo', tooltip=_translate("Undo last action"), func=self.frame.undo) # Undo self.frame.bldrBtnRedo = self.addPsychopyTool( name='redo', label=_translate('Redo'), shortcut='redo', tooltip=_translate("Redo last action"), func=self.frame.redo) # Redo self.AddSeparator() # Seperator self.addPsychopyTool( name='monitors', label=_translate('Monitor Center'), shortcut='none', tooltip=_translate("Monitor settings and calibration"), func=self.frame.app.openMonitorCenter) # Monitor Center self.addPsychopyTool( name='cogwindow', label=_translate('Experiment Settings'), shortcut='none', tooltip=_translate("Edit experiment settings"), func=self.frame.setExperimentSettings) # Settings self.AddSeparator() self.addPsychopyTool(name='compile', label=_translate('Compile Script'), shortcut='compileScript', tooltip=_translate("Compile to script"), func=self.frame.compileScript) # Compile self.frame.bldrBtnRunner = self.addPsychopyTool( name='runner', label=_translate('Runner'), shortcut='runnerScript', tooltip=_translate("Send experiment to Runner"), func=self.frame.runFile) # Run self.frame.bldrBtnRun = self.addPsychopyTool( name='run', label=_translate('Run'), shortcut='runScript', tooltip=_translate("Run experiment"), func=self.frame.runFile) # Run self.AddSeparator() # Seperator pavButtons.addPavloviaTools() elif frame.__class__.__name__ == 'CoderFrame': self.addPsychopyTool('filenew', 'New', 'new', "Create new experiment file", self.frame.fileNew) # New self.addPsychopyTool('fileopen', 'Open', 'open', "Open an existing experiment file", self.frame.fileOpen) # Open self.frame.cdrBtnSave = \ self.addPsychopyTool('filesave', 'Save', 'save', "Save current experiment file", self.frame.fileSave) # Save self.addPsychopyTool('filesaveas', 'Save As...', 'saveAs', "Save current experiment file as...", self.frame.fileSaveAs) # SaveAs self.frame.cdrBtnUndo = \ self.addPsychopyTool('undo', 'Undo', 'undo', "Undo last action", self.frame.undo) # Undo self.frame.cdrBtnRedo = \ self.addPsychopyTool('redo', 'Redo', 'redo', "Redo last action", self.frame.redo) # Redo self.AddSeparator() # Seperator self.addPsychopyTool('monitors', 'Monitor Center', 'none', "Monitor settings and calibration", self.frame.app.openMonitorCenter) self.addPsychopyTool('color', 'Color Picker', 'none', "Color Picker -> clipboard", self.frame.app.colorPicker) self.AddSeparator() self.frame.cdrBtnRunner = self.addPsychopyTool( 'runner', 'Runner', 'runnerScript', "Send experiment to Runner", self.frame.runFile) self.frame.cdrBtnRun = self.addPsychopyTool( 'run', 'Run', 'runScript', "Run experiment", self.frame.runFile) self.AddSeparator() pavButtons.addPavloviaTools( buttons=['pavloviaSync', 'pavloviaSearch', 'pavloviaUser']) frame.btnHandles.update(pavButtons.btnHandles) self.Realize()