Python gi.repository.Gdk.Color() Examples

The following are 15 code examples of gi.repository.Gdk.Color(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gdk , or try the search function .
Example #1
Source File: backend_gtk3.py    From Computable with MIT License 6 votes vote down vote up
def on_combobox_lineprops_changed(self, item):
        'update the widgets from the active line'
        if not self._inited: return
        self._updateson = False
        line = self.get_active_line()

        ls = line.get_linestyle()
        if ls is None: ls = 'None'
        self.cbox_linestyles.set_active(self.linestyled[ls])

        marker = line.get_marker()
        if marker is None: marker = 'None'
        self.cbox_markers.set_active(self.markerd[marker])

        r,g,b = colorConverter.to_rgb(line.get_color())
        color = Gdk.Color(*[int(val*65535) for val in r,g,b])
        button = self.wtree.get_widget('colorbutton_linestyle')
        button.set_color(color)

        r,g,b = colorConverter.to_rgb(line.get_markerfacecolor())
        color = Gdk.Color(*[int(val*65535) for val in r,g,b])
        button = self.wtree.get_widget('colorbutton_markerface')
        button.set_color(color)
        self._updateson = True 
Example #2
Source File: backend_gtk3.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def on_combobox_lineprops_changed(self, item):
        'update the widgets from the active line'
        if not self._inited: return
        self._updateson = False
        line = self.get_active_line()

        ls = line.get_linestyle()
        if ls is None: ls = 'None'
        self.cbox_linestyles.set_active(self.linestyled[ls])

        marker = line.get_marker()
        if marker is None: marker = 'None'
        self.cbox_markers.set_active(self.markerd[marker])

        r,g,b = colorConverter.to_rgb(line.get_color())
        color = Gdk.Color(*[int(val*65535) for val in r,g,b])
        button = self.wtree.get_widget('colorbutton_linestyle')
        button.set_color(color)

        r,g,b = colorConverter.to_rgb(line.get_markerfacecolor())
        color = Gdk.Color(*[int(val*65535) for val in r,g,b])
        button = self.wtree.get_widget('colorbutton_markerface')
        button.set_color(color)
        self._updateson = True 
Example #3
Source File: backend_gtk3.py    From neural-network-animation with MIT License 6 votes vote down vote up
def on_combobox_lineprops_changed(self, item):
        'update the widgets from the active line'
        if not self._inited: return
        self._updateson = False
        line = self.get_active_line()

        ls = line.get_linestyle()
        if ls is None: ls = 'None'
        self.cbox_linestyles.set_active(self.linestyled[ls])

        marker = line.get_marker()
        if marker is None: marker = 'None'
        self.cbox_markers.set_active(self.markerd[marker])

        r,g,b = colorConverter.to_rgb(line.get_color())
        color = Gdk.Color(*[int(val*65535) for val in (r,g,b)])
        button = self.wtree.get_widget('colorbutton_linestyle')
        button.set_color(color)

        r,g,b = colorConverter.to_rgb(line.get_markerfacecolor())
        color = Gdk.Color(*[int(val*65535) for val in (r,g,b)])
        button = self.wtree.get_widget('colorbutton_markerface')
        button.set_color(color)
        self._updateson = True 
Example #4
Source File: backend_gtk3.py    From ImageFusion with MIT License 6 votes vote down vote up
def on_combobox_lineprops_changed(self, item):
        'update the widgets from the active line'
        if not self._inited: return
        self._updateson = False
        line = self.get_active_line()

        ls = line.get_linestyle()
        if ls is None: ls = 'None'
        self.cbox_linestyles.set_active(self.linestyled[ls])

        marker = line.get_marker()
        if marker is None: marker = 'None'
        self.cbox_markers.set_active(self.markerd[marker])

        r,g,b = colorConverter.to_rgb(line.get_color())
        color = Gdk.Color(*[int(val*65535) for val in (r,g,b)])
        button = self.wtree.get_widget('colorbutton_linestyle')
        button.set_color(color)

        r,g,b = colorConverter.to_rgb(line.get_markerfacecolor())
        color = Gdk.Color(*[int(val*65535) for val in (r,g,b)])
        button = self.wtree.get_widget('colorbutton_markerface')
        button.set_color(color)
        self._updateson = True 
Example #5
Source File: keyboard.py    From openrazer with GNU General Public License v2.0 6 votes vote down vote up
def gdk_colour_to_rgb(gdk_color):
        """
        Converts GDK colour to (R,G,B) tuple

        :param gdk_color: GDK colour
        :type gdk_color: Gdk.Color or tuple

        :return: Tuple of 3 ints
        :rtype: tuple
        """
        if isinstance(gdk_color, (list, tuple)):
            return gdk_color

        assert type(gdk_color) is Gdk.Color, "Is not of type Gdk.Color"

        red = int(gdk_color.red_float * 255)
        green = int(gdk_color.green_float * 255)
        blue = int(gdk_color.blue_float * 255)

        return red, green, blue 
Example #6
Source File: keyboard.py    From openrazer with GNU General Public License v2.0 6 votes vote down vote up
def set_key_colour(self, row, col, colour):
        """
        Set the colour of a key

        :param row: Row ID
        :type row: int

        :param col: Column ID
        :type col: int

        :param colour: Colour to set
        :type colour: Gdk.Color or tuple

        :raises KeyDoesNotExistError: If given key does not exist
        """
        self.colors[row][col].set(KeyboardColour.gdk_colour_to_rgb(colour)) 
Example #7
Source File: tag_editor.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def __set_default_values(self):
        """Configure the widget components with their initial default values"""
        # Disable some handlers while setting up the widget to avoid
        # interferences
        self.tn_cb.handler_block(self.tn_cb_clicked_hid)
        self.tn_entry.handler_block(self.tn_entry_clicked_hid)
        self.tag_icon_selector.handler_block(self.tis_selection_changed_hid)
        # Default icon
        markup = "<span size='small'>%s</span>" % _("Click to\nSet Icon")
        self.ti_bt_label.set_justify(Gtk.Justification.CENTER)
        self.ti_bt_label.set_markup(markup)
        self.ti_bt_label.show()
        self.__set_icon(None)
        # Unselect any previously selected icon
        self.tag_icon_selector.unselect_icon()
        # Show in WV
        self.tn_cb.set_active(True)
        # Name entry
        self.tn_entry.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, None)
        # Color selection
        # FIXME
        self.tc_cc_colsel.unselect_color()
        # self.tc_cc_colsel.set_use_alpha(False)
        # self.tc_cc_colsel.set_rgba(self.tc_cc_colsel, None)
        # Custom colors
        self.custom_colors = self.config.get('custom_colors')
        if len(self.custom_colors) > 0:
            self.tc_cc_colsel.set_custom_colors(self.custom_colors)
        # Focus
        self.tn_entry.grab_focus()
        # Re-enable checkbutton handler_block
        self.tn_cb.handler_unblock(self.tn_cb_clicked_hid)
        self.tn_entry.handler_unblock(self.tn_entry_clicked_hid)
        self.tag_icon_selector.handler_unblock(self.tis_selection_changed_hid) 
