Exemplo n.º 1
0
    def init_edit_widget(self):
        """Initialize controls"""

        qtplugin.init_edit_widget(self, stretch=True)
        # Use auto-controls for most stuff
        self.add_line_edit_control(
            var=u'correct_response',
            label=_(u'Correct response'),
            info=_(u'Leave empty to use "correct_response"'))
        self.add_line_edit_control(
            var=u'allowed_responses',
            label=_(u'Allowed responses'),
            info=_(u'Separated by semicolons, e.g. "z;/"'))
        self.add_line_edit_control(var=u'timeout',
                                   label=_(u'Timeout'),
                                   info=_(u'In milliseconds or "infinite"'),
                                   validator=timeout_validator(self))
        self.add_combobox_control(var=u'event_type',
                                  label=_(u'Event type'),
                                  options=[u'keypress', u'keyrelease'])
        self.add_checkbox_control(u'flush', _(u'Flush pending key events'))
        # List available keys
        button_list_keys = QtWidgets.QPushButton(
            self.theme.qicon(u"help-about"), _(u"List available keys"))
        button_list_keys.setIconSize(QtCore.QSize(16, 16))
        button_list_keys.clicked.connect(self.list_keys)
        self.add_control(u'', button_list_keys)
Exemplo n.º 2
0
    def init_edit_widget(self):

        """
		desc:
			Initializes the widget.
		"""

        qtplugin.init_edit_widget(self, False)
        self.canvas = sketchpad_canvas(self)
        self.sketchpad_widget = sketchpad_widget(self)
        self.add_widget(self.sketchpad_widget)
        self.auto_add_widget(self.sketchpad_widget.ui.edit_duration, u"duration")
        self.first_refresh = True
Exemplo n.º 3
0
    def init_edit_widget(self):
        """
		desc:
			Initializes the widget.
		"""

        qtplugin.init_edit_widget(self, False)
        self.canvas = sketchpad_canvas(self)
        self.sketchpad_widget = sketchpad_widget(self)
        self.add_widget(self.sketchpad_widget)
        self.auto_add_widget(self.sketchpad_widget.ui.edit_duration,
                             u'duration')
        self.first_refresh = True
Exemplo n.º 4
0
    def init_edit_widget(self):
        """
		desc:
			Initializes the widget.
		"""

        qtplugin.init_edit_widget(self, False)
        self.canvas = sketchpad_canvas(self)
        self.sketchpad_widget = sketchpad_widget(self)
        self.add_widget(self.sketchpad_widget)
        self.auto_add_widget(self.sketchpad_widget.ui.edit_duration,
                             u'duration')
        self.auto_add_widget(self.sketchpad_widget.ui.checkbox_reset_variables,
                             u'reset_variables')
Exemplo n.º 5
0
	def init_edit_widget(self):

		"""
		desc:
			Initializes the widget.
		"""

		qtplugin.init_edit_widget(self, False)
		self.canvas = sketchpad_canvas(self)
		self.sketchpad_widget = sketchpad_widget(self)
		self.add_widget(self.sketchpad_widget)
		self.auto_add_widget(self.sketchpad_widget.ui.edit_duration,
			u'duration')
		self.auto_add_widget(self.sketchpad_widget.ui.checkbox_reset_variables,
			u'reset_variables')
Exemplo n.º 6
0
	def init_edit_widget(self):

		"""
		desc:
			Initializes the widget.
		"""

		qtplugin.init_edit_widget(self, False)
		self.canvas = sketchpad_canvas(self)
		self.sketchpad_widget = sketchpad_widget(self)
		self.add_widget(self.sketchpad_widget)
		self.auto_add_widget(self.sketchpad_widget.ui.edit_duration,
			u'duration')
		self.sketchpad_widget.ui.edit_duration.setValidator(
			duration_validator(self))
		self.first_refresh = True
		self._lock = False
Exemplo n.º 7
0
    def init_edit_widget(self):
        """See qtitem."""

        from QProgEdit import QTabManager

        qtplugin.init_edit_widget(self, stretch=False)
        self.qprogedit = QTabManager(cfg=cfg, runButton=True)
        self.qprogedit.execute.connect(self.main_window.console.execute)
        self.qprogedit.handlerButtonClicked.connect(self.apply_edit_changes)
        self.qprogedit.focusLost.connect(self.apply_edit_changes)
        self.qprogedit.cursorRowChanged.connect(self.apply_edit_changes)
        self.qprogedit.addTab(_(u'Prepare')).setLang(u'Python')
        self.qprogedit.addTab(_(u'Run')).setLang(u'Python')
        # Switch to the run phase, unless there is only content for the prepare
        # phase.
        if self.var._run == u'' and self.var._prepare != u'':
            self.qprogedit.setCurrentIndex(0)
        else:
            self.qprogedit.setCurrentIndex(1)
        self.edit_vbox.addWidget(self.qprogedit)
