コード例 #1
0
 def __init__(self, parent, routine):
     super(SketchpadWindow, self).__init__(parent,
                                           title="Sketchy Pad",
                                           size=(880, 540))
     self.routine = routine
     self._haveShaders = False
     self.winType = "wxglcanvas"
     self.size = (128, 128)
     self.exp = parent.exp
     self.units = self.exp.settings.params["Units"].val
     if self.units == "use prefs":
         self.units = preferences.Preferences().general["units"]
     pygame.font.init()
     self.current_tool = None
     self.canvas = RoutinePreview(
         self, ToolHandler(self.routine, self.GetParent()))
     self.canvas.update_routine(self.routine)
     sizer = wx.BoxSizer(wx.VERTICAL)
     self.workspaceSizer = wx.BoxSizer(wx.HORIZONTAL)
     self.SetSizer(sizer)
     self.init_toolbar()
     #self.side_panel = SidePanel(self)
     sizer.Add(self.toolbar, flag=wx.EXPAND)
     sizer.Add(self.workspaceSizer,
               proportion=1,
               flag=wx.EXPAND | wx.ALL,
               border=8)
     self.workspaceSizer.Add(self.canvas, proportion=3, flag=wx.EXPAND)
     #self.workspaceSizer.Add(self.side_panel, proportion=1, flag=wx.EXPAND)
     sizer.Add(self.CreateButtonSizer(wx.OK),
               flag=wx.EXPAND | wx.ALL,
               border=8)
     self.Bind(wx.EVT_BUTTON, self.onOK, id=wx.ID_OK)
コード例 #2
0
 def __init__(self, prefs=None):
     self.name = None
     self.flow = Flow(exp=self)  #every exp has exactly one flow
     self.routines = {}
     #get prefs (from app if poss or from cfg files)
     if prefs == None:
         prefs = preferences.Preferences()
     #deepCopy doesn't like the full prefs object to be stored, so store each subset
     self.prefsAppDataCfg = prefs.appDataCfg
     self.prefsGeneral = prefs.general
     self.prefsCoder = prefs.coder
     self.prefsBuilder = prefs.builder
     #this can be checked by the builder that this is an experiment and a compatible version
     self.psychopyVersion = psychopy.__version__  #imported from components
     self.psychopyLibs = ['core', 'data', 'event']
     self.settings = getAllComponents()['SettingsComponent'](parentName='',
                                                             exp=self)
     self._doc = None  #this will be the xml.dom.minidom.doc object for saving
     self.namespace = NameSpace(self)  # manage variable names
コード例 #3
0
 def __init__(self):
     prefs = preferences.Preferences()
     splashFile = os.path.join(prefs.paths['resources'],
                               'psychopySplash.png')
     aBitmap = wx.Image(name=splashFile).ConvertToBitmap()
     splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.NO_BORDER
     # Call the constructor with the above arguments in exactly the
     # following order.
     wx.SplashScreen.__init__(self, aBitmap, splashStyle, 0, None)
     #setup statusbar
     self.SetBackgroundColour('WHITE')
     self.status = wx.StaticText(
         self,
         -1,
         "  Loading libraries..." + uidRootFlag,
         wx.Point(0, 250),  #splash image is 640x240
         wx.Size(520, 20),
         wx.ALIGN_LEFT | wx.ALIGN_TOP)
     self.status.SetMinSize(wx.Size(520, 20))
     self.Fit()
     self.Close()
コード例 #4
0
def testGenerateSpec():
    # Get base spec
    base = open(preferences.__folder__ / "baseNoArch.spec").read()
    # Change theme default for use as a marker
    base = re.sub(r"(?<=theme = string\(default=')PsychopyLight(?='\))", "PsychopyDark", base)
    # Generate spec
    preferences.generateSpec(baseSpec=base)
    darwin = open(preferences.__folder__ / "Darwin.spec").read()
    freeBSD = open(preferences.__folder__ / "FreeBSD.spec").read()
    linux = open(preferences.__folder__ / "Linux.spec").read()
    windows = open(preferences.__folder__ / "Windows.spec").read()
    # Check for marker
    assert all("theme = string(default='PsychopyDark')" in target for target in [darwin, freeBSD, linux, windows])
    assert all("theme = string(default='PsychopyLight')" not in target for target in [darwin, freeBSD, linux, windows])
    # Check generated prefs
    prefs = preferences.Preferences()
    prefs.resetPrefs()
    assert prefs.app['theme'] == "PsychopyDark"
    # Check that the app still loads

    app.startApp(testMode=True, showSplash=False)
    app.quitApp()
