我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用gi.repository.Gdk.Color()。
def on_osd_color_set(self, *a): """ Called when user selects color. """ # Following lambdas converts Gdk.Color into #rrggbb notation. # Gdk.Color can do similar, except it uses #rrrrggggbbbb notation that # is not understood by Gdk css parser.... cbOSDColorPreset = self.builder.get_object("cbOSDColorPreset") striphex = lambda a: hex(a).strip("0x").zfill(2) tohex = lambda a: "".join([ striphex(int(x * 0xFF)) for x in a.to_floats() ]) for k in self.app.config["osd_colors"]: w = self.builder.get_object("cb%s" % (k,)) if w: self.app.config["osd_colors"][k] = tohex(w.get_color()) for k in self.app.config["osk_colors"]: w = self.builder.get_object("cbosk_%s" % (k,)) if w: self.app.config["osk_colors"][k] = tohex(w.get_color()) self.app.config["osd_color_theme"] = None self.set_cb(cbOSDColorPreset, "None") self.app.save_config()
def textview_color_changed(self,widget): logger.debug(widget.get_label() + " clicked") self.color_text = widget.get_label().lower() logger.debug("Color changed to :" + self.color_text if self.color_text else "Not available") color = self.check_color_label_or_rbg(widget.get_label()) if color == "Yellow": self.bg_color = Gdk.Color(red=65535, green=65278, blue=20300) elif color == "Blue": self.bg_color = Gdk.Color(red=29298, green=40863, blue=53199) elif color == 'Purple': self.bg_color = Gdk.Color(red=44461, green=32639, blue=43176) elif color == "Peach": self.bg_color = Gdk.Color(red=64764, green=44975, blue=15934) self.application_menu_object.change_item_icon(self.title if self.title else str(self.uuid), self.color_text.strip()) self.window.modify_bg(Gtk.StateType.NORMAL,self.bg_color) self.textview.modify_bg(Gtk.StateType.NORMAL,self.bg_color)
def signInButtonClicked(self, *args): COLOR_INVALID = Color(50000, 10000, 10000) email = self.login_window.email_field.get_text() password = self.login_window.password_field.get_text() result = re.match( '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email) if result is None: print("None") self.login_window.email_field.modify_fg( Gtk.StateFlags.NORMAL, COLOR_INVALID) return else: self.login_window.email_field.modify_fg( Gtk.StateFlags.NORMAL, None) self.login_window.spinner.start() try: result = is_valid(email, password) if result: self.login_window.spinner.stop() self.login_window.show_successful_login_dialog() config['usage_mode'] = 'authenticated' config['login_credentials']['email'] = email config['login_credentials']['password'] = password else: self.login_window.spinner.stop() self.login_window.show_failed_login_dialog() config['usage_mode'] = 'anonymous' except ConnectionError: self.login_window.spinner.stop() self.login_window.show_connection_error_dialog() finally: self.login_window.spinner.stop()
def _load_color(self, w, dct, key): """ Common part of load_colors """ if w: success, color = Gdk.Color.parse("#%s" % (self.app.config[dct][key],)) if not success: success, color = Gdk.Color.parse("#%s" % (self.app.config[dct][key],)) w.set_color(color)
def __init__( self, keybinder, settings ): self.keybinder = keybinder self.settings = settings self.data_path = os.path.join( '/', 'usr', 'share', 'ukui-menu' ) self.icon = "/usr/share/ukui-menu/icons/ukui-logo.svg" # Load UI file and extract widgets builder = Gtk.Builder() builder.add_from_file(os.path.join( self.data_path, "ukui-menu.glade" )) self.window = builder.get_object( "mainWindow" ) self.eventbox = builder.get_object( "eventbox1" ) self.paneholder = builder.get_object( "paneholder" ) self.border = builder.get_object( "border" ) builder.connect_signals(self) self.borderwidth = 1 self.border.set_padding( self.borderwidth, self.borderwidth, self.borderwidth, self.borderwidth ) defaultStyle = self.getDefaultStyle() color = defaultStyle.lookup_color('taskbar_applet_border_color')[1] if color == Gdk.Color(red=0, green=0, blue=0): self.window.modify_bg( Gtk.StateType.NORMAL, Gdk.color_parse( "#014276" )) else: self.window.modify_bg( Gtk.StateType.NORMAL, color ) self.eventbox.set_name("EventBox") self.window.connect( "key-press-event", self.onKeyPress ) self.window.connect( "focus-in-event", self.onFocusIn ) self.loseFocusId = self.window.connect( "focus-out-event", self.onFocusOut ) self.loseFocusBlocked = False self.offset = 0 self.window.stick() self.PopulatePlugins()