Example #1
0
    def _apply(self):
        """
		desc:
			Confirms and applies the script changes.
		"""

        resp = QtGui.QMessageBox.question(
            self.main_window, _(u'Apply?'),
            _(u'Are you sure you want to apply the changes to the general script?'
              ), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
        if resp == QtGui.QMessageBox.No:
            return
        try:
            exp = experiment(self.main_window,
                             name=self.experiment.title,
                             string=self.ui.qprogedit.text(),
                             pool_folder=self.experiment.pool_folder,
                             experiment_path=self.experiment.experiment_path,
                             resources=self.experiment.resources)
        except osexception as e:
            self.notify(e.html())
            self.main_window.print_debug_window(e)
            return
        self.main_window.experiment = exp
        self.main_window.tabwidget.close_all()
        self.main_window.tabwidget.open_general()
        self.experiment.build_item_tree()
        self.extension_manager.fire(u'regenerate')
	def _apply(self):

		"""
		desc:
			Confirms and applies the script changes.
		"""

		resp = QtGui.QMessageBox.question(self.main_window, _(u'Apply?'),
			_(u'Are you sure you want to apply the changes to the general script?'),
			QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
		if resp == QtGui.QMessageBox.No:
			return
		try:
			exp = experiment(self.main_window, name=self.experiment.title,
				string=self.ui.qprogedit.text(),
				pool_folder=self.experiment.pool_folder,
				experiment_path=self.experiment.experiment_path,
				resources=self.experiment.resources)
		except osexception as e:
			self.notify(e.html())
			self.main_window.print_debug_window(e)
			return
		self.main_window.experiment = exp
		self.main_window.tabwidget.close_all()
		self.main_window.tabwidget.open_general()
		self.experiment.build_item_tree()
		self.extension_manager.fire(u'regenerate')
Example #3
0
	def regenerate(self, script):

		"""
		desc:
			Regenerates the current experiment from script, and updates the GUI.

		argument:
			script:
				desc:	The new experiment script.
				type:	str
		"""

		try:
			exp = experiment.experiment(self, name=self.experiment.var.title,
				string=script, pool_folder=self.experiment.pool.folder(),
				experiment_path=self.experiment.experiment_path,
				resources=self.experiment.resources)
		except osexception as e:
			md = _(u'# Parsing error\n\nFailed to parse the script for the '
				u'following reason:\n\n- ') + e.markdown()
			self.tabwidget.open_markdown(md)
			self.console.write(e)
			return
		self.extension_manager.fire(u'prepare_regenerate')
		self.experiment = exp
		self.tabwidget.close_all()
		self.experiment.build_item_tree()
		self.extension_manager.fire(u'regenerate')
Example #4
0
	def regenerate(self, script):
	
		"""
		Handles a full regeneration of the experiment.
		
		Arguments:
		script 			--	A definition Unicode string / QString.
		"""
				
		self.main_window.set_busy(True)		
		script = self.main_window.experiment.unistr(script)
		try:
			# Generate the new experiment
			tmp = experiment.experiment(self.main_window, \
				self.main_window.experiment.title, script, \
				self.main_window.experiment.pool_folder)
		except Exception as error:		
			# If something is wrong with the script, notify the user and print
			# a traceback to the debug window
			self.main_window.experiment.notify( \
				_('Failed to parse script (see traceback in debug window): %s') \
				% error)
			self.main_window.print_debug_window(error)
			return
		# Apply the new experiment
		self.main_window.experiment = tmp
		self.main_window.experiment.build_item_tree()			
		self.main_window.ui.tabwidget.close_all()
		self.main_window.ui.tabwidget.open_general_script()
		self.main_window.set_busy(False)
		self.main_window.set_unsaved()	
Example #5
0
	def regenerate(self, script):
	
		"""
		Handles a full regeneration of the experiment
		
		Arguments:
		script -- a definition string (unicode/ QString)
		"""
				
		self.main_window.set_busy(True)		
		script = self.main_window.experiment.unistr(script)
		try:
			# Generate the new experiment
			tmp = experiment.experiment(self.main_window, \
				self.main_window.experiment.title, script, \
				self.main_window.experiment.pool_folder)
		except libopensesame.exceptions.script_error as error:		
			# If something is wrong with the script, notify the user
			self.main_window.experiment.notify(_("Could not parse script: %s") \
				% error)
			return
		# Apply the new experiment
		self.main_window.experiment = tmp
		self.main_window.experiment.build_item_tree()			
		self.main_window.ui.tabwidget.close_all()
		self.main_window.ui.tabwidget.open_general_script()
		self.main_window.set_busy(False)
		self.main_window.set_unsaved()	
Example #6
0
    def regenerate(self, script):
        """
		desc:
			Regenerates the current experiment from script, and updates the GUI.

		argument:
			script:
				desc:	The new experiment script.
				type:	str
		"""

        try:
            exp = experiment.experiment(
                self,
                name=self.experiment.var.title,
                string=script,
                pool_folder=self.experiment.pool.folder(),
                experiment_path=self.experiment.experiment_path,
                resources=self.experiment.resources)
        except osexception as e:
            md = _(u'# Parsing error\n\nFailed to parse the script for the '
                   u'following reason:\n\n- ') + e.markdown()
            self.tabwidget.open_markdown(md)
            self.console.write(e)
            return
        self.extension_manager.fire(u'prepare_regenerate')
        self.experiment = exp
        self.tabwidget.close_all()
        self.experiment.build_item_tree()
        self.extension_manager.fire(u'regenerate')
Example #7
0
    def regenerate(self, script):
        """
		Handles a full regeneration of the experiment.
		
		Arguments:
		script 			--	A definition Unicode string / QString.
		"""

        self.main_window.set_busy(True)
        script = self.main_window.experiment.unistr(script)
        try:
            # Generate the new experiment
            tmp = experiment.experiment(self.main_window, \
             self.main_window.experiment.title, script, \
             self.main_window.experiment.pool_folder)
        except Exception as error:
            # If something is wrong with the script, notify the user and print
            # a traceback to the debug window
            self.main_window.experiment.notify( \
             _(u'Failed to parse script (see traceback in debug window): %s') \
             % error)
            self.main_window.print_debug_window(error)
            return
        # Apply the new experiment
        self.main_window.experiment = tmp
        self.main_window.experiment.build_item_tree()
        self.main_window.ui.tabwidget.close_all()
        self.main_window.ui.tabwidget.open_general_script()
        self.main_window.set_busy(False)
        self.main_window.set_unsaved()
Example #8
0
    def open_file(self, dummy=None, path=None, add_to_recent=True):
        """
		Open a .opensesame or .opensesame.tar.gz file

		Keyword arguments:
		dummy -- An unused argument which is passed by the signal (default=None)
		path -- The path to the file. If None, a file dialog is presented
				(default=None)
		"""

        if not self.save_unsaved_changes():
            self.ui.tabwidget.open_general()
            return
        if path == None:
            path = unicode(
                QtGui.QFileDialog.getOpenFileName(
                    self.ui.centralwidget,
                    _(u"Open file"),
                    filter=self.file_type_filter,
                    directory=cfg.file_dialog_path))
        if path == None or path == u'' or (
                not path.lower().endswith(u'.opensesame')
                and not path.lower().endswith(u'.opensesame.tar.gz')):
            return
        self.set_status(u"Opening ...", status=u'busy')
        self.ui.tabwidget.close_all()
        cfg.file_dialog_path = os.path.dirname(path)
        try:
            exp = experiment.experiment(self,
                                        u"Experiment",
                                        path,
                                        experiment_path=os.path.dirname(path))
        except Exception as e:
            if not isinstance(e, osexception):
                e = osexception(msg=u'Failed to open file', exception=e)
            self.print_debug_window(e)
            self.experiment.notify(e.html(), title=u'Exception')
            return
        libopensesame.experiment.clean_up(verbose=debug.enabled,
                                          keep=[exp.pool_folder])
        self.experiment = exp
        self.experiment.build_item_tree()
        self.ui.tabwidget.open_general()
        if add_to_recent:
            self.current_path = path
            self.window_message(self.current_path)
            self.update_recent_files()
            cfg.default_logfile_folder = os.path.dirname(self.current_path)
        else:
            self.window_message(u"New experiment")
            self.current_path = None
        self.set_auto_response()
        self.set_unsaved(False)
        self.ui.pool_widget.refresh()
        self.ui.variable_inspector.refresh()
        self.extension_manager.fire(u'open_experiment', path=path)
        self.set_status(u"Opened %s" % path)
Example #9
0
	def open_file(self, dummy=None, path=None, add_to_recent=True):

		"""
		Open a .opensesame or .opensesame.tar.gz file

		Keyword arguments:
		dummy -- An unused argument which is passed by the signal (default=None)
		path -- The path to the file. If None, a file dialog is presented
				(default=None)
		"""

		if not self.save_unsaved_changes():
			self.ui.tabwidget.open_general()
			return
		if path == None:
			path = unicode(QtGui.QFileDialog.getOpenFileName(
				self.ui.centralwidget, _(u"Open file"),
				filter=self.file_type_filter, directory=cfg.file_dialog_path))
		if path == None or path == u'' or (not path.lower().endswith(
			u'.opensesame') and not path.lower().endswith(
			u'.opensesame.tar.gz')):
			return
		self.set_status(u"Opening ...", status=u'busy')
		self.ui.tabwidget.close_all()
		cfg.file_dialog_path = os.path.dirname(path)
		try:
			exp = experiment.experiment(self, u"Experiment", path,
				experiment_path=os.path.dirname(path))
		except Exception as e:
			if not isinstance(e, osexception):
				e = osexception(msg=u'Failed to open file', exception=e)
			self.print_debug_window(e)
			self.experiment.notify(e.html(), title=u'Exception')
			return
		libopensesame.experiment.clean_up(verbose=debug.enabled,
			keep=[exp.pool_folder])
		self.experiment = exp
		self.experiment.build_item_tree()
		self.ui.tabwidget.open_general()
		if add_to_recent:
			self.current_path = path
			self.window_message(self.current_path)
			self.update_recent_files()
			cfg.default_logfile_folder = os.path.dirname(self.current_path)
		else:
			self.window_message(u"New experiment")
			self.current_path = None
		self.set_auto_response()
		self.set_unsaved(False)
		self.refresh_pool()
		self.refresh_variable_inspector()
		self.extension_manager.fire(u'open_experiment', path=path)
		self.set_status(u"Opened %s" % path)
Example #10
0
    def update_resolution(self, width, height):
        """
		desc:
			Updates the resolution in a way that preserves display centering.
			This is kind of a quick hack. First generate the script, change the
			resolution in the script and then re-parse the script.

		arguments:
			width:		The display width in pixels.
			height:		The display height in pixels.
		"""

        debug.msg(u"changing resolution to %d x %d" % (width, height))
        try:
            script = self.experiment.to_string()
        except Exception as e:
            if not isinstance(e, osexception):
                e = osexception(u'Failed to change the display resolution',
                                exception=e)
            md = _(u'# Error\n\nFailed to change display resolution for the '
                   u'following reason:\n\n- ') + e.markdown()
            self.tabwidget.open_markdown(md)
            return
        old_cmd = self.experiment.syntax.create_cmd(
            u'set', [u'height', self.experiment.var.height])
        new_cmd = self.experiment.syntax.create_cmd(u'set',
                                                    [u'height', height])
        script = script.replace(old_cmd, new_cmd)
        old_cmd = self.experiment.syntax.create_cmd(
            u'set', [u'width', self.experiment.var.width])
        new_cmd = self.experiment.syntax.create_cmd(u'set', [u'width', width])
        script = script.replace(old_cmd, new_cmd)
        try:
            tmp = experiment.experiment(
                self,
                name=self.experiment.var.title,
                string=script,
                pool_folder=self.experiment.pool.folder(),
                experiment_path=self.experiment.experiment_path,
                resources=self.experiment.resources)
        except osexception as error:
            self.experiment.notify(_(u"Could not parse script: %s") % error)
            self.edit_script.edit.setText(self.experiment.to_string())
            return
        self.experiment = tmp
        self.ui.tabwidget.close_other()
        self.update_overview_area()
        self.extension_manager.fire(u'regenerate')
Example #11
0
	def update_resolution(self, width, height):

		"""
		desc:
			Updates the resolution in a way that preserves display centering.
			This is kind of a quick hack. First generate the script, change the
			resolution in the script and then re-parse the script.

		arguments:
			width:		The display width in pixels.
			height:		The display height in pixels.
		"""

		debug.msg(u"changing resolution to %d x %d" % (width, height))
		try:
			script = self.experiment.to_string()
		except Exception as e:
			if not isinstance(e, osexception):
				e = osexception(u'Failed to change the display resolution',
					exception=e)
			md = _(u'# Error\n\nFailed to change display resolution for the '
				u'following reason:\n\n- ') + e.markdown()
			self.tabwidget.open_markdown(md)
			return
		old_cmd = self.experiment.syntax.create_cmd(
			u'set', [u'height', self.experiment.var.height])
		new_cmd = self.experiment.syntax.create_cmd(u'set', [u'height', height])
		script = script.replace(old_cmd, new_cmd)
		old_cmd = self.experiment.syntax.create_cmd(
			u'set', [u'width', self.experiment.var.width])
		new_cmd = self.experiment.syntax.create_cmd(u'set', [u'width', width])
		script = script.replace(old_cmd, new_cmd)
		try:
			tmp = experiment.experiment(self, name=self.experiment.var.title,
				string=script, pool_folder=self.experiment.pool.folder(),
				experiment_path=self.experiment.experiment_path,
				resources=self.experiment.resources)
		except osexception as error:
			self.experiment.notify(_(u"Could not parse script: %s") % error)
			self.edit_script.edit.setText(self.experiment.to_string())
			return
		self.experiment = tmp
		self.ui.tabwidget.close_other()
		self.update_overview_area()
		self.extension_manager.fire(u'regenerate')
Example #12
0
	def apply_script(self):

		"""Apply changes to the general script"""

		self.main_window.set_busy(True)
		script = str(self.edit_script.edit.toPlainText())
		try:
			tmp = experiment.experiment(self.main_window, \
				self.main_window.experiment.title, 	script, \
				self.main_window.experiment.pool_folder)
		except libopensesame.exceptions.script_error as error:
			self.main_window.experiment.notify("Could not parse script: %s" % error)
			self.edit_script.edit.setText(self.main_window.experiment.to_string())
			return

		self.main_window.experiment = tmp
		self.main_window.close_other_tabs()
		self.edit_script.setModified(False)
		self.main_window.refresh()
		self.main_window.set_busy(False)
Example #13
0
    def update_resolution(self, width, height):
        """
		desc:
			Updates the resolution in a way that preserves display centering.
			This is kind of a quick hack. First generate the script, change the
			resolution in the script and then re-parse the script.

		arguments:
			width:		The display width in pixels.
			height:		The display height in pixels.
		"""

        debug.msg(u"changing resolution to %d x %d" % (width, height))
        try:
            script = self.experiment.to_string()
        except Exception as e:
            if not isinstance(e, osexception):
                e = osexception(u'Failed to change the display resolution',
                                exception=e)
            self.experiment.notify(e.html())
            return
        script = script.replace(u"\nset height \"%s\"\n" % \
         self.experiment.get(u"height"), u"\nset height \"%s\"\n" % height)
        script = script.replace(u"\nset width \"%s\"\n" % \
         self.experiment.get(u"width"), u"\nset width \"%s\"\n" % width)
        try:
            tmp = experiment.experiment(
                self,
                name=self.experiment.title,
                string=script,
                pool_folder=self.experiment.pool_folder,
                experiment_path=self.experiment.experiment_path,
                resources=self.experiment.resources)
        except osexception as error:
            self.experiment.notify(_(u"Could not parse script: %s") % error)
            self.edit_script.edit.setText(self.experiment.to_string())
            return
        self.experiment = tmp
        self.ui.tabwidget.close_other()
        self.update_overview_area()
        self.extension_manager.fire(u'regenerate')
Example #14
0
	def update_resolution(self, width, height):

		"""
		desc:
			Updates the resolution in a way that preserves display centering.
			This is kind of a quick hack. First generate the script, change the
			resolution in the script and then re-parse the script.

		arguments:
			width:		The display width in pixels.
			height:		The display height in pixels.
		"""

		debug.msg(u"changing resolution to %d x %d" % (width, height))
		try:
			script = self.experiment.to_string()
		except Exception as e:
			if not isinstance(e, osexception):
				e = osexception(u'Failed to change the display resolution',
					exception=e)
			self.experiment.notify(e.html())
			return
		script = script.replace(u"\nset height \"%s\"\n" % \
			self.experiment.get(u"height"), u"\nset height \"%s\"\n" % height)
		script = script.replace(u"\nset width \"%s\"\n" % \
			self.experiment.get(u"width"), u"\nset width \"%s\"\n" % width)
		try:
			tmp = experiment.experiment(self, name=self.experiment.title,
				string=script, pool_folder=self.experiment.pool_folder,
				experiment_path=self.experiment.experiment_path,
				resources=self.experiment.resources)
		except osexception as error:
			self.experiment.notify(_(u"Could not parse script: %s") % error)
			self.edit_script.edit.setText(self.experiment.to_string())
			return
		self.experiment = tmp
		self.ui.tabwidget.close_other()
		self.update_overview_area()
		self.extension_manager.fire(u'regenerate')
from libqtopensesame.qtopensesame import qtopensesame
from libqtopensesame.items.experiment import experiment

# A very basic experiment in OpenSesame script
exp_str = u'''
set start my_sketchpad
define sketchpad my_sketchpad
	draw textline 0 0 "Dummy text"
'''

main_window = qtopensesame()

# Parse the OpenSesame script into an experiment object
exp = experiment(main_window, u'experiment', string=exp_str)
# Calling the `experiment.run()` method will launch the full experiment
exp.run()
Example #16
0
	def open_file(self, dummy=None, path=None, add_to_recent=True):

		"""
		desc:
			Opens an experiment file.

		keywords:
			dummy:		Dummy argument passed by event handler.
			path:
			 	desc:	The path to the file. If None, a file dialog is
						presented.
				type:	[str, NoneType]
			add_to_recent:
				desc:	Indicates whether the file should be added to the list
						of recent experiments.
				type:	bool
		"""

		if not self.save_unsaved_changes():
			self.ui.tabwidget.open_general()
			return
		if path is None:
			path = QtGui.QFileDialog.getOpenFileName(
				self.ui.centralwidget, _(u"Open file"),
				filter=self.open_file_filter, directory=cfg.file_dialog_path)
		if path is None or path == u'' or ( \
			not path.lower().endswith(u'.opensesame') and \
			not  path.lower().endswith(u'.opensesame.tar.gz') and \
			not path.lower().endswith(u'.osexp')):
			return
		self.set_busy()
		self.ui.tabwidget.close_all(avoid_empty=False)
		cfg.file_dialog_path = os.path.dirname(path)
		try:
			exp = experiment.experiment(self, u"Experiment", path,
				experiment_path=os.path.dirname(path))
		except Exception as e:
			if not isinstance(e, osexception):
				e = osexception(msg=u'Failed to open file', exception=e)
			md = _(u'# Failed to open\n\nFailed to open the file for the '
				u'following reason:\n\n- ') + e.markdown()
			self.tabwidget.open_markdown(md)
			self.ui.console.write(e)
			self.set_busy(False)
			return
		self.experiment.pool.clean_up()
		self.experiment = exp
		self.experiment.build_item_tree()
		self.ui.tabwidget.open_general()
		if add_to_recent:
			self.current_path = path
			self.window_message(self.current_path)
			self.update_recent_files()
			cfg.default_logfile_folder = os.path.dirname(self.current_path)
		else:
			self.window_message(u"New experiment")
			self.current_path = None
		self.set_auto_response()
		self.set_unsaved(False)
		self.ui.pool_widget.refresh()
		self.ui.console.reset()
		self.extension_manager.fire(u'open_experiment', path=path)
		self.set_busy(False)
Example #17
0
    def resume_init(self):
        """Resume GUI initialization"""

        from libopensesame import misc
        from libqtopensesame.misc import theme
        from libqtopensesame.extensions import extension_manager
        import random

        # Make sure that icons are shown in context menu, regardless of the
        # system settings. This is necessary, because Ubuntu doesn't show menu
        # icons by default.
        QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_DontShowIconsInMenus,
                                            False)
        # Do a few things to customize QProgEdit behavior:
        # - Register the bundled monospace font (Droid Sans Mono)
        # - Make sure that QProgEdit doesn't complain about some standard names
        # - Ignore undefined name warnings, which don't play well with
        #   OpenSesame's single workspace
        QtGui.QFontDatabase.addApplicationFont(misc.resource(u'mono.ttf'))
        from QProgEdit import validate
        validate.addPythonBuiltins([u'exp', u'win', u'self'])
        if hasattr(validate, u'setPyFlakesFilter'):
            validate.setPyFlakesFilter(
                lambda msg: msg.message == u'undefined name %r')
        # Initialize random number generator
        random.seed()

        # Check the filesystem encoding for debugging purposes
        debug.msg(u'filesystem encoding: %s' % misc.filesystem_encoding())

        # # Parse the command line
        # self.parse_command_line()
        #
        # # Restore the configuration
        # self.restore_config()
        self.set_style()
        self.set_warnings()
        # self.set_locale()

        # Setup the UI
        self.load_ui(u'misc.main_window')
        self.theme = theme.theme(self, self.options._theme)
        self.ui.itemtree.setup(self)
        self.ui.console.setup(self)
        self.ui.tabwidget.main_window = self

        # Determine the home folder
        self.home_folder = libopensesame.misc.home_folder()

        # Create .opensesame folder if it doesn't exist yet
        if not os.path.exists(os.path.join(self.home_folder, u".opensesame")):
            os.mkdir(os.path.join(self.home_folder, u".opensesame"))

        # Set the filter-string for opening and saving files
        self.save_file_filter = u'OpenSesame files (*.osexp)'
        self.open_file_filter = \
         u'OpenSesame files (*.osexp *.opensesame.tar.gz *.opensesame)'

        # Set the window message
        self._read_only = False
        self.window_message(_(u"New experiment"))

        # Set the window icon
        self.setWindowIcon(self.theme.qicon(u"opensesame"))

        # Make the connections
        self.ui.itemtree.structure_change.connect(self.update_overview_area)
        self.ui.action_quit.triggered.connect(self.close)
        self.ui.action_open.triggered.connect(self.open_file)
        self.ui.action_save.triggered.connect(self.save_file)
        self.ui.action_save_as.triggered.connect(self.save_file_as)
        self.ui.action_run.triggered.connect(self.run_experiment)
        self.ui.action_run_in_window.triggered.connect(
            self.run_experiment_in_window)
        self.ui.action_run_quick.triggered.connect(self.run_quick)
        self.ui.action_kill.triggered.connect(self.kill_experiment)
        self.ui.action_enable_auto_response.triggered.connect(
            self.set_auto_response)
        self.ui.action_close_current_tab.triggered.connect(
            self.ui.tabwidget.close_current)
        self.ui.action_close_all_tabs.triggered.connect(
            self.ui.tabwidget.close_all)
        self.ui.action_close_other_tabs.triggered.connect(
            self.ui.tabwidget.close_other)
        self.ui.action_onetabmode.triggered.connect(
            self.ui.tabwidget.toggle_onetabmode)
        self.ui.action_show_overview.triggered.connect(self.toggle_overview)
        self.ui.action_show_pool.triggered.connect(self.toggle_pool)
        self.ui.action_show_stdout.triggered.connect(self.refresh_stdout)
        self.ui.action_preferences.triggered.connect(
            self.ui.tabwidget.open_preferences)

        # Setup console
        self.ui.button_help_console.clicked.connect(
            self.ui.tabwidget.open_stdout_help)
        self.ui.button_reset_console.clicked.connect(self.ui.console.reset)

        # Setup the overview area
        self.ui.dock_overview.show()
        self.ui.dock_overview.visibilityChanged.connect(
            self.ui.action_show_overview.setChecked)

        # Setup the file pool
        from libqtopensesame.widgets.pool_widget import pool_widget
        self.ui.dock_pool.hide()
        self.ui.dock_pool.visibilityChanged.connect(
            self.ui.action_show_pool.setChecked)
        self.ui.pool_widget = pool_widget(self)
        self.ui.dock_pool.setWidget(self.ui.pool_widget)

        # Uncheck the debug window button on debug window close
        self.ui.dock_stdout.hide()
        self.ui.dock_stdout.visibilityChanged.connect(
            self.ui.action_show_stdout.setChecked)

        # Initialize keyboard shortcuts
        self.ui.shortcut_itemtree = QtWidgets.QShortcut(
            QtGui.QKeySequence(), self, self.focus_overview_area)
        self.ui.shortcut_tabwidget = QtWidgets.QShortcut(
            QtGui.QKeySequence(), self, self.ui.tabwidget.focus)
        self.ui.shortcut_stdout = QtWidgets.QShortcut(QtGui.QKeySequence(),
                                                      self,
                                                      self.focus_debug_window)
        self.ui.shortcut_pool = QtWidgets.QShortcut(QtGui.QKeySequence(), self,
                                                    self.focus_file_pool)

        # Create the initial experiment, which is the default template. Because
        # not all backends are supported under Python 3, we use a different
        # backend for each.
        if py3:
            tmpl = u'default-py3.osexp'
        else:
            tmpl = u'default.osexp'
        with safe_open(misc.resource(os.path.join(u'templates', tmpl)),
                       u'r') as fd:
            self.experiment = experiment.experiment(self, u'New experiment',
                                                    fd.read())
        self.experiment.build_item_tree()
        self.ui.itemtree.default_fold_state()

        # Miscellaneous initialization
        self.restore_state()
        self.update_recent_files()
        self.set_unsaved(False)
        self.init_custom_fonts()

        # Initialize extensions
        self.extension_manager = extension_manager(self)
        self.extension_manager.fire(u'startup')
Example #18
0
    def open_file(self, dummy=None, path=None, add_to_recent=True):
        """
		desc:
			Opens an experiment file.

		keywords:
			dummy:		Dummy argument passed by event handler.
			path:
			 	desc:	The path to the file. If None, a file dialog is
						presented.
				type:	[str, NoneType]
			add_to_recent:
				desc:	Indicates whether the file should be added to the list
						of recent experiments.
				type:	bool
		"""

        if not self.save_unsaved_changes():
            self.ui.tabwidget.open_general()
            return
        if path is None:
            path = QtWidgets.QFileDialog.getOpenFileName(
                self.ui.centralwidget,
                _(u"Open file"),
                filter=self.open_file_filter,
                directory=cfg.file_dialog_path)
        # In PyQt5, the QFileDialog.getOpenFileName returns a tuple instead of
        # a string, of which the first position contains the path. check for that
        # here.
        if isinstance(path, tuple):
            path = path[0]
        if path is None or path == u'' or ( \
         not path.lower().endswith(u'.opensesame') and \
         not  path.lower().endswith(u'.opensesame.tar.gz') and \
         not path.lower().endswith(u'.osexp')):
            return
        self.set_busy()
        self.ui.tabwidget.close_all(avoid_empty=False)
        cfg.file_dialog_path = os.path.dirname(path)
        try:
            exp = experiment.experiment(self,
                                        u"Experiment",
                                        path,
                                        experiment_path=os.path.dirname(path))
        except Exception as e:
            if not isinstance(e, osexception):
                e = osexception(msg=u'Failed to open file', exception=e)
            md = _(u'# Failed to open\n\nFailed to open the file for the '
                   u'following reason:\n\n- ') + e.markdown()
            self.tabwidget.open_markdown(md)
            self.ui.console.write(e)
            self.set_busy(False)
            return
        self.experiment.pool.clean_up()
        self.experiment = exp
        self.experiment.build_item_tree()
        self.ui.itemtree.default_fold_state()
        self.ui.tabwidget.open_general()
        if add_to_recent:
            self.current_path = path
            self.read_only = not os.access(path, os.W_OK)
            self.window_message(self.current_path)
            self.update_recent_files()
            cfg.default_logfile_folder = os.path.dirname(self.current_path)
        else:
            self.window_message(u"New experiment")
            self.current_path = None
        self.set_auto_response()
        self.set_unsaved(False)
        self.ui.pool_widget.refresh()
        self.ui.console.reset()
        self.extension_manager.fire(u'open_experiment', path=path)
        self.set_busy(False)
        # Process non-fatal errors
        if exp.items.error_log:
            self.tabwidget.open_markdown(
             _(u'Errors occurred while opening the file:\n\n') + \
             u'\n---\n'.join([exc.markdown() for exc in exp.items.error_log]),
             title=_(u'Error'), icon=u'dialog-error')
            self.window_message(u"New experiment")
            self.current_path = None
Example #19
0
    def resume_init(self):
        """Resume GUI initialization"""

        from libopensesame import misc
        from libqtopensesame.misc import theme
        from libqtopensesame.extensions import extension_manager
        import platform
        import random

        # Set some initial variables
        self.current_path = None
        self.version = misc.version
        self.codename = misc.codename
        self.lock_refresh = False
        self.unsaved_changes = False

        # Make sure that QProgEdit doesn't complain about some standard names
        from QProgEdit import validate
        validate.addPythonBuiltins([u'exp', u'win', u'self'])

        # Initialize random number generator
        random.seed()

        # Check the filesystem encoding for debugging purposes
        debug.msg(u'filesystem encoding: %s' % misc.filesystem_encoding())

        # Parse the command line
        self.parse_command_line()

        # Restore the configuration
        self.restore_config()

        # Setup the UI
        self.load_ui(u'misc.main_window')
        self.ui.itemtree.setup(self)
        self.ui.tabwidget.main_window = self

        # Load a theme
        self.theme = theme.theme(self, self.options._theme)

        # Determine the home folder
        self.home_folder = libopensesame.misc.home_folder()

        # Create .opensesame folder if it doesn't exist yet
        if not os.path.exists(os.path.join(self.home_folder, u".opensesame")):
            os.mkdir(os.path.join(self.home_folder, u".opensesame"))

        # Set the filter-string for opening and saving files
        self.file_type_filter = \
         u"OpenSesame files (*.opensesame.tar.gz *.opensesame);;OpenSesame script and file pool (*.opensesame.tar.gz);;OpenSesame script (*.opensesame)"
        self.file_type_filter_script = u"OpenSesame script (*.opensesame)"
        self.file_type_filter_pool = \
         u"OpenSesame script and file pool (*.opensesame.tar.gz)"

        # Set the window message
        self.window_message(_(u"Welcome to OpenSesame %s") % self.version)

        # Set the window icon
        self.setWindowIcon(self.theme.qicon(u"opensesame"))

        # Make the connections
        self.ui.itemtree.structure_change.connect(self.update_overview_area)
        self.ui.action_quit.triggered.connect(self.close)
        self.ui.action_new.triggered.connect(self.new_file)
        self.ui.action_open.triggered.connect(self.open_file)
        self.ui.action_save.triggered.connect(self.save_file)
        self.ui.action_save_as.triggered.connect(self.save_file_as)
        self.ui.action_run.triggered.connect(self.run_experiment)
        self.ui.action_run_in_window.triggered.connect(
            self.run_experiment_in_window)
        self.ui.action_run_quick.triggered.connect(self.run_quick)
        self.ui.action_enable_auto_response.triggered.connect(
            self.set_auto_response)
        self.ui.action_close_current_tab.triggered.connect(
            self.ui.tabwidget.close_current)
        self.ui.action_close_all_tabs.triggered.connect(
            self.ui.tabwidget.close_all)
        self.ui.action_close_other_tabs.triggered.connect(
            self.ui.tabwidget.close_other)
        self.ui.action_onetabmode.triggered.connect(
            self.ui.tabwidget.toggle_onetabmode)
        self.ui.action_show_overview.triggered.connect(self.toggle_overview)
        self.ui.action_show_variable_inspector.triggered.connect(
            self.refresh_variable_inspector)
        self.ui.action_show_pool.triggered.connect(self.refresh_pool)
        self.ui.action_show_stdout.triggered.connect(self.refresh_stdout)
        self.ui.action_preferences.triggered.connect(
            self.ui.tabwidget.open_preferences)
        self.ui.button_help_stdout.clicked.connect(
            self.ui.tabwidget.open_stdout_help)

        # Setup the overview area
        self.ui.dock_overview.show()
        self.ui.dock_overview.visibilityChanged.connect( \
         self.ui.action_show_overview.setChecked)

        # Setup the variable inspector
        from libqtopensesame.widgets.variable_inspector import \
         variable_inspector
        self.ui.variable_inspector = variable_inspector(self)
        self.ui.dock_variable_inspector.hide()
        self.ui.dock_variable_inspector.visibilityChanged.connect(
            self.ui.action_show_variable_inspector.setChecked)
        self.ui.dock_variable_inspector.setWidget(self.ui.variable_inspector)

        # Setup the file pool
        from libqtopensesame.widgets.pool_widget import pool_widget
        self.ui.dock_pool.hide()
        self.ui.dock_pool.visibilityChanged.connect(
            self.ui.action_show_pool.setChecked)
        self.ui.pool_widget = pool_widget(self)
        self.ui.dock_pool.setWidget(self.ui.pool_widget)

        # Uncheck the debug window button on debug window close
        self.ui.dock_stdout.visibilityChanged.connect( \
         self.ui.action_show_stdout.setChecked)

        # Initialize keyboard shortcuts
        self.ui.shortcut_itemtree = QtGui.QShortcut( \
         QtGui.QKeySequence(), self, self.ui.itemtree.setFocus)
        self.ui.shortcut_tabwidget = QtGui.QShortcut( \
         QtGui.QKeySequence(), self, self.ui.tabwidget.setFocus)
        self.ui.shortcut_stdout = QtGui.QShortcut( \
         QtGui.QKeySequence(), self, self.ui.edit_stdout.setFocus)
        self.ui.shortcut_variables = QtGui.QShortcut( \
         QtGui.QKeySequence(), self, \
         self.ui.variable_inspector.set_focus())
        self.ui.shortcut_pool = QtGui.QShortcut( \
         QtGui.QKeySequence(), self, \
         self.ui.pool_widget.ui.edit_pool_filter.setFocus)

        # Create the initial experiment, which is the default template.
        self.experiment = experiment.experiment(self, u"New experiment", \
         open(misc.resource(os.path.join(u"templates", \
          u"default.opensesame")), u"r").read())
        self.experiment.build_item_tree()

        # Miscellaneous initialization
        self.restore_state()
        self.update_recent_files()
        self.set_unsaved(False)
        self.init_custom_fonts()
        self.ui.variable_inspector.refresh()

        # Initialize extensions
        self.extension_manager = extension_manager(self)
        self.extension_manager.fire(u'startup')
Example #20
0
	def open_file(self, dummy=None, path=None, add_to_recent=True):

		"""
		desc:
			Opens an experiment file.

		keywords:
			dummy:		Dummy argument passed by event handler.
			path:
			 	desc:	The path to the file. If None, a file dialog is
						presented.
				type:	[str, NoneType]
			add_to_recent:
				desc:	Indicates whether the file should be added to the list
						of recent experiments.
				type:	bool
		"""

		if not self.save_unsaved_changes():
			self.ui.tabwidget.open_general()
			return
		if path is None:
			path = QtWidgets.QFileDialog.getOpenFileName(self.ui.centralwidget,
				_(u"Open file"), filter=self.open_file_filter,
				directory=cfg.file_dialog_path)
		# In PyQt5, the QFileDialog.getOpenFileName returns a tuple instead of
		# a string, of which the first position contains the path. check for that
		# here.
		if isinstance(path,tuple):
			path = path[0]
		if path is None or path == u'' or ( \
			not path.lower().endswith(u'.opensesame') and \
			not  path.lower().endswith(u'.opensesame.tar.gz') and \
			not path.lower().endswith(u'.osexp')):
			return
		self.set_busy()
		self.ui.tabwidget.close_all(avoid_empty=False)
		cfg.file_dialog_path = os.path.dirname(path)
		try:
			exp = experiment.experiment(self, u"Experiment", path,
				experiment_path=os.path.dirname(path))
		except Exception as e:
			if not isinstance(e, osexception):
				e = osexception(msg=u'Failed to open file', exception=e)
			md = _(u'# Failed to open\n\nFailed to open the file for the '
				u'following reason:\n\n- ') + e.markdown()
			self.tabwidget.open_markdown(md)
			self.ui.console.write(e)
			self.set_busy(False)
			return
		self.experiment.pool.clean_up()
		self.experiment = exp
		self.experiment.build_item_tree()
		self.ui.itemtree.default_fold_state()
		self.ui.tabwidget.open_general()
		if add_to_recent:
			self.current_path = path
			self.read_only = not os.access(path, os.W_OK)
			self.window_message(self.current_path)
			self.update_recent_files()
			cfg.default_logfile_folder = os.path.dirname(self.current_path)
		else:
			self.window_message(u"New experiment")
			self.current_path = None
		self.set_auto_response()
		self.set_unsaved(False)
		self.ui.pool_widget.refresh()
		self.ui.console.reset()
		self.extension_manager.fire(u'open_experiment', path=path)
		self.set_busy(False)
		# Process non-fatal errors
		if exp.items.error_log:
			self.tabwidget.open_markdown(
				_(u'Errors occurred while opening the file:\n\n') + \
				u'\n---\n'.join([exc.markdown() for exc in exp.items.error_log]),
				title=_(u'Error'), icon=u'dialog-error')
			self.window_message(u"New experiment")
			self.current_path = None
Example #21
0
	def resume_init(self):

		"""Resume GUI initialization"""

		from libopensesame import misc
		from libqtopensesame.misc import theme
		from libqtopensesame.extensions import extension_manager
		import platform
		import random

		# Set some initial variables
		self.current_path = None
		self.version = misc.version
		self.codename = misc.codename
		self.lock_refresh = False
		self.unsaved_changes = False

		# Make sure that QProgEdit doesn't complain about some standard names
		from QProgEdit import validate
		validate.addPythonBuiltins([u'exp', u'win', u'self'])

		# Initialize random number generator
		random.seed()

		# Check the filesystem encoding for debugging purposes
		debug.msg(u'filesystem encoding: %s' % misc.filesystem_encoding())

		# Parse the command line
		self.parse_command_line()

		# Restore the configuration
		self.restore_config()

		# Setup the UI
		self.load_ui(u'misc.main_window')
		self.ui.itemtree.setup(self)
		self.ui.tabwidget.main_window = self

		# Load a theme
		self.theme = theme.theme(self, self.options._theme)

		# Determine the home folder
		self.home_folder = libopensesame.misc.home_folder()

		# Create .opensesame folder if it doesn't exist yet
		if not os.path.exists(os.path.join(self.home_folder, u".opensesame")):
			os.mkdir(os.path.join(self.home_folder, u".opensesame"))

		# Set the filter-string for opening and saving files
		self.file_type_filter = \
			u"OpenSesame files (*.opensesame.tar.gz *.opensesame);;OpenSesame script and file pool (*.opensesame.tar.gz);;OpenSesame script (*.opensesame)"

		# Set the window message
		self.window_message(_(u"Welcome to OpenSesame %s") % self.version)

		# Set the window icon
		self.setWindowIcon(self.theme.qicon(u"opensesame"))

		# Make the connections
		self.ui.itemtree.structure_change.connect(self.update_overview_area)
		self.ui.action_quit.triggered.connect(self.close)
		self.ui.action_new.triggered.connect(self.new_file)
		self.ui.action_open.triggered.connect(self.open_file)
		self.ui.action_save.triggered.connect(self.save_file)
		self.ui.action_save_as.triggered.connect(self.save_file_as)
		self.ui.action_run.triggered.connect(self.run_experiment)
		self.ui.action_run_in_window.triggered.connect(
			self.run_experiment_in_window)
		self.ui.action_run_quick.triggered.connect(self.run_quick)
		self.ui.action_enable_auto_response.triggered.connect(
			self.set_auto_response)
		self.ui.action_close_current_tab.triggered.connect(
			self.ui.tabwidget.close_current)
		self.ui.action_close_all_tabs.triggered.connect(
			self.ui.tabwidget.close_all)
		self.ui.action_close_other_tabs.triggered.connect(
			self.ui.tabwidget.close_other)
		self.ui.action_onetabmode.triggered.connect(
			self.ui.tabwidget.toggle_onetabmode)
		self.ui.action_show_overview.triggered.connect(self.toggle_overview)
		self.ui.action_show_variable_inspector.triggered.connect(
			self.refresh_variable_inspector)
		self.ui.action_show_pool.triggered.connect(self.refresh_pool)
		self.ui.action_show_stdout.triggered.connect(self.refresh_stdout)
		self.ui.action_preferences.triggered.connect(
			self.ui.tabwidget.open_preferences)
		self.ui.button_help_stdout.clicked.connect(
			self.ui.tabwidget.open_stdout_help)

		# Setup the overview area
		self.ui.dock_overview.show()
		self.ui.dock_overview.visibilityChanged.connect( \
			self.ui.action_show_overview.setChecked)

		# Setup the variable inspector
		from libqtopensesame.widgets.variable_inspector import \
			variable_inspector
		self.ui.variable_inspector = variable_inspector(self)
		self.ui.dock_variable_inspector.hide()
		self.ui.dock_variable_inspector.visibilityChanged.connect(
			self.ui.action_show_variable_inspector.setChecked)
		self.ui.dock_variable_inspector.setWidget(self.ui.variable_inspector)

		# Setup the file pool
		from libqtopensesame.widgets.pool_widget import pool_widget
		self.ui.dock_pool.hide()
		self.ui.dock_pool.visibilityChanged.connect(
			self.ui.action_show_pool.setChecked)
		self.ui.pool_widget = pool_widget(self)
		self.ui.dock_pool.setWidget(self.ui.pool_widget)

		# Uncheck the debug window button on debug window close
		self.ui.dock_stdout.visibilityChanged.connect( \
			self.ui.action_show_stdout.setChecked)

		# Initialize keyboard shortcuts
		self.ui.shortcut_itemtree = QtGui.QShortcut( \
			QtGui.QKeySequence(), self, self.ui.itemtree.setFocus)
		self.ui.shortcut_tabwidget = QtGui.QShortcut( \
			QtGui.QKeySequence(), self, self.ui.tabwidget.setFocus)
		self.ui.shortcut_stdout = QtGui.QShortcut( \
			QtGui.QKeySequence(), self, self.ui.edit_stdout.setFocus)
		self.ui.shortcut_variables = QtGui.QShortcut( \
			QtGui.QKeySequence(), self, \
			self.ui.variable_inspector.set_focus())
		self.ui.shortcut_pool = QtGui.QShortcut( \
			QtGui.QKeySequence(), self, \
			self.ui.pool_widget.ui.edit_pool_filter.setFocus)

		# Create the initial experiment, which is the default template.
		self.experiment = experiment.experiment(self, u"New experiment", \
			open(misc.resource(os.path.join(u"templates", \
				u"default.opensesame")), u"r").read())
		self.experiment.build_item_tree()

		# Miscellaneous initialization
		self.restore_state()
		self.update_recent_files()
		self.set_unsaved(False)		
		self.init_custom_fonts()

		# Initialize extensions
		self.extension_manager = extension_manager(self)
		self.extension_manager.fire(u'startup')
Example #22
0
	def resume_init(self):

		"""Resume GUI initialization"""

		from libopensesame import misc
		from libqtopensesame.misc import theme
		from libqtopensesame.extensions import extension_manager
		import random

		# Make sure that icons are shown in context menu, regardless of the
		# system settings. This is necessary, because Ubuntu doesn't show menu
		# icons by default.
		QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_DontShowIconsInMenus,
			False)
		# Add the Qt plugin folders to the library path, if they exists. Where
		# these folders are depends on the version of Qt4, but these are two
		# possible locations.
		qt_plugin_path = os.path.join(
			os.path.dirname(sys.executable), 'Library', 'plugins')
		if os.path.isdir(qt_plugin_path):
			QtCore.QCoreApplication.addLibraryPath(qt_plugin_path)
		qt_plugin_path = os.path.join(
			os.path.dirname(sys.executable), 'Library', 'lib', 'qt4', 'plugins')
		if os.path.isdir(qt_plugin_path):
			QtCore.QCoreApplication.addLibraryPath(qt_plugin_path)
		# Do a few things to customize QProgEdit behavior:
		# - Register the bundled monospace font (Droid Sans Mono)
		# - Make sure that QProgEdit doesn't complain about some standard names
		# - Ignore undefined name warnings, which don't play well with
		#   OpenSesame's single workspace
		QtGui.QFontDatabase.addApplicationFont(misc.resource(u'mono.ttf'))
		from QProgEdit import validate
		validate.addPythonBuiltins([u'exp', u'win', u'self'])
		if hasattr(validate, u'setPyFlakesFilter'):
			validate.setPyFlakesFilter(
				lambda msg: msg.message == u'undefined name %r')
		# Initialize random number generator
		random.seed()

		# Check the filesystem encoding for debugging purposes
		debug.msg(u'filesystem encoding: %s' % misc.filesystem_encoding())

		# # Parse the command line
		# self.parse_command_line()
		# 
		# # Restore the configuration
		# self.restore_config()
		self.set_style()
		self.set_warnings()
		# self.set_locale()

		# Setup the UI
		self.load_ui(u'misc.main_window')
		self.theme = theme.theme(self, self.options._theme)
		self.ui.itemtree.setup(self)
		self.ui.console.setup(self)
		self.ui.tabwidget.main_window = self

		# Determine the home folder
		self.home_folder = libopensesame.misc.home_folder()

		# Create .opensesame folder if it doesn't exist yet
		if not os.path.exists(os.path.join(self.home_folder, u".opensesame")):
			os.mkdir(os.path.join(self.home_folder, u".opensesame"))

		# Set the filter-string for opening and saving files
		self.save_file_filter =u'OpenSesame files (*.osexp)'
		self.open_file_filter = \
			u'OpenSesame files (*.osexp *.opensesame.tar.gz *.opensesame)'

		# Set the window message
		self._read_only = False
		self.window_message(_(u"New experiment"))

		# Set the window icon
		self.setWindowIcon(self.theme.qicon(u"opensesame"))

		# Make the connections
		self.ui.itemtree.structure_change.connect(self.update_overview_area)
		self.ui.action_quit.triggered.connect(self.close)
		self.ui.action_open.triggered.connect(self.open_file)
		self.ui.action_save.triggered.connect(self.save_file)
		self.ui.action_save_as.triggered.connect(self.save_file_as)
		self.ui.action_run.triggered.connect(self.run_experiment)
		self.ui.action_run_in_window.triggered.connect(
			self.run_experiment_in_window)
		self.ui.action_run_quick.triggered.connect(self.run_quick)
		self.ui.action_enable_auto_response.triggered.connect(
			self.set_auto_response)
		self.ui.action_close_current_tab.triggered.connect(
			self.ui.tabwidget.close_current)
		self.ui.action_close_all_tabs.triggered.connect(
			self.ui.tabwidget.close_all)
		self.ui.action_close_other_tabs.triggered.connect(
			self.ui.tabwidget.close_other)
		self.ui.action_onetabmode.triggered.connect(
			self.ui.tabwidget.toggle_onetabmode)
		self.ui.action_show_overview.triggered.connect(self.toggle_overview)
		self.ui.action_show_pool.triggered.connect(
			self.toggle_pool)
		self.ui.action_show_stdout.triggered.connect(self.refresh_stdout)
		self.ui.action_preferences.triggered.connect(
			self.ui.tabwidget.open_preferences)

		# Setup console
		self.ui.button_help_console.clicked.connect(
			self.ui.tabwidget.open_stdout_help)
		self.ui.button_reset_console.clicked.connect(
			self.ui.console.reset)

		# Setup the overview area
		self.ui.dock_overview.show()
		self.ui.dock_overview.visibilityChanged.connect(
			self.ui.action_show_overview.setChecked)

		# Setup the file pool
		from libqtopensesame.widgets.pool_widget import pool_widget
		self.ui.dock_pool.hide()
		self.ui.dock_pool.visibilityChanged.connect(
			self.ui.action_show_pool.setChecked)
		self.ui.pool_widget = pool_widget(self)
		self.ui.dock_pool.setWidget(self.ui.pool_widget)

		# Uncheck the debug window button on debug window close
		self.ui.dock_stdout.hide()
		self.ui.dock_stdout.visibilityChanged.connect(
			self.ui.action_show_stdout.setChecked)

		# Initialize keyboard shortcuts
		self.ui.shortcut_itemtree = QtWidgets.QShortcut(QtGui.QKeySequence(), self,
			self.focus_overview_area)
		self.ui.shortcut_tabwidget = QtWidgets.QShortcut(
			QtGui.QKeySequence(), self, self.ui.tabwidget.focus)
		self.ui.shortcut_stdout = QtWidgets.QShortcut(QtGui.QKeySequence(), self,
			self.focus_debug_window)
		self.ui.shortcut_pool = QtWidgets.QShortcut(QtGui.QKeySequence(), self,
			self.focus_file_pool)

		# Create the initial experiment, which is the default template. Because
		# not all backends are supported under Python 3, we use a different
		# backend for each.
		if py3:
			tmpl = u'default-py3.osexp'
		else:
			tmpl = u'default.osexp'
		with safe_open(misc.resource(os.path.join(u'templates', tmpl)), u'r') as fd:
			self.experiment = experiment.experiment(self, u'New experiment',
				fd.read())
		self.experiment.build_item_tree()
		self.ui.itemtree.default_fold_state()

		# Miscellaneous initialization
		self.restore_state()
		self.update_recent_files()
		self.set_unsaved(False)
		self.init_custom_fonts()

		# Initialize extensions
		self.extension_manager = extension_manager(self)
		self.extension_manager.fire(u'startup')
