Skip to content

Commit

Permalink
Improve opensesamerun:
Browse files Browse the repository at this point in the history
- Add margins to UI
- Remove EyeLink option (no longer necessary)
- Fix fullscreen support (closes #797)
- Code clean-up
  • Loading branch information
smathot committed Sep 14, 2023
1 parent fbe72d2 commit 000dd63
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 81 deletions.
4 changes: 0 additions & 4 deletions libopensesame/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def opensesamerun_options():
parser.set_defaults(logfile=None)
parser.set_defaults(debug=False)
parser.set_defaults(fullscreen=False)
parser.set_defaults(pylink=False)
parser.set_defaults(width=1024)
parser.set_defaults(height=768)
parser.set_defaults(custom_resolution=False)
Expand All @@ -119,9 +118,6 @@ def opensesamerun_options():
group.add_option(u"--stack", action=u"store_true",
dest=u"stack", help=u"Print stack information")
parser.add_option_group(group)
group = optparse.OptionGroup(parser, u"Miscellaneous options")
group.add_option(u"--pylink", action=u"store_true", dest=u"pylink",
help=u"Load PyLink before PyGame (necessary for using the Eyelink plug-ins in non-dummy mode)")
parser.add_option_group(group)
options, args = parser.parse_args(sys.argv)

Expand Down
35 changes: 18 additions & 17 deletions libqtopensesame/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
sys.stderr = open(os.devnull, 'w')
sys.stdin = open(os.devnull)

# On MacOS, the locations of the SSL cerfificates need to be explicitly indicated when packaged
# as an app, otherwise urllib.urlopen fails with an SSL related error. To do so, we make use of the
# certifi package that can provide this location, but it is unclear if certifi is always installed,
# On MacOS, the locations of the SSL cerfificates need to be explicitly
# indicated when packaged # as an app, otherwise urllib.urlopen fails with an
# SSL related error. To do so, we make use of the certifi package that can
# provide this location, but it is unclear if certifi is always installed,
# so let's fail gracefully if it isn't.
if platform.system() == 'Darwin':
try:
Expand Down Expand Up @@ -221,7 +222,7 @@ def opensesamerun():
"""The entrty point for the OpenSesameRun GUI"""
set_paths()
from libopensesame.oslogging import oslogger
oslogger.start(u'gui')
oslogger.start('gui')
from libopensesame import misc
misc.parse_environment_file()
from libopensesame.experiment import Experiment
Expand All @@ -236,11 +237,11 @@ def opensesamerun():
# without PyQt, people can still run experiments.
try:
from qtpy import QtGui, QtCore, QtWidgets
except:
misc.messagebox(u"OpenSesame Run", u"Incorrect or "
u"missing options.\n\nRun 'opensesame --help' from a terminal "
u"(or command prompt) to see a list of available options, or "
u"install Python Qt4 to enable the graphical user interface.")
except Exception as e:
misc.messagebox("OpenSesame Run", "Incorrect or "
"missing options.\n\nRun 'opensesame --help' from a terminal "
"(or command prompt) to see a list of available options, or "
"install PyQt to enable the graphical user interface.")
sys.exit()
# Create the GUI and show it
from libqtopensesame.qtopensesamerun import QtOpenSesameRun
Expand All @@ -258,17 +259,17 @@ def opensesamerun():
experiment = os.path.abspath(options.experiment)
if isinstance(experiment, bytes):
experiment = safe_decode(experiment, enc=sys.getfilesystemencoding(),
errors=u'ignore')
errors='ignore')
# experiment_path = os.path.dirname(experiment)
logfile = options.logfile
if isinstance(logfile, bytes):
logfile = safe_decode(logfile, enc=sys.getfilesystemencoding(),
errors=u'ignore')
errors='ignore')
experiment_path = safe_decode(os.path.abspath(options.experiment),
enc=sys.getfilesystemencoding())
# In debug mode, don't try to catch any exceptions
if options.debug:
exp = Experiment(u"Experiment", experiment,
exp = Experiment("Experiment", experiment,
experiment_path=experiment_path)
exp.set_subject(options.subject)
exp.var.fullscreen = options.fullscreen
Expand All @@ -278,17 +279,17 @@ def opensesamerun():
return
# Try to parse the experiment from a file
try:
exp = Experiment(u"Experiment", experiment,
exp = Experiment("Experiment", experiment,
experiment_path=experiment_path)
except Exception as e:
misc.messagebox(
u"OpenSesame Run",
"OpenSesame Run",
misc.strip_tags(e)
)
sys.exit()
# Set some options
exp.set_subject(options.subject)
exp.var.fullscreen = options.fullscreen
exp.var.fullscreen = 'yes' if options.fullscreen else 'no'
exp.logfile = logfile
# Initialize random number generator
import random
Expand All @@ -297,10 +298,10 @@ def opensesamerun():
try:
exp.run()
except Exception as e:
misc.messagebox(u"OpenSesame Run", misc.strip_tags(e))
misc.messagebox("OpenSesame Run", misc.strip_tags(e))
finally:
try:
exp.end()
except Exception as f:
misc.messagebox(u"OpenSesame Run", misc.strip_tags(f))
misc.messagebox("OpenSesame Run", misc.strip_tags(f))
exp.pool.clean_up()
49 changes: 20 additions & 29 deletions libqtopensesame/qtopensesamerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,19 @@


class QtOpenSesameRun(QtWidgets.QMainWindow, BaseComponent):

"""Implements the GUI for opensesamerun."""
"""Implements the GUI for opensesamerun.
Parameters
----------
options:
Command-line arguments passed to opensesamerun, as parsed by
`libopensesame.misc.opensesamerun_options()`.
parent: optional
"""
def __init__(self, options, parent=None):
"""
Constructor.
Arguments:
options -- Command-line arguments passed to opensesamerun, as
parsed by `libopensesame.misc.opensesamerun_options()`.
Keyword arguments:
parent -- A parent QWidget. (default=None)
"""
# Construct the parent
QtWidgets.QMainWindow.__init__(self, parent)
# Setup the UI
self.load_ui(u'misc.opensesamerun')
self.load_ui('misc.opensesamerun')
self.ui.button_run.clicked.connect(self.run)
self.ui.label_header.setText(
self.ui.label_header.text() % metadata.__version__)
Expand All @@ -52,34 +48,32 @@ def __init__(self, options, parent=None):
# Fill the GUI controls based on the options
self.ui.edit_experiment.setText(self.options.experiment)
self.ui.checkbox_fullscreen.setChecked(self.options.fullscreen)
self.ui.checkbox_pylink.setChecked(self.options.pylink)
self.ui.spinbox_subject_nr.setValue(int(self.options.subject))
self.ui.edit_logfile.setText(self.options.logfile)

def browse_experiment(self):
"""Locates the experiment file."""
file_type_filter = \
u"OpenSesame files (*.osexp *.opensesame.tar.gz *.opensesame);;OpenSesame script and file pool (*.opensesame.tar.gz);;OpenSesame script (*.opensesame)"
path = QtWidgets.QFileDialog.getOpenFileName(self,
u"Open experiment file", filter=file_type_filter)
"OpenSesame files (*.osexp *.opensesame.tar.gz *.opensesame);;OpenSesame script and file pool (*.opensesame.tar.gz);;OpenSesame script (*.opensesame)"
path = QtWidgets.QFileDialog.getOpenFileName(
self, "Open experiment file", filter=file_type_filter)
# In PyQt5, the QFileDialog.getOpenFileName returns a tuple instead of
# a string, of which the first position contains the path.
if isinstance(path, tuple):
path = path[0]
if path == u"":
if path == "":
return
self.ui.edit_experiment.setText(path)

def browse_logfile(self):
"""Locates the logfile. """
path = QtWidgets.QFileDialog.getSaveFileName(self,
u"Choose a location for the logfile")
"""Locates the logfile."""
path = QtWidgets.QFileDialog.getSaveFileName(
self, "Choose a location for the logfile")
# In PyQt5, the QFileDialog.getOpenFileName returns a tuple instead of
# a string, of which the first position contains the path.
if isinstance(path, tuple):
path = path[0]

if path == u"":
if path == "":
return
self.ui.edit_logfile.setText(path)

Expand All @@ -89,8 +83,7 @@ def show(self):
QtWidgets.QMainWindow.show(self)

def run(self):
"""
Does not actual run the experiment, but marks the application for
"""Does not actual run the experiment, but marks the application for
running later.
"""
self.run = True
Expand All @@ -102,15 +95,13 @@ def run(self):
self.ui.checkbox_custom_resolution.isChecked()
self.options.width = self.ui.spinbox_width.value()
self.options.height = self.ui.spinbox_height.value()
self.options.pylink = self.ui.checkbox_pylink.isChecked()
self.close()


# Alias for backwards compatibility
qtopensesamerun = QtOpenSesameRun


if __name__ == u'__main__':

if __name__ == '__main__':
from libqtopensesame import __main__
__main__.opensesamerun()
88 changes: 57 additions & 31 deletions libqtopensesame/resources/ui/misc/opensesamerun.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<height>389</height>
<width>419</width>
<height>339</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -19,14 +19,35 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>12</number>
</property>
<property name="topMargin">
<number>12</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>12</number>
</property>
<item>
<widget class="QWidget" name="widget_5" native="true">
<property name="styleSheet">
<string notr="true">background-color: #555753;
color: rgb(255, 255, 255);</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="margin">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
Expand Down Expand Up @@ -80,7 +101,16 @@ color: rgb(255, 255, 255);</string>
<item row="0" column="1">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -110,7 +140,16 @@ color: rgb(255, 255, 255);</string>
<item row="1" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -198,7 +237,16 @@ color: rgb(255, 255, 255);</string>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -303,42 +351,20 @@ color: rgb(255, 255, 255);</string>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>6</number>
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_pylink">
<property name="text">
<string>Enable PyLink module (required for the Eyelink plug-ins)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="margin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 000dd63

Please sign in to comment.