Exemplo n.º 8
0
	def init_edit_widget(self):

		"""See qtitem."""

		qtplugin.init_edit_widget(self)
		self.add_filepool_control(u'sample', _(u'Sound file'),
			info=_(u'In .ogg or .wav format'))
		self.add_doublespinbox_control(u'volume', _(u'Volume'),
			min_val=0, max_val=1, suffix=_(u' x original'))
		self.add_line_edit_control(u'pan', _(u'Panning'),
			info=_(u'Positive values toward the right; "left" or "right" for full panning'))
		self.add_doublespinbox_control(u'pitch', _(u'Pitch'), min_val=0,
			max_val=1000, suffix=_(u' x original'))
		self.add_spinbox_control(u'stop_after', _(u'Stop after'),
			min_val=0, max_val=10000000, suffix=_(u' ms'))
		self.add_spinbox_control(u'fade_in', _(u'Fade in'),
			min_val=0, max_val=10000000, suffix=_(u' ms'))
		self.add_line_edit_control(u'duration', _(u'Duration'),
			info=_(u'In milliseconds, "sound", "keypress", or "mouseclick"'),
			validator=duration_validator(self, default=u'sound'))
Exemplo n.º 9
0
    def init_edit_widget(self):

        """See qtitem."""

        qtplugin.init_edit_widget(self)
        self.add_combobox_control(u"osc", _(u"Waveform"), [u"sine", u"saw", u"square", u"white_noise"])
        self.add_line_edit_control(u"freq", _(u"Frequency"), info=_(u'In Hertz or as note, e.g. "A1"'))
        self.add_spinbox_control(u"attack", _(u"Attack"), min_val=0, max_val=10000000, suffix=_(u" ms"))
        self.add_spinbox_control(u"decay", _(u"Decay"), min_val=0, max_val=10000000, suffix=_(u" ms"))
        self.add_doublespinbox_control(u"volume", _(u"Volume"), min_val=0, max_val=1, suffix=_(u" x maximum"))
        self.add_line_edit_control(
            u"pan", _(u"Panning"), info=_(u'Positive values toward the right; "left" or "right" for full panning')
        )
        self.add_spinbox_control(u"length", _(u"Length"), min_val=0, max_val=10000000, suffix=_(u" ms"))
        self.add_line_edit_control(
            u"duration",
            _(u"Duration"),
            info=_(u'In milliseconds, "sound", "keypress", or "mouseclick"'),
            validator=duration_validator(self, default=u"sound"),
        )
Exemplo n.º 10
0
    def init_edit_widget(self):
        """See qtitem."""

        qtplugin.init_edit_widget(self)
        self.add_combobox_control(u'osc', _(u'Waveform'),
                                  [u'sine', u'saw', u'square', u'white_noise'])
        self.add_line_edit_control(u'freq',
                                   _(u'Frequency'),
                                   info=_(u'In Hertz or as note, e.g. "A1"'))
        self.add_spinbox_control(u'attack',
                                 _(u'Attack'),
                                 min_val=0,
                                 max_val=10000000,
                                 suffix=_(u' ms'))
        self.add_spinbox_control(u'decay',
                                 _(u'Decay'),
                                 min_val=0,
                                 max_val=10000000,
                                 suffix=_(u' ms'))
        self.add_doublespinbox_control(u'volume',
                                       _(u'Volume'),
                                       min_val=0,
                                       max_val=1,
                                       suffix=_(u' x maximum'))
        self.add_line_edit_control(
            u'pan',
            _(u'Panning'),
            info=
            _(u'Positive values toward the right; "left" or "right" for full panning'
              ))
        self.add_spinbox_control(u'length',
                                 _(u'Length'),
                                 min_val=0,
                                 max_val=10000000,
                                 suffix=_(u' ms'))
        self.add_line_edit_control(
            u'duration',
            _(u'Duration'),
            info=_(u'In milliseconds, "sound", "keypress", or "mouseclick"'),
            validator=duration_validator(self, default=u'sound'))
