def set_background_page_values(self): """ Handle the display and state of the Background page. """ if self.theme.background_type == BackgroundType.to_string( BackgroundType.Solid): self.color_button.color = self.theme.background_color self.setField('background_type', 0) elif self.theme.background_type == BackgroundType.to_string( BackgroundType.Gradient): self.gradient_start_button.color = self.theme.background_start_color self.gradient_end_button.color = self.theme.background_end_color self.setField('background_type', 1) elif self.theme.background_type == BackgroundType.to_string( BackgroundType.Image): self.image_color_button.color = self.theme.background_border_color self.image_file_edit.setText(self.theme.background_filename) self.setField('background_type', 2) elif self.theme.background_type == BackgroundType.to_string( BackgroundType.Transparent): self.setField('background_type', 3) if self.theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Horizontal): self.setField('gradient', 0) elif self.theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Vertical): self.setField('gradient', 1) elif self.theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Circular): self.setField('gradient', 2) elif self.theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.LeftTop): self.setField('gradient', 3) else: self.setField('gradient', 4)
def set_background_page_values(self): """ Handle the display and state of the Background page. """ if self.theme.background_type == BackgroundType.to_string(BackgroundType.Solid): self.color_button.color = self.theme.background_color self.setField('background_type', 0) elif self.theme.background_type == BackgroundType.to_string(BackgroundType.Gradient): self.gradient_start_button.color = self.theme.background_start_color self.gradient_end_button.color = self.theme.background_end_color self.setField('background_type', 1) elif self.theme.background_type == BackgroundType.to_string(BackgroundType.Image): self.image_color_button.color = self.theme.background_border_color self.image_file_edit.setText(self.theme.background_filename) self.setField('background_type', 2) elif self.theme.background_type == BackgroundType.to_string(BackgroundType.Video): self.video_color_button.color = self.theme.background_border_color self.video_file_edit.setText(self.theme.background_filename) self.setField('background_type', 4) elif self.theme.background_type == BackgroundType.to_string(BackgroundType.Transparent): self.setField('background_type', 3) if self.theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Horizontal): self.setField('gradient', 0) elif self.theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Vertical): self.setField('gradient', 1) elif self.theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Circular): self.setField('gradient', 2) elif self.theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.LeftTop): self.setField('gradient', 3) else: self.setField('gradient', 4)
def test_background_gradient_type_from_string(self): """ Test the from_string method of :class:`BackgroundGradientType` """ # GIVEN: The BackgroundGradientType strings background_gradient_horizontal = 'horizontal' background_gradient_vertical = 'vertical' background_gradient_circular = 'circular' background_gradient_left_top = 'leftTop' background_gradient_left_bottom = 'leftBottom' # WHEN: Calling BackgroundGradientType.from_string # THEN: The enum equivalents should be returned assert BackgroundGradientType.from_string( background_gradient_horizontal ) == BackgroundGradientType.Horizontal assert BackgroundGradientType.from_string( background_gradient_vertical) == BackgroundGradientType.Vertical assert BackgroundGradientType.from_string( background_gradient_circular) == BackgroundGradientType.Circular assert BackgroundGradientType.from_string( background_gradient_left_top) == BackgroundGradientType.LeftTop assert BackgroundGradientType.from_string( background_gradient_left_bottom ) == BackgroundGradientType.LeftBottom
def build_background_css(item, width): """ Build the background css :param item: Service Item containing theme and location information :param width: """ width = int(width) // 2 theme = item.theme_data background = 'background-color: black' if theme: if theme.background_type == BackgroundType.to_string(BackgroundType.Transparent): background = '' elif theme.background_type == BackgroundType.to_string(BackgroundType.Solid): background = 'background-color: {theme}'.format(theme=theme.background_color) else: if theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Horizontal): background = 'background: -webkit-gradient(linear, left top, left bottom, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.LeftTop): background = 'background: -webkit-gradient(linear, left top, right bottom, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.LeftBottom): background = 'background: -webkit-gradient(linear, left bottom, right top, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Vertical): background = 'background: -webkit-gradient(linear, left top, right top, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) else: background = 'background: -webkit-gradient(radial, {width} 50%, 100, {width} 50%, {width}, ' \ 'from({start}), to({end})) fixed'.format(width=width, start=theme.background_start_color, end=theme.background_end_color) return background
def build_background_css(item, width, height): """ Build the background css ``item`` Service Item containing theme and location information """ width = int(width) / 2 theme = item.themedata background = u'background-color: black' if theme: if theme.background_type == BackgroundType.to_string(BackgroundType.Transparent): background = u'' elif theme.background_type == BackgroundType.to_string(BackgroundType.Solid): background = u'background-color: %s' % theme.background_color else: if theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Horizontal): background = u'background: -webkit-gradient(linear, left top, left bottom, from(%s), to(%s)) fixed' \ % (theme.background_start_color, theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.LeftTop): background = u'background: -webkit-gradient(linear, left top, right bottom, from(%s), to(%s)) fixed' \ % (theme.background_start_color, theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.LeftBottom): background = u'background: -webkit-gradient(linear, left bottom, right top, from(%s), to(%s)) fixed' \ % (theme.background_start_color, theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string(BackgroundGradientType.Vertical): background = u'background: -webkit-gradient(linear, left top, right top, from(%s), to(%s)) fixed' % \ (theme.background_start_color, theme.background_end_color) else: background = u'background: -webkit-gradient(radial, %s 50%%, 100, %s 50%%, %s, from(%s), to(%s)) fixed'\ % (width, width, width, theme.background_start_color, theme.background_end_color) return background
def on_gradient_combo_box_current_index_changed(self, index): """ Background gradient Combo box has changed. """ if self.update_theme_allowed: self.theme.background_direction = BackgroundGradientType.to_string(index) self.set_background_page_values()
def gradient_type(self, value): if isinstance(value, str): self.gradient_combo_box.setCurrentIndex( BackgroundGradientType.from_string(value)) elif isinstance(value, int): self.gradient_combo_box.setCurrentIndex(value) else: raise TypeError('gradient_type must either be a string or an int')
def build_background_css(item, width): """ Build the background css :param item: Service Item containing theme and location information :param width: """ width = int(width) // 2 theme = item.theme_data background = 'background-color: black' if theme: if theme.background_type == BackgroundType.to_string( BackgroundType.Transparent): background = '' elif theme.background_type == BackgroundType.to_string( BackgroundType.Solid): background = 'background-color: {theme}'.format( theme=theme.background_color) else: if theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Horizontal): background = 'background: -webkit-gradient(linear, left top, left bottom, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.LeftTop): background = 'background: -webkit-gradient(linear, left top, right bottom, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.LeftBottom): background = 'background: -webkit-gradient(linear, left bottom, right top, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Vertical): background = 'background: -webkit-gradient(linear, left top, right top, from({start}), to({end})) ' \ 'fixed'.format(start=theme.background_start_color, end=theme.background_end_color) else: background = 'background: -webkit-gradient(radial, {width} 50%, 100, {width} 50%, {width}, ' \ 'from({start}), to({end})) fixed'.format(width=width, start=theme.background_start_color, end=theme.background_end_color) return background
def test_set_gradient_type_str(self): """ Test the gradient_type setter with a str """ # GIVEN: A BackgroundPage instance page = BackgroundPage() # WHEN: The property is set page.gradient_type = BackgroundGradientType.to_string( BackgroundGradientType.Circular) # THEN: The combobox should be correct assert page.gradient_combo_box.currentIndex() == 2
def build_background_css(item, width): """ Build the background css :param item: Service Item containing theme and location information :param width: """ width = int(width) // 2 theme = item.theme_data background = 'background-color: black' if theme: if theme.background_type == BackgroundType.to_string( BackgroundType.Transparent): background = '' elif theme.background_type == BackgroundType.to_string( BackgroundType.Solid): background = 'background-color: %s' % theme.background_color else: if theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Horizontal): background = 'background: -webkit-gradient(linear, left top, left bottom, from(%s), to(%s)) fixed' \ % (theme.background_start_color, theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.LeftTop): background = 'background: -webkit-gradient(linear, left top, right bottom, from(%s), to(%s)) fixed' \ % (theme.background_start_color, theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.LeftBottom): background = 'background: -webkit-gradient(linear, left bottom, right top, from(%s), to(%s)) fixed' \ % (theme.background_start_color, theme.background_end_color) elif theme.background_direction == BackgroundGradientType.to_string( BackgroundGradientType.Vertical): background = 'background: -webkit-gradient(linear, left top, right top, from(%s), to(%s)) fixed' % \ (theme.background_start_color, theme.background_end_color) else: background = 'background: -webkit-gradient(radial, %s 50%%, 100, %s 50%%, %s, from(%s), to(%s)) fixed'\ % (width, width, width, theme.background_start_color, theme.background_end_color) return background
def test_background_gradient_type_to_string(self): """ Test the to_string method of :class:`BackgroundGradientType` """ # GIVEN: The BackgroundGradientType member background_gradient_horizontal = BackgroundGradientType.Horizontal background_gradient_vertical = BackgroundGradientType.Vertical background_gradient_circular = BackgroundGradientType.Circular background_gradient_left_top = BackgroundGradientType.LeftTop background_gradient_left_bottom = BackgroundGradientType.LeftBottom # WHEN: Calling BackgroundGradientType.to_string # THEN: The string equivalents should be returned assert BackgroundGradientType.to_string( background_gradient_horizontal) == 'horizontal' assert BackgroundGradientType.to_string( background_gradient_vertical) == 'vertical' assert BackgroundGradientType.to_string( background_gradient_circular) == 'circular' assert BackgroundGradientType.to_string( background_gradient_left_top) == 'leftTop' assert BackgroundGradientType.to_string( background_gradient_left_bottom) == 'leftBottom'
def gradient_type(self): return BackgroundGradientType.to_string( self.gradient_combo_box.currentIndex())