Example #8
Source File: tag_editor.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def on_tc_colsel_changed(self, widget):
        """Callback: update the tag color depending on the current color
        selection"""
        color = self.tc_cc_colsel.get_selected_color()
        if self.tag is not None:
            if color is not None:
                my_color = Gdk.color_parse(color)
                color = Gdk.Color(my_color.red, my_color.green, my_color.blue).to_string()
                color_add(color)
                self.tag.set_attribute('color', color)
            else:
                color_remove(self.tag.get_attribute('color'))
                self.tag.del_attribute('color') 
Example #9
Source File: colors.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def background_color(tags, bgcolor=None):
    if not bgcolor:
        bgcolor = Gdk.color_parse("#FFFFFF")
    # Compute color
    my_color = None
    color_count = 0.0
    red = 0
    green = 0
    blue = 0
    for my_tag in tags:
        my_color_str = my_tag.get_attribute("color")
        if my_color_str is not None and my_color_str not in used_color:
            used_color.append(my_color_str)
        if my_color_str:
            my_color = Gdk.color_parse(my_color_str)
            color_count = color_count + 1
            red = red + my_color.red
            green = green + my_color.green
            blue = blue + my_color.blue
    if color_count != 0:
        red = int(red / color_count)
        green = int(green / color_count)
        blue = int(blue / color_count)
        brightness = (red + green + blue) / 3.0
        target_brightness = (bgcolor.red + bgcolor.green + bgcolor.blue) / 3.0

        alpha = (1 - abs(brightness - target_brightness) / 65535.0) / 2.0
        red = int(red * alpha + bgcolor.red * (1 - alpha))
        green = int(green * alpha + bgcolor.green * (1 - alpha))
        blue = int(blue * alpha + bgcolor.blue * (1 - alpha))

        my_color = Gdk.Color(red, green, blue).to_string()
    return my_color 