Exemplo n.º 11
0
    def init_edit_widget(self):
        """See qtitem."""

        qtplugin.init_edit_widget(self)
        self.add_filepool_control(u'sample',
                                  _(u'Sound file'),
                                  info=_(u'In .ogg or .wav format'))
        self.add_doublespinbox_control(u'volume',
                                       _(u'Volume'),
                                       min_val=0,
                                       max_val=1,
                                       suffix=_(u' x original'))
        self.add_line_edit_control(
            u'pan',
            _(u'Panning'),
            info=
            _(u'Positive values toward the right; "left" or "right" for full panning'
              ))
        self.add_doublespinbox_control(u'pitch',
                                       _(u'Pitch'),
                                       min_val=0,
                                       max_val=1000,
                                       suffix=_(u' x original'))
        self.add_spinbox_control(u'stop_after',
                                 _(u'Stop after'),
                                 min_val=0,
                                 max_val=10000000,
                                 suffix=_(u' ms'))
        self.add_spinbox_control(u'fade_in',
                                 _(u'Fade in'),
                                 min_val=0,
                                 max_val=10000000,
                                 suffix=_(u' ms'))
        self.add_line_edit_control(
            u'duration',
            _(u'Duration'),
            info=_(u'In milliseconds, "sound", "keypress", or "mouseclick"'),
            validator=duration_validator(self, default=u'sound'))
Exemplo n.º 12
0
	def init_edit_widget(self):

		"""See qtitem."""

		qtplugin.init_edit_widget(self)
		self.add_combobox_control(u'osc', _(u'Waveform'),
			[u'sine', u'saw', u'square', u'white_noise'])
		self.add_line_edit_control(u'freq',
			_(u'Frequency'),
			info=_(u'In Hertz or as note, e.g. "A1"'))
		self.add_spinbox_control(u'attack', _(u'Attack'),
			min_val=0, max_val=10000000, suffix=_(u' ms'))
		self.add_spinbox_control(u'decay', _(u'Decay'),
			min_val=0, max_val=10000000, suffix=_(u' ms'))
		self.add_doublespinbox_control(u'volume', _(u'Volume'),
			min_val=0, max_val=1, suffix=_(u' x maximum'))
		self.add_line_edit_control(u'pan', _(u'Panning'),
			info=_(u'Positive values toward the right; "left" or "right" for full panning'))
		self.add_spinbox_control(u'length', _(u'Length'),
			min_val=0, max_val=10000000, suffix=_(u' ms'))
		self.add_line_edit_control(u'duration', _(u'Duration'),
			info=_(u'In milliseconds, "sound", "keypress", or "mouseclick"'),
			validator=duration_validator(self, default=u'sound'))
Exemplo n.º 13
0
    def init_edit_widget(self):
        """
		desc:
			Initialize controls.
		"""

        qtplugin.init_edit_widget(self, stretch=True)
        self.add_line_edit_control(
            var=u'correct_response',
            label=_(u'Correct response'),
            info=_(u'Leave empty to use "correct_response"'))
        self.add_line_edit_control(
            var=u'allowed_responses',
            label=_(u'Allowed responses'),
            info=_(
                u'Separated by semicolons, e.g. "left_button;right_button"'))
        self.add_line_edit_control(var=u'timeout',
                                   label=_(u'Timeout'),
                                   tooltip=_(u'In milliseconds or "infinite"'),
                                   validator=timeout_validator(self))
        self._combobox_sketchpad = item_combobox(
            self.main_window,
            filter_fnc=lambda item: isinstance(self.experiment.items[item],
                                               feedpad))
        self._combobox_sketchpad.activated.connect(self.apply_edit_changes)
        self.auto_combobox[u'linked_sketchpad'] = self._combobox_sketchpad
        self.add_control(label=_(u'Linked sketchpad'),
                         widget=self._combobox_sketchpad,
                         info=_('Elements define regions of interest'))
        self.add_combobox_control(var=u'event_type',
                                  label=_(u'Event type'),
                                  options=[u'mouseclick', u'mouserelease'])
        self.add_checkbox_control(var=u'show_cursor',
                                  label=_(u'Visible mouse cursor'))
        self.add_checkbox_control(var=u'flush',
                                  label=_(u'Flush pending mouse clicks'))
