def get_color(logicalcolorname): settings = gtk.settings_get_default() color_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', \ 'osso-logical-colors', gtk.Button) if not color_style: font_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', 'GtkButton', gtk.Button) return color_style.lookup_color(logicalcolorname)
def get_font_desc(logicalfontname): settings = gtk.settings_get_default() font_style = gtk.rc_get_style_by_paths(settings, logicalfontname, \ None, None) if not font_style: font_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', 'GtkButton', gtk.Button) font_desc = font_style.font_desc return font_desc
def getForegroundColor(): """ @rtype: RGBA @return: the foreground color from the gtk theme """ style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), "GtkTextView", "GtkTextView", gtk.TextView) c = RGBA() c.setGdk(style.text[gtk.STATE_NORMAL]) return c
def getBackgroundColor(): """ @rtype: RGBA @return: a color representation of the background color from the gtk theme """ style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), "GtkTextView", "GtkTextView", gtk.TextView) c = RGBA() c.setGdk(style.bg[gtk.STATE_NORMAL]) return c
def get_color(color_name): # Adapted from gPodder settings = gtk.settings_get_default() if not settings: return None color_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', 'osso-logical-colors', gtk.Button) return color_style.lookup_color(color_name).to_string()
def text_color(): "color as triple or None" settings = gtk.settings_get_default() s = gtk.rc_get_style_by_paths(settings, "kupfer.*", None, None) if not s: e = gtk.Invisible() e.realize() s = e.style c = s.fg[gtk.STATE_NORMAL] return (1.0*c.red/0xffff, 1.0*c.green/0xffff, 1.0*c.blue/0xffff)
def text_color(): "color as triple or None" settings = gtk.settings_get_default() s = gtk.rc_get_style_by_paths(settings, "kupfer.*", None, None) if not s: e = gtk.Invisible() e.realize() s = e.style c = s.fg[gtk.STATE_NORMAL] return (1.0 * c.red / 0xFFFF, 1.0 * c.green / 0xFFFF, 1.0 * c.blue / 0xFFFF)
def style_button(button): style = button.get_style() style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), 'gtk-button', 'gtk-button', gobject.TYPE_NONE) button.set_flags(gtk.CAN_DEFAULT) button.grab_default() # label = "<span size='x-large'><b>%s</b></span>" % gobject.markup_escape_text(button.get_label()) label = button.get_label() button.set_label(label) button.child.set_use_markup(True)
def _determine_edit_colour(self): """Determine which colour to use for the editable hint""" def _compare_colors(oColor1, oColor2): """Compare the RGB values for 2 gtk.gdk.Colors. Return True if they're the same, false otherwise.""" return oColor1.to_string() == oColor2.to_string() oCurStyle = self.rc_get_style() # Styles don't seem to be applied to TreeView text, so we default # to black text for non-editable, and work out editable from the # style self.oCellColor = gtk.gdk.color_parse('black') oCurBackColor = oCurStyle.base[gtk.STATE_NORMAL] self.set_name('editable_view') oDefaultSutekhStyle = gtk.rc_get_style_by_paths(self.get_settings(), '', self.class_path(), self) # We want the class style for this widget, ignoring set_name effects oSpecificStyle = self.rc_get_style() if oSpecificStyle == oDefaultSutekhStyle or \ oDefaultSutekhStyle is None: # No specific style set sColour = 'red' if _compare_colors(gtk.gdk.color_parse(sColour), oCurStyle.fg[gtk.STATE_NORMAL]): sColour = 'green' # FIXME: rc_parse_string doesn't play nicely with # theme changes, which cause a rcfile reparse. sStyleInfo = """ style "internal_sutekh_editstyle" { fg[NORMAL] = "%(colour)s" } widget "%(path)s" style "internal_sutekh_editstyle" """ % {'colour': sColour, 'path': self.path()} gtk.rc_parse_string(sStyleInfo) # Need to force re-assesment of styles self.set_name('editable_view') oCurStyle = self.rc_get_style() # Force a hint on the number column as well oEditColor = oCurStyle.fg[gtk.STATE_NORMAL] oEditBackColor = oCurStyle.base[gtk.STATE_NORMAL] if not _compare_colors(oEditColor, self.oCellColor) or \ not _compare_colors(oEditBackColor, oCurBackColor): # Visiually distinct, so honour user's choice self._oModel.oEditColour = oEditColor else: # If the theme change isn't visually distinct here, we go # with red as the default - this is safe, # since CellRenderers aren't # themed, so the default color will not be red # (famous last words) # If the default background color is red, too bad self._oModel.oEditColour = gtk.gdk.color_parse('red')
def build_palette(self, gtksettings): style = gtk.rc_get_style_by_paths(gtksettings, 'GtkWindow', 'GtkWindow', gtk.Window) style = style or gtk.widget_get_default_style() # build pathbar color palette self.fg = PathBarColorArray(style.fg) self.bg = PathBarColorArray(style.bg) self.text = PathBarColorArray(style.text) self.base = PathBarColorArray(style.base) self.light = PathBarColorArray(style.base) self.mid = PathBarColorArray(style.base) self.dark = PathBarColorArray(style.base) return
def set_focussed_title(self): """Set the title to the correct style when focussed.""" oCurStyle = self._oTitleLabel.rc_get_style() self._oTitleLabel.set_name('selected_title') # We can't have this name be a superset of the title name, # otherwise any style set on 'title' automatically applies # here, which is not what we want. oDefaultSutekhStyle = gtk.rc_get_style_by_paths( self._oTitleLabel.get_settings(), self.path() + '.', self.class_path(), self._oTitleLabel) # Bit of a hack, but get's matches to before the title specific bits # of the path oSpecificStyle = self._oTitleLabel.rc_get_style() if oSpecificStyle == oDefaultSutekhStyle or \ oDefaultSutekhStyle is None: # No specific style which affects highlighted titles set, so create # one oMap = self._oTitleLabel.get_colormap() sColour = 'purple' if oMap.alloc_color(sColour).pixel == \ oCurStyle.fg[gtk.STATE_NORMAL].pixel: sColour = 'green' # Prevent collisions. If the person is using # purple on a green background, they deserve # invisible text sStyleInfo = """ style "internal_sutekh_hlstyle" { fg[NORMAL] = "%(colour)s" } widget "%(path)s" style "internal_sutekh_hlstyle" """ % {'colour': sColour, 'path': self._oTitleLabel.path()} gtk.rc_parse_string(sStyleInfo) # We use gtk's style machinery to do the update. # This seems the only way of ensuring we will actually do # the right thing with themes, while still allowing flexiblity # Here, as this forces gtk to re-asses styles of widget and children self._oTitle.set_name('selected_title')
def set_text_style(self, widget, prev, *params): settings = gtk.settings_get_default() style = gtk.rc_get_style_by_paths(settings, "*PanelApplet*", "PanelApp*" , None) self.temp.set_style(style)
def __init__(self, sourceview): self.sourceview = sourceview # Widgets self.textview = tv = gtk.TextView() self.hscrollbar = hs = gtk.HScrollbar() self.vscrollbar = vs = gtk.VScrollbar() self.resizegrip = rg = gtk.EventBox() self.vbox1 = vb1 = gtk.VBox() self.vbox2 = vb2 = gtk.VBox() self.hbox = hb = gtk.HBox() self.window = win = gtk.Window(gtk.WINDOW_POPUP) self.char_width, self.char_height = self.get_char_size(tv) # Dragging vars self.is_dragging = None self.drag_x = None self.drag_y = None self.drag_left = None self.drag_top = None self.was_dragged = None # Resizing vars self.is_resizing = None self.resize_x = None self.resize_y = None self.resize_width = None self.resize_height = None self.was_displayed = False # Initialization style = gtk.rc_get_style_by_paths(tv.get_settings(), "gtk-tooltip", "gtk-tooltip", TYPE_NONE) tv.modify_text(gtk.STATE_NORMAL, style.fg[gtk.STATE_NORMAL]) tv.modify_base(gtk.STATE_NORMAL, style.bg[gtk.STATE_NORMAL]) tv.set_size_request(0, 0) tv.props.editable = False tv.connect("event", self.on_textview_event) tv.set_scroll_adjustments(hs.props.adjustment, vs.props.adjustment) tv.connect("scroll-event", self.on_textview_scroll) hs.props.adjustment.connect("changed", self.on_hadj_changed) rg.add_events(gdk.BUTTON_PRESS_MASK | gdk.BUTTON_MOTION_MASK | gdk.BUTTON_RELEASE_MASK | gdk.EXPOSURE_MASK) rg.connect("event", self.on_resizegrip_event) rg.set_size_request(vs.size_request()[0], vs.size_request()[0]) vb1.pack_start(tv, True, True) vb1.pack_start(hs, False, False) vb2.pack_start(vs, True, True) vb2.pack_end(rg, False, False) hb.pack_start(vb1, True, True) hb.pack_start(vb2, False, False) win.add(hb) # Make all widgets except the window visible, so that a simple "show" # will suffice to show the window hb.show_all() # We define this handler here so that it will be defined before # the default key-press handler, and so will have higher priority. self.keypress_handler = self.sourceview.connect("key-press-event", self.on_keypress) self.sourceview.handler_block(self.keypress_handler) self.keypress_handler_blocked = True
def __init__(self, markup, parent_win=None): gtk.Window.__init__(self, gtk.WINDOW_POPUP) # Inherit the system theme for a tooltip style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), 'gtk-tooltip', 'gtk-tooltip', gobject.TYPE_NONE) self.set_style(style) # The placement of the close button on the tip should reflect how the # window manager of the users system places close buttons. Try to read # the metacity gconf key to determine whether the close button is on the # left or the right. # In the case that we can't determine the users configuration we default # to close buttons being on the right. __button_right = True try: client = gconf.client_get_default() order = client.get_string("/apps/metacity/general/button_layout") if order and order.endswith(":"): __button_right = False except NameError: pass # We need to ensure we're only shown once self.shown = False # We don't want any WM decorations self.set_decorated(False) # We don't want to show in the taskbar or window switcher self.set_skip_pager_hint(True) self.set_skip_taskbar_hint(True) # We must be modal to ensure we grab focus when presented from a gtk.Dialog self.set_modal(True) self.set_border_width(0) self.set_position(gtk.WIN_POS_MOUSE) self.set_opacity(0.95) # Ensure a reasonable minimum size self.set_geometry_hints(self, 100, 50) # Set this window as a transient window for parent(main window) if parent_win: self.set_transient_for(parent_win) self.set_destroy_with_parent(True) # Draw our label and close buttons hbox = gtk.HBox(False, 0) hbox.show() self.add(hbox) img = gtk.Image() img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON) self.button = gtk.Button() self.button.set_image(img) self.button.connect("clicked", self._dismiss_cb) self.button.set_flags(gtk.CAN_DEFAULT) self.button.grab_focus() self.button.show() vbox = gtk.VBox(False, 0) vbox.show() vbox.pack_start(self.button, False, False, 0) if __button_right: hbox.pack_end(vbox, True, True, 0) else: hbox.pack_start(vbox, True, True, 0) self.set_default(self.button) bin = gtk.HBox(True, 6) bin.set_border_width(6) bin.show() self.label = gtk.Label() self.label.set_line_wrap(True) # We want to match the colours of the normal tooltips, as dictated by # the users gtk+-2.0 theme, wherever possible - on some systems this # requires explicitly setting a fg_color for the label which matches the # tooltip_fg_color settings = gtk.settings_get_default() colours = settings.get_property('gtk-color-scheme').split('\n') # remove any empty lines, there's likely to be a trailing one after # calling split on a dictionary-like string colours = filter(None, colours) for col in colours: item, val = col.split(': ') if item == 'tooltip_fg_color': style = self.label.get_style() style.fg[gtk.STATE_NORMAL] = gtk.gdk.color_parse(val) self.label.set_style(style) break # we only care for the tooltip_fg_color self.label.set_markup(markup) self.label.show() bin.add(self.label) hbox.pack_end(bin, True, True, 6) self.connect("key-press-event", self._catch_esc_cb)
# # You should have received a copy of the GNU General Public License # along with ReSiStance. If not, see <http://www.gnu.org/licenses/>. ######################################################################### from sys import maxint as MAXINT import cairo import constants import gobject import gtk # As defined here: http://docs.python.org/library/sys.html MININT = -MAXINT-1 # SYSTEM FONTS font_style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), 'SystemFont', None, None) SYSTEM_FONT_DESC = font_style.font_desc del font_style font_style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), 'SmallSystemFont', None, None) SMALL_FONT_DESC = font_style.font_desc del font_style color_style = gtk.rc_get_style_by_paths(gtk.settings_get_default() , 'GtkButton', 'osso-logical-colors', gtk.Button) SELECTION_COLOR = color_style.lookup_color('SelectionColor') del color_style class FeedCellRenderer(gtk.GenericCellRenderer): __gproperties__ = { 'id': (int, 'The feed ID', 'The feed ID', MININT, MAXINT, 0, gobject.PARAM_READWRITE), 'title': (str, 'The pixbuf to render', 'The pixbuf to render', None, gobject.PARAM_READWRITE),
def __init__(self, sourceview, sv_changed): self.sourceview = sourceview sv_changed.append(self.on_sv_changed) # Widgets self.textview = tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) self.hscrollbar = hs = gtk.HScrollbar() self.vscrollbar = vs = gtk.VScrollbar() self.resizegrip = rg = gtk.EventBox() self.vbox1 = vb1 = gtk.VBox() self.vbox2 = vb2 = gtk.VBox() self.hbox = hb = gtk.HBox() self.window = win = gtk.Window(gtk.WINDOW_POPUP) self.char_width, self.char_height = self.get_char_size(tv) # Dragging vars self.is_dragging = None self.drag_x = None self.drag_y = None self.drag_left = None self.drag_top = None self.was_dragged = None # Resizing vars self.is_resizing = None self.resize_x = None self.resize_y = None self.resize_width = None self.resize_height = None self.was_displayed = False # Initialization style = gtk.rc_get_style_by_paths(tv.get_settings(), 'gtk-tooltip', 'gtk-tooltip', TYPE_NONE) tv.modify_text(gtk.STATE_NORMAL, style.fg[gtk.STATE_NORMAL]) tv.modify_base(gtk.STATE_NORMAL, style.bg[gtk.STATE_NORMAL]) tv.set_size_request(0, 0) tv.props.editable = False tv.connect('event', self.on_textview_event) tv.set_scroll_adjustments(hs.props.adjustment, vs.props.adjustment) tv.connect('scroll-event', self.on_textview_scroll) hs.props.adjustment.connect('changed', self.on_hadj_changed) rg.add_events(gdk.BUTTON_PRESS_MASK | gdk.BUTTON_MOTION_MASK | gdk.BUTTON_RELEASE_MASK | gdk.EXPOSURE_MASK) rg.connect('event', self.on_resizegrip_event) rg.set_size_request(vs.size_request()[0], vs.size_request()[0]) vb1.pack_start(tv, True, True) vb1.pack_start(hs, False, False) vb2.pack_start(vs, True, True) vb2.pack_end(rg, False, False) hb.pack_start(vb1, True, True) hb.pack_start(vb2, False, False) win.add(hb) # Make all widgets except the window visible, so that a simple "show" # will suffice to show the window hb.show_all() # We define this handler here so that it will be defined before # the default key-press handler, and so will have higher priority. self.keypress_handler = self.sourceview.connect( 'key-press-event', self.on_keypress) self.sourceview.handler_block(self.keypress_handler) self.keypress_handler_blocked = True
def get_color(logicalcolorname): settings = gtk.settings_get_default() color_style = gtk.rc_get_style_by_paths(settings, "GtkButton", "osso-logical-colors", gtk.Button) return color_style.lookup_color(logicalcolorname)
def __init__(self, markup, parent_win=None): gtk.Window.__init__(self, gtk.WINDOW_POPUP) # Inherit the system theme for a tooltip style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), 'gtk-tooltip', 'gtk-tooltip', gobject.TYPE_NONE) self.set_style(style) # The placement of the close button on the tip should reflect how the # window manager of the users system places close buttons. Try to read # the metacity gconf key to determine whether the close button is on the # left or the right. # In the case that we can't determine the users configuration we default # to close buttons being on the right. __button_right = True try: client = gconf.client_get_default() order = client.get_string("/apps/metacity/general/button_layout") if order and order.endswith(":"): __button_right = False except NameError: pass # We need to ensure we're only shown once self.shown = False # We don't want any WM decorations self.set_decorated(False) # We don't want to show in the taskbar or window switcher self.set_skip_pager_hint(True) self.set_skip_taskbar_hint(True) # We must be modal to ensure we grab focus when presented from a gtk.Dialog self.set_modal(True) self.set_border_width(0) self.set_position(gtk.WIN_POS_MOUSE) self.set_opacity(0.95) # Ensure a reasonable minimum size self.set_geometry_hints(self, 100, 50) # Set this window as a transient window for parent(main window) if parent_win: self.set_transient_for(parent_win) self.set_destroy_with_parent(True) # Draw our label and close buttons hbox = gtk.HBox(False, 0) hbox.show() self.add(hbox) img = gtk.Image() img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON) self.button = gtk.Button() self.button.set_image(img) self.button.connect("clicked", self._dismiss_cb) self.button.set_flags(gtk.CAN_DEFAULT) self.button.grab_focus() self.button.show() vbox = gtk.VBox(False, 0) vbox.show() vbox.pack_start(self.button, False, False, 0) if __button_right: hbox.pack_end(vbox, True, True, 0) else: hbox.pack_start(vbox, True, True, 0) self.set_default(self.button) bin = gtk.HBox(True, 6) bin.set_border_width(6) bin.show() self.label = gtk.Label() self.label.set_line_wrap(True) # We want to match the colours of the normal tooltips, as dictated by # the users gtk+-2.0 theme, wherever possible - on some systems this # requires explicitly setting a fg_color for the label which matches the # tooltip_fg_color settings = gtk.settings_get_default() colours = settings.get_property('gtk-color-scheme').split('\n') # remove any empty lines, there's likely to be a trailing one after # calling split on a dictionary-like string colours = filter(None, colours) for col in colours: item, val = col.split(': ') if item == 'tooltip_fg_color': style = self.label.get_style() style.fg[gtk.STATE_NORMAL] = gtk.gdk.color_parse(val) self.label.set_style(style) break # we only care for the tooltip_fg_color self.label.set_markup(markup) self.label.show() bin.add(self.label) hbox.pack_end(bin, True, True, 6) # add the original URL display for user reference if 'a href' in markup: hbox.set_tooltip_text(self.get_markup_url(markup)) hbox.show() self.connect("key-press-event", self._catch_esc_cb)
def get_font_desc(self, logicalfontname): settings = gtk.settings_get_default() font_style = gtk.rc_get_style_by_paths(settings, logicalfontname, \ None, None) font_desc = font_style.font_desc return font_desc
def getHighlightColor(): style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), "GtkTextView", "GtkTextView", gtk.TextView) c = RGBA() c.setGdk(style.bg[gtk.STATE_SELECTED]) return c
def get_color(self, logicalcolorname): settings = gtk.settings_get_default() color_style = gtk.rc_get_style_by_paths(settings, 'GtkButton', \ 'osso-logical-colors', gtk.Button) return color_style.lookup_color(logicalcolorname)
def __init__(self, markup): gtk.Window.__init__(self, gtk.WINDOW_POPUP) # The placement of the close button on the tip should reflect how the # window manager of the users system places close buttons. Try to read # the metacity gconf key to determine whether the close button is on the # left or the right. # In the case that we can't determine the users configuration we default # to close buttons being on the right. __button_right = True try: client = gconf.client_get_default() order = client.get_string("/apps/metacity/general/button_layout") if order and order.endswith(":"): __button_right = False except NameError: pass # We need to ensure we're only shown once self.shown = False # We don't want any WM decorations self.set_decorated(False) # We don't want to show in the taskbar or window switcher self.set_skip_pager_hint(True) self.set_skip_taskbar_hint(True) # We must be modal to ensure we grab focus when presented from a gtk.Dialog self.set_modal(True) self.set_border_width(6) self.set_position(gtk.WIN_POS_MOUSE) self.set_opacity(0.95) # Draw our label and close buttons hbox = gtk.HBox(False, 0) hbox.show() vbox = gtk.VBox(False, 0) vbox.show() vbox.pack_start(hbox, True, True, 0) img = gtk.Image() img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_BUTTON) self.button = gtk.Button() self.button.set_image(img) self.button.connect("clicked", self._dismiss_cb) self.button.set_can_default(True) self.button.grab_focus() self.button.show() if __button_right: hbox.pack_end(self.button, False, False, 0) else: hbox.pack_start(self.button, False, False, 0) self.set_default(self.button) self.label = gtk.Label() self.label.set_markup(markup) self.label.show() vbox.pack_end(self.label, True, True, 6) self.connect("key-press-event", self._catch_esc_cb) # Inherit the system theme for a tooltip style = gtk.rc_get_style_by_paths(gtk.settings_get_default(), 'gtk-tooltip', 'gtk-tooltip', gobject.TYPE_NONE) self.set_style(style) self.add(vbox)