Example #10
Source File: colors.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def generate_tag_color():

    maxvalue = 65535
    flag = 0
    while(flag == 0):
        red = random.randint(0, maxvalue)
        green = random.randint(0, maxvalue)
        blue = random.randint(0, maxvalue)
        my_color = Gdk.Color(red, green, blue).to_string()
        if my_color not in used_color:
            flag = 1
    used_color.append(my_color)
    return my_color 
Example #11
Source File: alarm.py    From coinprice-indicator with MIT License 5 votes vote down vote up
def _strip_text(self, widget):
        widget.modify_fg(Gtk.StateFlags.NORMAL, None)
        text = widget.get_text().strip()
        filtered_text = (''.join([i for i in text if i in '0123456789.']))
        widget.set_text(filtered_text)
        try:
            float(filtered_text)
        except ValueError:
            widget.modify_fg(Gtk.StateFlags.NORMAL, Color(50000, 0, 0))

    ##
    # Sets the alarm threshold
    # 
Example #12
Source File: gtk.py    From bups with MIT License 5 votes vote down vote up
def __init__(self, manager, parent=None):
		Gtk.Window.__init__(self, title=_("Backup"))
		self.set_border_width(10)
		self.set_icon_name("drive-harddisk")
		self.set_position(Gtk.WindowPosition.CENTER)

		if parent is not None:
			self.set_transient_for(parent)

		vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
		self.add(vbox)

		self.label = Gtk.Label(_("Ready."), xalign=0)
		self.label.set_justify(Gtk.Justification.LEFT)
		vbox.pack_start(self.label, False, False, 0)

		self.progressbar = Gtk.ProgressBar()
		vbox.pack_start(self.progressbar, False, False, 0)

		self.textview = Gtk.TextView()
		#self.textview.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(0, 0, 0))
		#self.textview.modify_text(Gtk.StateType.NORMAL, Gdk.Color(255, 255, 255))
		fontdesc = Pango.FontDescription("monospace")
		self.textview.modify_font(fontdesc)
		self.textview.set_editable(False)
		sw = Gtk.ScrolledWindow()
		sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
		sw.set_min_content_height(200)
		sw.add(self.textview)
		exp = Gtk.Expander()
		exp.set_label(_("Details"))
		exp.add(sw)
		vbox.pack_start(exp, True, True, 0)

		hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
		vbox.add(hbox)
		self.close_button = Gtk.Button(_("Close"))
		self.close_button.connect("clicked", self.on_close_clicked)
		hbox.pack_end(self.close_button, False, False, 0)

		self.manager = manager 
Example #13
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def set_bgcolor(self, bgcolor):
		'''Set background color
		@param bgcolor: background color as color hex code, (e.g. "#FFF")
		'''
		assert bgcolor.startswith('#'), 'BUG: Should specify colors in hex'
		color = Gdk.color_parse(bgcolor)
			# Gdk.Color(spec) only for gtk+ >= 2.14
		self.modify_bg(Gtk.StateType.NORMAL, color) 