Exemplo n.º 14
0
    def init_edit_widget(self):
        """Construct the GUI controls based on info.yaml"""

        qtplugin.init_edit_widget(self, False)
        self.info = plugins.plugin_properties(self.item_type, _type=u'plugins')
        # Some options are required. Which options are requires depends on the
        # specific widget.
        required  = [
         ([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
          u'line_edit', u'spinbox', u'text'], [u'label']),
         ([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
          u'line_edit', u'spinbox'], [u'var']),
         ([u'spinbox', u'slider'], [u'min_val', u'max_val']),
         ([u'combobox'], [u'options']),
         ]
        # Keywords are optional parameters that are set to some default if they
        # are not specified.
        keywords = {
            u'tooltip': None,
            u'min_width': None,
            u'prefix': u'',
            u'suffix': u'',
            u'left_label': u'min.',
            u'right_label': u'max.',
            u'syntax': False
        }
        # This indicates whether we should pad the controls with a stretch at
        # the end.
        need_stretch = True
        for c in self.info[u'controls']:
            # Check whether all required options have been specified
            if u'type' not in c:
                raise Exception(_( \
                 u'You must specify "type" for %s controls in info.yaml') \
                 % option)
            for types, options in required:
                if c[u'type'] in types:
                    for option in options:
                        if option not in c:
                            raise Exception(_( \
                             u'You must specify "%s" for %s controls in info.yaml') \
                             % (option, c[u'type']))
            # Set missing keywords to None
            for keyword, default in keywords.iteritems():
                if keyword not in c:
                    c[keyword] = default
            # Parse checkbox
            if c[u'type'] == u'checkbox':
                widget = self.add_checkbox_control(c[u'var'], c[u'label'], \
                 tooltip=c[u'tooltip'])
            # Parse color_edit
            elif c[u'type'] == u'color_edit':
                widget = self.add_color_edit_control(c[u'var'], c[u'label'], \
                 tooltip=c[u'tooltip'], min_width=c[u'min_width'])
            # Parse combobox
            elif c[u'type'] == u'combobox':
                widget = self.add_combobox_control(c[u'var'], c[u'label'], \
                 c[u'options'], tooltip=c[u'tooltip'])
            # Parse editor
            elif c[u'type'] == u'editor':
                widget = self.add_editor_control(c[u'var'], c[u'label'], \
                 syntax=c[u'syntax'], tooltip=c[u'tooltip'])
                need_stretch = False
            # Parse filepool
            elif c[u'type'] == u'filepool':
                widget = self.add_filepool_control(c[u'var'], c[u'label'], \
                 tooltip=c[u'tooltip'])
            # Parse line_edit
            elif c[u'type'] == u'line_edit':
                widget = self.add_line_edit_control(c[u'var'], c[u'label'], \
                 tooltip=c[u'tooltip'], min_width=c[u'min_width'])
            # Parse spinbox
            elif c[u'type'] == u'spinbox':
                widget = self.add_spinbox_control(c[u'var'], c[u'label'], \
                 c[u'min_val'], c[u'max_val'], prefix=c[u'prefix'], suffix= \
                 c[u'suffix'], tooltip=c[u'tooltip'])
            # Parse slider
            elif c[u'type'] == u'slider':
                widget = self.add_slider_control(c[u'var'], c[u'label'], \
                 c[u'min_val'], c[u'max_val'], left_label=c[u'left_label'], \
                 right_label=c[u'right_label'], tooltip=c[u'tooltip'])
            # Parse text
            elif c[u'type'] == u'text':
                widget = self.add_text(c[u'label'])
            else:
                raise Exception(_(u'"%s" is not a valid qtautoplugin control') \
                 % controls[u'type'])
            # Add the widget as an item property when the 'name' option is
            # specified.
            if u'name' in c:
                if hasattr(self, c[u'name']):
                    raise Exception(_( \
                     u'Name "%s" is already taken in qtautoplugin control') \
                     % c[u'name'])
                setattr(self, c[u'name'], widget)
        if need_stretch:
            self.add_stretch()
        self.lock = True
