Example #1
0
    def runTest(self):
        """
		desc:
			Checks various correct and incorrect color specifications.
		"""

        for colorspec in [
                u'white',
                u'#FFFFFF',
                u'#ffffff',
                u'#FFF',
                u'#fff',
            (255, 255, 255),
                255,
                u'rgb(255,255,255)',
                u'rgb( 255 , 255 , 255 )',
                u'rgb(100%,100%,100%)',
                u'rgb( 100% , 100% , 100% )',
        ]:
            print(u'Checking correct %s (%s)' %
                  (str(colorspec), type(colorspec)))
            self.assertEqual(u'#ffffff', color.to_hex(colorspec))

        for colorspec in [
                u'wihte',
                u'#FFFFF',
                u'#FFFFG',
            (255, 255, 255.0),
            (255, 255, 255, 255),
                255.0,
                u'rgb(255,255)',
                u'rgb(255,255,255,255)',
                u'rgb(100%,100%,100)',
        ]:
            print(u'Checking incorrect %s (%s)' \
             % (str(colorspec), type(colorspec)))
            self.assertRaises(osexception, color.to_hex, colorspec)
Example #2
0
    def runTest(self):

        """
		desc:
			Checks various correct and incorrect color specifications.
		"""

        for colorspec in [
            u"white",
            u"#FFFFFF",
            u"#ffffff",
            u"#FFF",
            u"#fff",
            (255, 255, 255),
            255,
            u"rgb(255,255,255)",
            u"rgb( 255 , 255 , 255 )",
            u"rgb(100%,100%,100%)",
            u"rgb( 100% , 100% , 100% )",
        ]:
            print(u"Checking correct %s (%s)" % (str(colorspec), type(colorspec)))
            self.assertEqual(u"#ffffff", color.to_hex(colorspec))

        for colorspec in [
            u"wihte",
            u"#FFFFF",
            u"#FFFFG",
            (255, 255, 255.0),
            (255, 255, 255, 255),
            255.0,
            u"rgb(255,255)",
            u"rgb(255,255,255,255)",
            u"rgb(100%,100%,100)",
        ]:
            print(u"Checking incorrect %s (%s)" % (str(colorspec), type(colorspec)))
            self.assertRaises(osexception, color.to_hex, colorspec)
Example #3
0
	def apply_changes(self):

		"""
		desc:
			Applies changes to the general tab.
		"""

		# Skip if the general tab is locked and lock it otherwise
		if self.lock:
			return
		self.lock = True

		self.main_window.set_busy(True)
		self.main_window.extension_manager.fire(u'prepare_change_experiment')
		# Set the title and the description
		title = self.experiment.syntax.sanitize(
			self.header_widget.edit_name.text())
		if title != self.experiment.var.title:
			self.experiment.var.title = title
			self.experiment.build_item_tree()
		desc = self.experiment.syntax.sanitize(
			self.header_widget.edit_desc.text())
		self.experiment.var.description = desc

		# Set the backend
		if self.ui.combobox_backend.isEnabled():
			i = self.ui.combobox_backend.currentIndex()
			_backend = list(backend.backend_info(self.experiment).values())[i]
			self.experiment.var.canvas_backend = _backend[u"canvas"]
			self.experiment.var.keyboard_backend = _backend[u"keyboard"]
			self.experiment.var.mouse_backend = _backend[u"mouse"]
			self.experiment.var.sampler_backend = _backend[u"sampler"]
			self.experiment.var.clock_backend = _backend[u"clock"]
			self.experiment.var.color_backend = _backend[u"color"]
		else:
			debug.msg(
				u'not setting back-end, because a custom backend is selected')

		# Set the display width
		width = self.ui.spinbox_width.value()
		height = self.ui.spinbox_height.value()
		if self.experiment.var.width != width or \
			self.experiment.var.height != height:
			self.main_window.update_resolution(width, height)

		# Set the foreground color
		foreground = self.experiment.syntax.sanitize(self.ui.edit_foreground.text())
		refs = []
		try:
			refs = self.experiment.get_refs(foreground)
			color.to_hex(foreground)
		except Exception as e:
			if refs == []:
				self.experiment.notify(e)
				foreground = self.experiment.var.foreground
				self.ui.edit_foreground.setText(foreground)
		self.experiment.var.foreground = foreground

		# Set the background color
		background = self.experiment.syntax.sanitize(self.ui.edit_background.text())
		refs = []
		try:
			refs = self.experiment.get_refs(background)
			color.to_hex(background)
		except Exception as e:
			if refs == []:
				self.experiment.notify(e)
				background = self.experiment.var.background
				self.ui.edit_background.setText(background)
		self.experiment.var.background = foreground
		self.experiment.var.background = background

		# Set the font
		self.experiment.var.font_family = self.ui.widget_font.family
		self.experiment.var.font_size = self.ui.widget_font.size
		self.experiment.var.font_italic = self.ui.widget_font.italic
		self.experiment.var.font_bold = self.ui.widget_font.bold
		# Set bi-directional text
		self.experiment.var.bidi = self.ui.checkbox_bidi.isChecked()
		self.experiment.var.uniform_coordinates = \
			self.ui.checkbox_uniform_coordinates.isChecked()
		self.check_bidi()
		# Refresh the interface and unlock the general tab
		self.lock = False
		self.main_window.extension_manager.fire(u'change_experiment')
		self.main_window.set_busy(False)