Example #23
0
	def open_file(self, dummy=None, path=None, add_to_recent=True):

		"""
		desc:
			Opens an experiment file.

		keywords:
			dummy:		Dummy argument passed by event handler.
			path:
			 	desc:	The path to the file. If None, a file dialog is
						presented.
				type:	[str, NoneType]
			add_to_recent:
				desc:	Indicates whether the file should be added to the list
						of recent experiments.
				type:	bool
		"""

		if not self.save_unsaved_changes():
			self.ui.tabwidget.open_general()
			return
		if path is None:
			path = QtGui.QFileDialog.getOpenFileName(
				self.ui.centralwidget, _(u"Open file"),
				filter=self.open_file_filter, directory=cfg.file_dialog_path)
		if path is None or path == u'' or ( \
			not path.lower().endswith(u'.opensesame') and \
			not  path.lower().endswith(u'.opensesame.tar.gz') and \
			not path.lower().endswith(u'.osexp')):
			return
		self.set_busy()
		self.ui.tabwidget.close_all(avoid_empty=False)
		cfg.file_dialog_path = os.path.dirname(path)
		try:
			exp = experiment.experiment(self, u"Experiment", path,
				experiment_path=os.path.dirname(path))
		except Exception as e:
			if not isinstance(e, osexception):
				e = osexception(msg=u'Failed to open file', exception=e)
			md = _(u'# Failed to open\n\nFailed to open the file for the '
				u'following reason:\n\n- ') + e.markdown()
			self.tabwidget.open_markdown(md)
			self.ui.console.write(e)
			self.set_busy(False)
			return
		self.experiment.pool.clean_up()
		self.experiment = exp
		self.experiment.build_item_tree()
		self.ui.tabwidget.open_general()
		if add_to_recent:
			self.current_path = path
			self.window_message(self.current_path)
			self.update_recent_files()
			cfg.default_logfile_folder = os.path.dirname(self.current_path)
		else:
			self.window_message(u"New experiment")
			self.current_path = None
		self.set_auto_response()
		self.set_unsaved(False)
		self.ui.pool_widget.refresh()
		self.ui.console.reset()
		self.extension_manager.fire(u'open_experiment', path=path)
		self.set_busy(False)