Exemplo n.º 15
0
    def init_edit_widget(self):

        """Construct the GUI controls based on info.yaml"""

        qtplugin.init_edit_widget(self, False)
        self.info = plugins.plugin_properties(self.item_type, _type=u"plugins")
        # Some options are required. Which options are requires depends on the
        # specific widget.
        required = [
            (
                [u"checkbox", u"color_edit", u"combobox", u"editor", u"filepool", u"line_edit", u"spinbox", u"text"],
                [u"label"],
            ),
            ([u"checkbox", u"color_edit", u"combobox", u"editor", u"filepool", u"line_edit", u"spinbox"], [u"var"]),
            ([u"spinbox", u"slider"], [u"min_val", u"max_val"]),
            ([u"combobox"], [u"options"]),
        ]
        # Keywords are optional parameters that are set to some default if they
        # are not specified.
        keywords = {
            u"tooltip": None,
            u"min_width": None,
            u"prefix": u"",
            u"suffix": u"",
            u"left_label": u"min.",
            u"right_label": u"max.",
            u"syntax": False,
        }
        # This indicates whether we should pad the controls with a stretch at
        # the end.
        need_stretch = True
        for c in self.info[u"controls"]:
            # Check whether all required options have been specified
            if u"type" not in c:
                raise osexception(_(u'You must specify "type" for %s controls in info.yaml') % option)
            for types, options in required:
                if c[u"type"] in types:
                    for option in options:
                        if option not in c:
                            raise osexception(
                                _(u'You must specify "%s" for %s controls in info.yaml') % (option, c[u"type"])
                            )
            if u"var" in c and not self.syntax.valid_var_name(c[u"var"]):
                raise osexception(
                    _(u"Invalid variable name (%s) specified in %s plugin info") % (c[u"var"], self.item_type)
                )
                # Set missing keywords to None
            for keyword, default in keywords.items():
                if keyword not in c:
                    c[keyword] = default
                    # Parse checkbox
            if c[u"type"] == u"checkbox":
                widget = self.add_checkbox_control(c[u"var"], c[u"label"], tooltip=c[u"tooltip"])
                # Parse color_edit
            elif c[u"type"] == u"color_edit":
                widget = self.add_color_edit_control(
                    c[u"var"], c[u"label"], tooltip=c[u"tooltip"], min_width=c[u"min_width"]
                )
                # Parse combobox
            elif c[u"type"] == u"combobox":
                widget = self.add_combobox_control(c[u"var"], c[u"label"], c[u"options"], tooltip=c[u"tooltip"])
                # Parse editor
            elif c[u"type"] == u"editor":
                widget = self.add_editor_control(c[u"var"], c[u"label"], syntax=c[u"syntax"], tooltip=c[u"tooltip"])
                need_stretch = False
                # Parse filepool
            elif c[u"type"] == u"filepool":
                widget = self.add_filepool_control(c[u"var"], c[u"label"], tooltip=c[u"tooltip"])
                # Parse line_edit
            elif c[u"type"] == u"line_edit":
                widget = self.add_line_edit_control(
                    c[u"var"], c[u"label"], tooltip=c[u"tooltip"], min_width=c[u"min_width"]
                )
                # Parse spinbox
            elif c[u"type"] == u"spinbox":
                widget = self.add_spinbox_control(
                    c[u"var"],
                    c[u"label"],
                    c[u"min_val"],
                    c[u"max_val"],
                    prefix=c[u"prefix"],
                    suffix=c[u"suffix"],
                    tooltip=c[u"tooltip"],
                )
                # Parse slider
            elif c[u"type"] == u"slider":
                widget = self.add_slider_control(
                    c[u"var"],
                    c[u"label"],
                    c[u"min_val"],
                    c[u"max_val"],
                    left_label=c[u"left_label"],
                    right_label=c[u"right_label"],
                    tooltip=c[u"tooltip"],
                )
                # Parse text
            elif c[u"type"] == u"text":
                widget = self.add_text(c[u"label"])
            else:
                raise Exception(_(u'"%s" is not a valid qtautoplugin control') % controls[u"type"])
                # Add an optional validator
            if u"validator" in c:
                try:
                    validator = getattr(validators, u"%s_validator" % c[u"validator"])
                except:
                    raise osexception(u"Invalid validator: %s" % c[u"validator"])
                widget.setValidator(validator(self.main_window))
                # Add the widget as an item property when the 'name' option is
                # specified.
            if u"name" in c:
                if hasattr(self, c[u"name"]):
                    raise Exception(_(u'Name "%s" is already taken in qtautoplugin control') % c[u"name"])
                setattr(self, c[u"name"], widget)
        if need_stretch:
            self.add_stretch()
        self.lock = True
