示例#1
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')
示例#2
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')
示例#3
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')
示例#4
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')