コード例 #5
0
ファイル: preferencesDlg.py プロジェクト: yoer77/psychopy
                    en = listToString(e, depth - 1) + ','
                else:
                    e = e.replace('\\', '\\\\').replace("'", "\\'")
                    # try str() first because we don't want to append "u" if
                    # unnecessary.
                    try:
                        en = "'" + str(e) + "',"
                    except Exception:  # unicode
                        # "u" is necessary if string is unicode.
                        en = "u'" + unicode(e) + "',"
                l += en
            # remove unnecessary comma
            if l[-1] == ',':
                l = l[:-1]
            l += ']'
        else:
            l = errmsg
        return l


if __name__ == '__main__':
    from psychopy import preferences
    if wx.version() < '2.9':
        app = wx.PySimpleApp()
    else:
        app = wx.App(False)
    # don't do this normally - use the existing psychopy.prefs instance
    app.prefs = preferences.Preferences()
    dlg = PreferencesDlg(app)
    dlg.ShowModal()
コード例 #6
0
    def OnInit(self):
        self.version = psychopy.__version__
        self.SetAppName('PsychoPy2')
        #show splash screen
        splash = PsychoSplashScreen()
        if splash:
            splash.Show()
        #LONG IMPORTS - these need to be imported after splash screen starts (they're slow)
        #but then that they end up being local so keep track in self
        splash.status.SetLabel("  Loading PsychoPy2..." + uidRootFlag)
        from psychopy.monitors import MonitorCenter
        from psychopy.app import coder, builder, wxIDs, connections, urls
        #set default paths and prefs
        self.prefs = preferences.Preferences()  #from preferences.py
        if self.prefs.app['debugMode']:
            log.console.setLevel(log.DEBUG)
        self.keys = self.prefs.keys
        self.prefs.pageCurrent = 0  # track last-viewed page of prefs, to return there
        self.IDs = wxIDs
        self.urls = urls.urls
        self.quitting = False
        self.updater = None  #create an updater when it's needed
        #setup links for URLs
        #on a mac, don't exit when the last frame is deleted, just show a menu
        if sys.platform == 'darwin':
            self.menuFrame = MenuFrame(parent=None, app=self)
        #get preferred view(s) from prefs and previous view
        if self.prefs.app['defaultView'] == 'last':
            mainFrame = self.prefs.appData['lastFrame']
        else:
            # configobjValidate should take care of this situation (?), but doesn't:
            if self.prefs.app['defaultView'] in [
                    'last', 'coder', 'builder', 'both'
            ]:
                mainFrame = self.prefs.app['defaultView']
            else:
                self.prefs.app['defaultView'] = 'both'
                mainFrame = 'both'
        #fetch prev files if that's the preference
        if self.prefs.coder['reloadPrevFiles']:
            scripts = self.prefs.appData['coder']['prevFiles']
        else:
            scripts = []
        if self.prefs.builder['reloadPrevExp'] and (
                'prevFiles' in self.prefs.appData['builder'].keys()):
            exps = self.prefs.appData['builder']['prevFiles']
        else:
            exps = []
        #then override the prev files by command options and passed files
        if len(sys.argv) > 1:
            if sys.argv[1] == __name__:
                args = sys.argv[
                    2:]  # program was excecuted as "python.exe PsychoPyIDE.py %1'
            else:
                args = sys.argv[
                    1:]  # program was excecuted as "PsychoPyIDE.py %1'
            #choose which frame to start with
            if args[0] in ['builder', '--builder', '-b']:
                mainFrame = 'builder'
                args = args[1:]  #can remove that argument
            elif args[0] in ['coder', '--coder', '-c']:
                mainFrame = 'coder'
                args = args[1:]  #can remove that argument
            #did we get .py or .psyexp files?
            elif args[0][-7:] == '.psyexp':
                mainFrame = 'builder'
                exps = [args[0]]
            elif args[0][-3:] == '.py':
                mainFrame = 'coder'
                scripts = [args[0]]
        else:
            args = []

        self.dpi = int(wx.GetDisplaySize()[0] /
                       float(wx.GetDisplaySizeMM()[0]) * 25.4)
        if not (50 < self.dpi < 120):
            self.dpi = 80  #dpi was unreasonable, make one up

        #create both frame for coder/builder as necess
        self.coder = None
        self.builderFrames = []
        self.copiedRoutine = None
        self.allFrames = [
        ]  #these are ordered and the order is updated with self.onNewTopWindow
        if mainFrame in ['both', 'coder']: self.showCoder(fileList=scripts)
        if mainFrame in ['both', 'builder']: self.showBuilder(fileList=exps)

        #send anonymous info to www.psychopy.org/usage.php
        #please don't disable this - it's important for PsychoPy's development
        if self.prefs.connections['allowUsageStats']:
            statsThread = threading.Thread(
                target=connections.sendUsageStats,
                args=(self.prefs.connections['proxy'], ))
            statsThread.start()
        if self.prefs.connections['checkForUpdates']:
            self.updater = connections.Updater(
                app=self, proxy=self.prefs.connections['proxy'])
            self.updater.suggestUpdate(
                confirmationDlg=False)  #check for updates (silently)
        else:
            self.updater = False
        """This is in wx demo. Probably useful one day.
        #---------------------------------------------
        def ShowTip(self):
            config = GetConfig()
            showTipText = config.Read("tips")
            if showTipText:
                showTip, index = eval(showTipText)
            else:
                showTip, index = (1, 0)

            if showTip:
                tp = wx.CreateFileTipProvider(opj("data/tips.txt"), index)
                ##tp = MyTP(0)
                showTip = wx.ShowTip(self, tp)
                index = tp.GetCurrentTip()
                config.Write("tips", str( (showTip, index) ))
                config.Flush()"""

        return True