Exemplo n.º 16
0
    def init_edit_widget(self):
        """Construct the GUI controls based on info.yaml"""

        qtplugin.init_edit_widget(self, False)
        item_type_translate = translation_context(self.item_type,
                                                  category=u'plugin')
        self.info = plugins.plugin_properties(self.item_type, _type=u'plugins')
        # Process the help url, if specified
        if u'help' in self.info:
            self.help_url = self.info[u'help']
        # Some options are required. Which options are requires depends on the
        # specific widget.
        required  = [
         ([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
          u'line_edit', u'spinbox', u'text'], [u'label']),
         ([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
          u'line_edit', u'spinbox'], [u'var']),
         ([u'spinbox', u'slider'], [u'min_val', u'max_val']),
         ([u'combobox'], [u'options']),
         ]
        # Keywords are optional parameters that are set to some default if they
        # are not specified.
        keywords = {
            u'info': None,
            u'min_width': None,
            u'prefix': u'',
            u'suffix': u'',
            u'left_label': u'min.',
            u'right_label': u'max.',
            u'syntax': False
        }
        # This indicates whether we should pad the controls with a stretch at
        # the end.
        need_stretch = True
        for c in self.info[u'controls']:
            # Check whether all required options have been specified
            if u'type' not in c:
                raise osexception(
                 _(u'You must specify "type" for %s controls in info.yaml') \
                 % option)
            for types, options in required:
                if c[u'type'] in types:
                    for option in options:
                        if option not in c:
                            raise osexception(
                             _(u'You must specify "%s" for %s controls in info.yaml') \
                             % (option, c[u'type']))
            if u'var' in c and not self.syntax.valid_var_name(c[u'var']):
                raise osexception(
                    _(u'Invalid variable name (%s) specified in %s plugin info'
                      ) % (c[u'var'], self.item_type))
            # Set missing keywords to None
            for keyword, default in keywords.items():
                if keyword not in c:
                    c[keyword] = default
            # Translate translatable fields
            c[u'label'] = item_type_translate(c[u'label'])
            if c[u'info'] is not None:
                c[u'info'] = item_type_translate(c[u'info'])
            # Parse checkbox
            if c[u'type'] == u'checkbox':
                widget = self.add_checkbox_control(c[u'var'],
                                                   c[u'label'],
                                                   info=c[u'info'])
            # Parse color_edit
            elif c[u'type'] == u'color_edit':
                widget = self.add_color_edit_control(c[u'var'],
                                                     c[u'label'],
                                                     info=c[u'info'],
                                                     min_width=c[u'min_width'])
            # Parse combobox
            elif c[u'type'] == u'combobox':
                widget = self.add_combobox_control(c[u'var'],
                                                   c[u'label'],
                                                   c[u'options'],
                                                   info=c[u'info'])
            # Parse editor
            elif c[u'type'] == u'editor':
                widget = self.add_editor_control(c[u'var'],
                                                 c[u'label'],
                                                 syntax=c[u'syntax'])
                need_stretch = False
            # Parse filepool
            elif c[u'type'] == u'filepool':
                widget = self.add_filepool_control(c[u'var'],
                                                   c[u'label'],
                                                   info=c[u'info'])
            # Parse line_edit
            elif c[u'type'] == u'line_edit':
                widget = self.add_line_edit_control(c[u'var'],
                                                    c[u'label'],
                                                    info=c[u'info'],
                                                    min_width=c[u'min_width'])
            # Parse spinbox
            elif c[u'type'] == u'spinbox':
                widget = self.add_spinbox_control(c[u'var'],
                                                  c[u'label'],
                                                  c[u'min_val'],
                                                  c[u'max_val'],
                                                  prefix=c[u'prefix'],
                                                  suffix=c[u'suffix'],
                                                  info=c[u'info'])
            # Parse slider
            elif c[u'type'] == u'slider':
                widget = self.add_slider_control(c[u'var'],
                                                 c[u'label'],
                                                 c[u'min_val'],
                                                 c[u'max_val'],
                                                 left_label=c[u'left_label'],
                                                 right_label=c[u'right_label'],
                                                 info=c[u'info'])
            # Parse text
            elif c[u'type'] == u'text':
                widget = self.add_text(c[u'label'])
            else:
                raise Exception(_(u'"%s" is not a valid qtautoplugin control') \
                 % controls[u'type'])
            # Add an optional validator
            if u'validator' in c:
                try:
                    validator = getattr(validators,
                                        u'%s_validator' % c[u'validator'])
                except:
                    raise osexception(u'Invalid validator: %s' %
                                      c[u'validator'])
                widget.setValidator(validator(self.main_window))
            # Add the widget as an item property when the 'name' option is
            # specified.
            if u'name' in c:
                if hasattr(self, c[u'name']):
                    raise Exception(_(u'Name "%s" is already taken in qtautoplugin control') \
                     % c[u'name'])
                setattr(self, c[u'name'], widget)
        if need_stretch:
            self.add_stretch()
        self.lock = True