Example #14
Source File: tag_editor.py    From gtg with GNU General Public License v3.0 4 votes vote down vote up
def __build_window(self):
        """Build up the widget"""
        # toplevel widget
        self.top_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(self.top_vbox)
        # header line: icon, grid with name and "hide in wv"
        # FIXME
        self.hdr_align = Gtk.Alignment()
        self.top_vbox.pack_start(self.hdr_align, True, True, 0)
        self.hdr_align.set_padding(0, 25, 0, 0)
        self.hdr_box = Gtk.Box()
        self.hdr_align.add(self.hdr_box)
        self.hdr_box.set_spacing(10)
        # Button to tag icon selector
        self.ti_bt = Gtk.Button()
        self.ti_bt_label = Gtk.Label()
        self.ti_bt.add(self.ti_bt_label)
        self.hdr_box.pack_start(self.ti_bt, True, True, 0)
        self.ti_bt.set_size_request(64, 64)
        self.ti_bt.set_relief(Gtk.ReliefStyle.HALF)
        # vbox for tag name and hid in WV
        self.tp_grid = Gtk.Grid()
        self.hdr_box.pack_start(self.tp_grid, True, True, 0)
        self.tp_grid.set_column_spacing(5)
        self.tn_entry_lbl_align = Gtk.Alignment.new(0, 0.5, 0, 0)
        self.tp_grid.add(self.tn_entry_lbl_align)
        self.tn_entry_lbl = Gtk.Label()
        self.tn_entry_lbl.set_markup("<span weight='bold'>%s</span>"
                                     % _("Name : "))
        self.tn_entry_lbl_align.add(self.tn_entry_lbl)
        self.tn_entry = Gtk.Entry()
        self.tn_entry.set_width_chars(20)
        self.tp_grid.attach(self.tn_entry, 1, 0, 1, 1)
        self.tn_cb_lbl_align = Gtk.Alignment.new(0, 0.5, 0, 0)
        self.tp_grid.attach(self.tn_cb_lbl_align, 0, 1, 1, 1)
        self.tn_cb_lbl = Gtk.Label(label=_('Show Tag in "Actionable" view:'))
        self.tn_cb_lbl_align.add(self.tn_cb_lbl)
        self.tn_cb = Gtk.CheckButton()
        self.tp_grid.attach(self.tn_cb, 1, 1, 1, 1)
        # Tag color
        self.tc_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.top_vbox.pack_start(self.tc_vbox, True, True, 0)
        self.tc_label_align = Gtk.Alignment()
        self.tc_vbox.pack_start(self.tc_label_align, True, True, 0)
        self.tc_label_align.set_padding(0, 0, 0, 0)
        self.tc_label = Gtk.Label()
        self.tc_label_align.add(self.tc_label)
        self.tc_label.set_markup(
            "<span weight='bold'>%s</span>" % _("Select Tag Color:"))
        self.tc_label.set_alignment(0, 0.5)
        # Tag color chooser
        self.tc_cc_align = Gtk.Alignment.new(0.5, 0.5, 0, 0)
        self.tc_vbox.pack_start(self.tc_cc_align, True, True, 0)
        self.tc_cc_align.set_padding(15, 15, 10, 10)
        self.tc_cc_colsel = SimpleColorSelector()
        # self.tc_cc_colsel = Gtk.ColorChooserWidget()
        self.tc_cc_align.add(self.tc_cc_colsel)
        # Icon selector
        self.tag_icon_selector = TagIconSelector() 
Example #15
Source File: gremlin3dwidget.py    From hazzy with GNU General Public License v2.0 4 votes vote down vote up
def __init__(self, inifile, width, height):
        #GObject.__init__(self)
        gremlin3d.Gremlin3D.__init__(self, inifile)

        self.width = width
        self.height = height

        self.percent = 0
        self.mouse_mode = None
        self.zoom_in_pressed = False
        self.zoom_out_pressed = False

        self.set_display_units('mm')

        # Gremlin3D width = width - 40 to allow room for the controls
        self.set_size_request(self.width - 40, self.height)

        # Add gremlin back-plot
        self.gremlin_view = Gtk.HBox()
        fixed = Gtk.Fixed()
        fixed.put(self, 0, 0)
        self.gremlin_view.add(fixed)
        self.connect('button_press_event', self.on_gremlin_clicked)

        # Add touchscreen controls
        gladefile = os.path.join(UIDIR, 'controls.glade')
        self.builder = Gtk.Builder()
        self.builder.add_from_file(gladefile)
        self.builder.connect_signals(self)
        controls = self.builder.get_object('controls')
        controls.set_size_request(40, self.height)
        self.gremlin_view.add(controls)

        # Add progress label
        self.label = Gtk.Label()
        # self.label.modify_font(Pango.FontDescription('FreeSans 11'))
        # self.label.modify_fg(Gtk.StateType.NORMAL, Gdk.Color('White'))

        # labelbox = Gtk.EventBox()
        # labelbox.modify_bg(Gtk.StateType.NORMAL, Gdk.Color('Black'))
        # labelbox.set_size_request(-1, 20)
        # labelbox.add(self.label)
        # fixed.put(labelbox, 0, self.height - 20)

    #    def fileloading(self, current_line):
    #        self.progressbar.show()
    #        percent = current_line * 100 / self.line_count
    #        if self.percent != percent:
    #            self.percent = percent
    #            msg = "Generating preview {}%".format(self.percent)
    #            self.progressbar.set_text(msg)
    #            self.progressbar.set_fraction(self.percent / 100)
    #            log.debug(msg)
    #            self.emit('loading_progress', percent)