コード例 #7
0
                if hasattr(e, '__iter__'):
                    en = listToString(e, depth - 1) + ','
                else:
                    e = e.replace('\\', '\\\\').replace("'", "\\'")
                    # try str() first because we don't want to append "u" if unnecessary.
                    try:
                        en = "'" + str(e) + "',"
                    except:  # unicode
                        # "u" is necessary if string is unicode.
                        en = "u'" + unicode(e) + "',"
                l += en
            # remove unnecessary comma
            if l[-1] == ',':
                l = l[:-1]
            l += ']'
        else:
            l = errmsg
        return l


if __name__ == '__main__':
    from psychopy import preferences
    if wx.version() < '2.9':
        app = wx.PySimpleApp()
    else:
        app = wx.App(False)
    app.prefs = preferences.Preferences(
    )  #don't do this normally - use the existing psychopy.prefs instance
    dlg = PreferencesDlg(app)
    dlg.ShowModal()
コード例 #8
0
    def onInit(self, showSplash=True):
        self.version = psychopy.__version__
        self.SetAppName('PsychoPy2')
        #set default paths and prefs
        self.prefs = preferences.Preferences()  #from preferences.py
        if self.prefs.app['debugMode']:
            logging.console.setLevel(logging.DEBUG)

        if showSplash:
            #show splash screen
            splashFile = os.path.join(self.prefs.paths['resources'],
                                      'psychopySplash.png')
            splashBitmap = wx.Image(name=splashFile).ConvertToBitmap()
            splash = AS.AdvancedSplash(
                None, bitmap=splashBitmap, timeout=2000, shadowcolour=wx.RED
            )  #could use this in future for transparency
            splash.SetTextPosition((10, 240))
            splash.SetText("  Loading libraries..." + uidRootFlag)
        else:
            splash = None

        #LONG IMPORTS - these need to be imported after splash screen starts (they're slow)
        #but then that they end up being local so keep track in self
        if splash: splash.SetText("  Loading PsychoPy2..." + uidRootFlag)
        from psychopy import compatibility
        from psychopy.app import coder, builder, dialogs, wxIDs, urls  #import coder and builder here but only use them later
        self.keys = self.prefs.keys
        self.prefs.pageCurrent = 0  # track last-viewed page of prefs, to return there
        self.IDs = wxIDs
        self.urls = urls.urls
        self.quitting = False
        #check compatibility with last run version (before opening windows)
        self.firstRun = False
        if '--firstrun' in sys.argv:
            del sys.argv[sys.argv.index('--firstrun')]
            self.firstRun = True
        if 'lastVersion' not in self.prefs.appData.keys():
            last = self.prefs.appData[
                'lastVersion'] = '1.73.04'  #must be before 1.74.00
            self.firstRun = True
        else:
            last = self.prefs.appData['lastVersion']
        if self.firstRun:
            self.configWizard(firstrun=True)

        #setup links for URLs
        #on a mac, don't exit when the last frame is deleted, just show a menu
        if sys.platform == 'darwin':
            self.menuFrame = MenuFrame(parent=None, app=self)
        #get preferred view(s) from prefs and previous view
        if self.prefs.app['defaultView'] == 'last':
            mainFrame = self.prefs.appData['lastFrame']
        else:
            # configobjValidate should take care of this situation (?), but doesn't:
            if self.prefs.app['defaultView'] in [
                    'last', 'coder', 'builder', 'both'
            ]:
                mainFrame = self.prefs.app['defaultView']
            else:
                self.prefs.app['defaultView'] = 'both'
                mainFrame = 'both'
        #fetch prev files if that's the preference
        if self.prefs.coder['reloadPrevFiles']:
            scripts = self.prefs.appData['coder']['prevFiles']
        else:
            scripts = []
        if self.prefs.builder['reloadPrevExp'] and (
                'prevFiles' in self.prefs.appData['builder'].keys()):
            exps = self.prefs.appData['builder']['prevFiles']
        else:
            exps = []
        #then override the prev files by command options and passed files
        if len(sys.argv) > 1:
            if sys.argv[1] == __name__:
                args = sys.argv[
                    2:]  # program was excecuted as "python.exe PsychoPyIDE.py %1'
            else:
                args = sys.argv[
                    1:]  # program was excecuted as "PsychoPyIDE.py %1'
            #choose which frame to start with
            if args[0] in ['builder', '--builder', '-b']:
                mainFrame = 'builder'
                args = args[1:]  #can remove that argument
            elif args[0] in ['coder', '--coder', '-c']:
                mainFrame = 'coder'
                args = args[1:]  #can remove that argument
            #did we get .py or .psyexp files?
            elif args[0][-7:] == '.psyexp':
                mainFrame = 'builder'
                exps = [args[0]]
            elif args[0][-3:] == '.py':
                mainFrame = 'coder'
                scripts = [args[0]]
        else:
            args = []

        self.dpi = int(wx.GetDisplaySize()[0] /
                       float(wx.GetDisplaySizeMM()[0]) * 25.4)
        if not (50 < self.dpi < 120):
            self.dpi = 80  #dpi was unreasonable, make one up

        #create both frame for coder/builder as necess
        if splash: splash.SetText("  Creating frames..." + uidRootFlag)
        self.coder = None
        self.builderFrames = []
        self.copiedRoutine = None
        self.allFrames = [
        ]  #these are ordered and the order is updated with self.onNewTopWindow
        if mainFrame in ['both', 'coder']: self.showCoder(fileList=scripts)
        if mainFrame in ['both', 'builder']: self.showBuilder(fileList=exps)

        #send anonymous info to www.psychopy.org/usage.php
        #please don't disable this - it's important for PsychoPy's development
        self._latestAvailableVersion = None
        self.updater = None
        if self.prefs.connections['checkForUpdates'] or self.prefs.connections[
                'allowUsageStats']:
            connectThread = threading.Thread(
                target=connections.makeConnections, args=(self, ))
            connectThread.start()

        ok, msg = compatibility.checkCompatibility(last,
                                                   self.version,
                                                   self.prefs,
                                                   fix=True)
        if not ok and not self.firstRun:  #tell the user what has changed
            dlg = dialogs.MessageDialog(parent=None,
                                        message=msg,
                                        type='Info',
                                        title="Compatibility information")
            dlg.ShowModal()

        if self.prefs.app['showStartupTips']:
            tipIndex = self.prefs.appData['tipIndex']
            tp = wx.CreateFileTipProvider(
                os.path.join(self.prefs.paths['resources'], "tips.txt"),
                tipIndex)
            showTip = wx.ShowTip(None, tp)
            self.prefs.appData['tipIndex'] = tp.GetCurrentTip()
            self.prefs.saveAppData()
            self.prefs.app['showStartupTips'] = showTip
            self.prefs.saveUserPrefs()
        if self.prefs.connections['checkForUpdates']:
            self.Bind(wx.EVT_IDLE, self.checkUpdates)
        else:
            self.Bind(wx.EVT_IDLE, self.onIdle)
        return True