Exemplo n.º 17
0
	def init_edit_widget(self):

		"""Construct the GUI controls based on info.json"""

		# Import json only when required, as it is not necessary for the
		# runtime environment and may be not available on all platforms,
		# notably Android.
		import json
	
		self.lock = True
		qtplugin.init_edit_widget(self, False)		
		# Load info.json
		json_path = os.path.join(self.plugin_folder, u'info.json')
		self.json = json.load(open(json_path))				
		# Some options are required. Which options are requires depends on the
		# specific widget.
		required  = [
			([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
				u'line_edit', u'spinbox', u'text'], [u'label']),
			([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
				u'line_edit', u'spinbox'], [u'var']),
			([u'spinbox', u'slider'], [u'min_val', u'max_val']),
			([u'combobox'], [u'options']),
			]
		# Keywords are optional parameters that are set to some default if they
		# are not specified.
		keywords = {
			u'tooltip' : None,
			u'min_width' : None,
			u'prefix' : u'',
			u'suffix' : u'',
			u'left_label' : u'min.',
			u'right_label' : u'max.',
			u'syntax' : False
			}
		# This indicates whether we should pad the controls with a stretch at
		# the end.
		need_stretch = True
		for c in self.json[u'controls']:			
			# Check whether all required options have been specified
			if u'type' not in c:
				raise Exception(_( \
					u'You must specify "type" for %s controls in info.json') \
					% option)
			for types, options in required:
				if c[u'type'] in types:
					for option in options:
						if option not in c:
							raise Exception(_( \
								u'You must specify "%s" for %s controls in info.json') \
								% (option, c[u'type']))
			# Set missing keywords to None
			for keyword, default in keywords.iteritems():
				if keyword not in c:
					c[keyword] = default
			# Parse checkbox
			if c[u'type'] == u'checkbox':
				widget = self.add_checkbox_control(c[u'var'], c[u'label'], \
					tooltip=c[u'tooltip'])
			# Parse color_edit
			elif c[u'type'] == u'color_edit':
				widget = self.add_color_edit_control(c[u'var'], c[u'label'], \
					tooltip=c[u'tooltip'], min_width=c[u'min_width'])
			# Parse combobox
			elif c[u'type'] == u'combobox':
				widget = self.add_combobox_control(c[u'var'], c[u'label'], \
					c[u'options'], tooltip=c[u'tooltip'])
			# Parse editor
			elif c[u'type'] == u'editor':
				widget = self.add_editor_control(c[u'var'], c[u'label'], \
					syntax=c[u'syntax'], tooltip=c[u'tooltip'])
				need_stretch = False
			# Parse filepool
			elif c[u'type'] == u'filepool':
				widget = self.add_filepool_control(c[u'var'], c[u'label'], \
					tooltip=c[u'tooltip'])
			# Parse line_edit
			elif c[u'type'] == u'line_edit':
				widget = self.add_line_edit_control(c[u'var'], c[u'label'], \
					tooltip=c[u'tooltip'], min_width=c[u'min_width'])
			# Parse spinbox
			elif c[u'type'] == u'spinbox':
				widget = self.add_spinbox_control(c[u'var'], c[u'label'], \
					c[u'min_val'], c[u'max_val'], prefix=c[u'prefix'], suffix= \
					c[u'suffix'], tooltip=c[u'tooltip'])
			# Parse slider
			elif c[u'type'] == u'slider':
				widget = self.add_slider_control(c[u'var'], c[u'label'], \
					c[u'min_val'], c[u'max_val'], left_label=c[u'left_label'], \
					right_label=c[u'right_label'], tooltip=c[u'tooltip'])
			# Parse text
			elif c[u'type'] == u'text':
				widget = self.add_text(c[u'label'])
			else:
				raise Exception(_(u'"%s" is not a valid qtautoplugin control') \
					% controls[u'type'])
			# Add the widget as an item property when the 'name' option is
			# specified.
			if u'name' in c:
				if hasattr(self, c[u'name']):
					raise Exception(_( \
						u'Name "%s" is already taken in qtautoplugin control') \
						% c[u'name'])
				setattr(self, c[u'name'], widget)
		if need_stretch:
			self.add_stretch()
		self.lock = True
