Example #1
0
    def load_skin_from_image(self, filepath):
        '''
        Load theme from given image.

        @param filepath: The file path of image.
        '''
        # Init.
        skin_dir = os.path.join(self.user_skin_dir, str(uuid.uuid4()))
        skin_image_file = os.path.basename(filepath)
        config_file = os.path.join(skin_dir, "config.ini")
        dominant_color = get_dominant_color(filepath)
        similar_color = find_similar_color(dominant_color)[0]
        default_config = [
            ("theme", [("theme_name", similar_color)]),
            ("application", [("app_id", self.app_given_id),
                             ("app_version", self.app_given_version)]),
            ("background", [("image", skin_image_file),
                            ("x", "0"),
                            ("y", "0"),
                            ("scale_x", "1.0"),
                            ("scale_y", "1.0"),
                            ("dominant_color", dominant_color)]),
            ("action", [("deletable", "True"),
                        ("editable", "True"),
                        ("vertical_mirror", "False"),
                        ("horizontal_mirror", "False")])]

        # Create skin directory.
        create_directory(skin_dir, True)

        # Copy skin image file.
        shutil.copy(filepath, skin_dir)

        # Touch skin config file.
        touch_file(config_file)

        # Write default skin config information.
        Config(config_file, default_config).write()

        if self.reload_skin(os.path.basename(skin_dir)):
            self.apply_skin()

            return (True, skin_dir, skin_image_file)
        else:
            return (False, skin_dir, skin_image_file)
Example #2
0
    def color_test_widget_expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Draw pixbuf.
        draw_pixbuf(cr, self.pixbuf, 0, 0)

        # Draw mask.
        draw_vlinear(cr, rect.x,
                     rect.y + self.pixbuf.get_height() - SHADOW_SIZE,
                     rect.width, SHADOW_SIZE,
                     [(0, (self.background_color, 0)),
                      (1, (self.background_color, 1))])

        draw_hlinear(cr, rect.x + self.pixbuf.get_width() - SHADOW_SIZE,
                     rect.y, SHADOW_SIZE, rect.height,
                     [(0, (self.background_color, 0)),
                      (1, (self.background_color, 1))])

        # Draw background.
        (similar_color_name,
         similar_color_value) = find_similar_color(self.background_color)
        print(similar_color_name, self.background_color, similar_color_value)
        cr.set_source_rgb(*color_hex_to_cairo(similar_color_value))
        cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y,
                     rect.width - self.pixbuf.get_width(), rect.height)
        cr.fill()
        cr.set_source_rgb(*color_hex_to_cairo(self.background_color))
        cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), rect.width,
                     rect.height - self.pixbuf.get_height())
        cr.fill()

        # cr.set_source_rgb(*color_hex_to_cairo(self.background_color))
        # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y,
        #              rect.width - self.pixbuf.get_width(), rect.height)
        # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(),
        #              rect.width, rect.height - self.pixbuf.get_height())

        # cr.fill()

        propagate_expose(widget, event)

        return True
Example #3
0
    def color_test_widget_expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Draw pixbuf.
        draw_pixbuf(cr, self.pixbuf, 0, 0)
        
        # Draw mask.
        draw_vlinear(
            cr, rect.x, rect.y + self.pixbuf.get_height() - SHADE_SIZE, rect.width, SHADE_SIZE,
            [(0, (self.background_color, 0)),
             (1, (self.background_color, 1))])
        
        draw_hlinear(
            cr, rect.x + self.pixbuf.get_width() - SHADE_SIZE, rect.y, SHADE_SIZE, rect.height,
            [(0, (self.background_color, 0)),
             (1, (self.background_color, 1))])

        # Draw background.
        (similar_color_name, similar_color_value) = find_similar_color(self.background_color)
        print (similar_color_name, self.background_color, similar_color_value)
        cr.set_source_rgb(*color_hex_to_cairo(similar_color_value))
        cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y,
                     rect.width - self.pixbuf.get_width(), rect.height)
        cr.fill()
        cr.set_source_rgb(*color_hex_to_cairo(self.background_color))
        cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), 
                     rect.width, rect.height - self.pixbuf.get_height())
        cr.fill()
        
        # cr.set_source_rgb(*color_hex_to_cairo(self.background_color))
        # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y,
        #              rect.width - self.pixbuf.get_width(), rect.height)
        # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), 
        #              rect.width, rect.height - self.pixbuf.get_height())
        
        # cr.fill()
        
        propagate_expose(widget, event)
        
        return True