Replace deprecated override_background_color()

This commit is contained in:
Philipp Hörist 2017-12-18 00:11:39 +01:00
parent f4a6b0299a
commit bdf16c5182
3 changed files with 28 additions and 11 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 --> <!-- Generated with glade 3.20.1 -->
<interface> <interface>
<requires lib="gtk+" version="3.12"/> <requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="popup_notification_window"> <object class="GtkWindow" id="popup_notification_window">
@ -16,6 +16,7 @@
<signal name="button-press-event" handler="on_popup_notification_window_button_press_event" swapped="no"/> <signal name="button-press-event" handler="on_popup_notification_window_button_press_event" swapped="no"/>
<child> <child>
<object class="GtkEventBox" id="eventbox"> <object class="GtkEventBox" id="eventbox">
<property name="name">PopupNotificationEventBox</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
@ -116,5 +117,8 @@
</child> </child>
</object> </object>
</child> </child>
<child type="titlebar">
<placeholder/>
</child>
</object> </object>
</interface> </interface>

View File

@ -3114,10 +3114,10 @@ class PopupNotificationWindow:
self.jid = jid self.jid = jid
self.msg_type = msg_type self.msg_type = msg_type
self.index = len(app.interface.roster.popup_notification_windows) self.index = len(app.interface.roster.popup_notification_windows)
xml = gtkgui_helpers.get_gtk_builder('popup_notification_window.ui') xml = gtkgui_helpers.get_gtk_builder('popup_notification_window.ui')
self.window = xml.get_object('popup_notification_window') self.window = xml.get_object('popup_notification_window')
self.window.set_type_hint(Gdk.WindowTypeHint.TOOLTIP) self.window.set_type_hint(Gdk.WindowTypeHint.TOOLTIP)
self.window.set_name('NotificationPopup')
close_button = xml.get_object('close_button') close_button = xml.get_object('close_button')
event_type_label = xml.get_object('event_type_label') event_type_label = xml.get_object('event_type_label')
event_description_label = xml.get_object('event_description_label') event_description_label = xml.get_object('event_description_label')
@ -3133,10 +3133,8 @@ class PopupNotificationWindow:
'<span foreground="black" weight="bold">%s</span>' % '<span foreground="black" weight="bold">%s</span>' %
GLib.markup_escape_text(title)) GLib.markup_escape_text(title))
# set colors [ http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html ] css = '#NotificationPopup {background-color: black }'
color = Gdk.RGBA() gtkgui_helpers.add_css_to_widget(self.window, css)
Gdk.RGBA.parse(color, 'black')
self.window.override_background_color(Gtk.StateType.NORMAL, color)
# default image # default image
if not path_to_image: if not path_to_image:
@ -3162,11 +3160,19 @@ class PopupNotificationWindow:
bg_color = app.config.get('notif_status_color') bg_color = app.config.get('notif_status_color')
else: # Unknown event! Shouldn't happen but deal with it else: # Unknown event! Shouldn't happen but deal with it
bg_color = app.config.get('notif_other_color') bg_color = app.config.get('notif_other_color')
popup_bg_color = Gdk.RGBA()
Gdk.RGBA.parse(popup_bg_color, bg_color) background_class = '''
close_button.override_background_color(Gtk.StateType.NORMAL, .popup-style {
popup_bg_color) border-image: none;
eventbox.override_background_color(Gtk.StateType.NORMAL, popup_bg_color) background-image: none;
background-color: %s }''' % bg_color
gtkgui_helpers.add_css_to_widget(eventbox, background_class)
eventbox.get_style_context().add_class('popup-style')
gtkgui_helpers.add_css_to_widget(close_button, background_class)
eventbox.get_style_context().add_class('popup-style')
event_description_label.set_markup('<span foreground="black">%s</span>' % event_description_label.set_markup('<span foreground="black">%s</span>' %
GLib.markup_escape_text(text)) GLib.markup_escape_text(text))

View File

@ -851,6 +851,13 @@ def add_css_class(widget, class_name):
if class_name: if class_name:
style.add_class('theme_' + class_name) style.add_class('theme_' + class_name)
def add_css_to_widget(widget, css):
provider = Gtk.CssProvider()
provider.load_from_data(bytes(css.encode()))
context = widget.get_style_context()
context.add_provider(provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
def remove_css_class(widget, class_name): def remove_css_class(widget, class_name):
style = widget.get_style_context() style = widget.get_style_context()
style.remove_class('theme_' + class_name) style.remove_class('theme_' + class_name)