Exemplo n.º 18
0
	def init_edit_widget(self):

		"""Construct the GUI controls based on info.yaml"""

		qtplugin.init_edit_widget(self, False)
		item_type_translate = translation_context(self.item_type,
			category=u'plugin')
		self.info = plugins.plugin_properties(self.item_type, _type=u'plugins')
		# Some options are required. Which options are requires depends on the
		# specific widget.
		required  = [
			([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
				u'line_edit', u'spinbox', u'text'], [u'label']),
			([u'checkbox', u'color_edit', u'combobox', u'editor', u'filepool', \
				u'line_edit', u'spinbox'], [u'var']),
			([u'spinbox', u'slider'], [u'min_val', u'max_val']),
			([u'combobox'], [u'options']),
			]
		# Keywords are optional parameters that are set to some default if they
		# are not specified.
		keywords = {
			u'info' : None,
			u'min_width' : None,
			u'prefix' : u'',
			u'suffix' : u'',
			u'left_label' : u'min.',
			u'right_label' : u'max.',
			u'syntax' : False
			}
		# This indicates whether we should pad the controls with a stretch at
		# the end.
		need_stretch = True
		for c in self.info[u'controls']:
			# Check whether all required options have been specified
			if u'type' not in c:
				raise osexception(
					_(u'You must specify "type" for %s controls in info.yaml') \
					% option)
			for types, options in required:
				if c[u'type'] in types:
					for option in options:
						if option not in c:
							raise osexception(
								_(u'You must specify "%s" for %s controls in info.yaml') \
								% (option, c[u'type']))
			if u'var' in c and not self.syntax.valid_var_name(c[u'var']):
				raise osexception(
					_(u'Invalid variable name (%s) specified in %s plugin info') %
					(c[u'var'], self.item_type))
			# Set missing keywords to None
			for keyword, default in keywords.items():
				if keyword not in c:
					c[keyword] = default
			# Translate translatable fields
			c[u'label'] = item_type_translate(c[u'label'])
			if c[u'info'] is not None:
				c[u'info'] = item_type_translate(c[u'info'])
			# Parse checkbox
			if c[u'type'] == u'checkbox':
				widget = self.add_checkbox_control(c[u'var'], c[u'label'],
					info=c[u'info'])
			# Parse color_edit
			elif c[u'type'] == u'color_edit':
				widget = self.add_color_edit_control(c[u'var'], c[u'label'],
					info=c[u'info'], min_width=c[u'min_width'])
			# Parse combobox
			elif c[u'type'] == u'combobox':
				widget = self.add_combobox_control(c[u'var'], c[u'label'],
					c[u'options'], info=c[u'info'])
			# Parse editor
			elif c[u'type'] == u'editor':
				widget = self.add_editor_control(c[u'var'], c[u'label'],
					syntax=c[u'syntax'])
				need_stretch = False
			# Parse filepool
			elif c[u'type'] == u'filepool':
				widget = self.add_filepool_control(c[u'var'], c[u'label'],
					info=c[u'info'])
			# Parse line_edit
			elif c[u'type'] == u'line_edit':
				widget = self.add_line_edit_control(c[u'var'], c[u'label'],
					info=c[u'info'], min_width=c[u'min_width'])
			# Parse spinbox
			elif c[u'type'] == u'spinbox':
				widget = self.add_spinbox_control(c[u'var'], c[u'label'],
					c[u'min_val'], c[u'max_val'], prefix=c[u'prefix'],
					suffix=c[u'suffix'], info=c[u'info'])
			# Parse slider
			elif c[u'type'] == u'slider':
				widget = self.add_slider_control(c[u'var'], c[u'label'],
					c[u'min_val'], c[u'max_val'], left_label=c[u'left_label'],
					right_label=c[u'right_label'], info=c[u'info'])
			# Parse text
			elif c[u'type'] == u'text':
				widget = self.add_text(c[u'label'])
			else:
				raise Exception(_(u'"%s" is not a valid qtautoplugin control') \
					% controls[u'type'])
			# Add an optional validator
			if u'validator' in c:
				try:
					validator = getattr(validators,
						u'%s_validator' % c[u'validator'])
				except:
					raise osexception(
						u'Invalid validator: %s' % c[u'validator'])
				widget.setValidator(validator(self.main_window))
			# Add the widget as an item property when the 'name' option is
			# specified.
			if u'name' in c:
				if hasattr(self, c[u'name']):
					raise Exception(_(u'Name "%s" is already taken in qtautoplugin control') \
						% c[u'name'])
				setattr(self, c[u'name'], widget)
		if need_stretch:
			self.add_stretch()
		self.lock = True