Skip to content

Commit

Permalink
Ubuntu is an ancient African word for not being able to keep up-to-da…
Browse files Browse the repository at this point in the history
…te Debian
  • Loading branch information
kozec committed Apr 28, 2016
1 parent 7f2b691 commit 83acf93
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app.glade
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar" id="headerbar1">
<object class="GtkHeaderBar" id="hbWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
Expand Down
2 changes: 2 additions & 0 deletions scc/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from scc.gui.action_editor import ActionEditor
from scc.gui.parser import GuiActionParser
from scc.gui.svg_widget import SVGWidget
from scc.gui.dwsnc import headerbar
from scc.gui.ribar import RIBar
from scc.paths import get_daemon_path, get_config_path, get_profiles_path
from scc.constants import SCButtons
Expand Down Expand Up @@ -99,6 +100,7 @@ def setup_widgets(self):
self.background.connect('click', self.on_background_area_click)
main_area.put(self.background, 0, 0)
main_area.put(vbc, 0, 0) # (self.IMAGE_SIZE[0] / 2) - 90, self.IMAGE_SIZE[1] - 100)
headerbar(self.builder.get_object("hbWindow"))


def check(self):
Expand Down
2 changes: 2 additions & 0 deletions scc/gui/button_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from scc.actions import HatLeftAction, HatRightAction
from scc.actions import HatUpAction, HatDownAction
from scc.gui.editor import Editor
from scc.gui.dwsnc import headerbar
from scc.gui.svg_widget import SVGWidget
from scc.gui.gdk_to_key import keyevent_to_key
from scc.gui.area_to_action import AREA_TO_ACTION
Expand Down Expand Up @@ -65,6 +66,7 @@ def setup_widgets(self):
self.images.append(image)
parent.pack_start(image, True, True, 0)
parent.show_all()
headerbar(self.builder.get_object("header"))


def allow_axes(self):
Expand Down
64 changes: 64 additions & 0 deletions scc/gui/dwsnc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
DWSNC - Doing Weird Things in Name of Compatibility
This module, when imported, applies various fixes and monkey-patching to allow
application to run with older versions of GLib and/or GTK.
"""
from __future__ import unicode_literals
from gi.repository import Gtk, GObject
import os


def fix_label_missing_set_XYalign_methods():
"""
Fix Gtk.Label missing set_xalign and set_yalign methods with older
versions of Gtk.
Prevents crashing, but alings are ignored.
"""
Gtk.Label.set_xalign = Gtk.Label.set_yalign = lambda *a : None

def child_get_property(parent, child, propname):
"""
Wrapper for child_get_property, which pygobject doesn't properly
introspect
"""
value = GObject.Value()
value.init(GObject.TYPE_INT)
parent.child_get_property(child, propname, value)
return value.get_int()


def headerbar(bar):
"""
Moves all buttons from left to right (and vice versa) if user's desktop
environment is identified as Unity
"""
pass # Not outside of Unity

if "XDG_CURRENT_DESKTOP" in os.environ and "Unity" in os.environ["XDG_CURRENT_DESKTOP"].split(":"):
# User runs Unity
def _headerbar(bar):
children = [] + bar.get_children()
pack_start = []
pack_end = []
for c in children:
if child_get_property(bar, c, 'pack-type') == Gtk.PackType.END:
bar.remove(c)
pack_start.append(c)
else:
bar.remove(c)
pack_end.append(c)
if len(pack_end) > 1:
c, pack_end = pack_end[0], pack_end[1:]
pack_end.append(c)
if (Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 10):
# Old ubuntu has this in order, new Ubuntu has it reversed
pack_end = reversed(pack_end)
for c in pack_start: bar.pack_start(c)
for c in pack_end: bar.pack_end(c)
headerbar = _headerbar

if not hasattr(Gtk.Label, "set_xalign"):
# GTK is old enought
fix_label_missing_set_XYalign_methods()
2 changes: 2 additions & 0 deletions scc/gui/modeswitch_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from scc.gui.action_editor import ActionEditor
from scc.gui.editor import Editor
from scc.constants import SCButtons
from scc.gui.dwsnc import headerbar
from scc.actions import Action, NoAction
from scc.modifiers import ModeModifier
from scc.profile import Profile
Expand Down Expand Up @@ -67,6 +68,7 @@ def setup_widgets(self):
for button, text in self.BUTTONS:
model.append(( None if button is None else button.name, text ))
cbButtonChooser.set_active(0)
headerbar(self.builder.get_object("header"))


def _add_action(self, button, action):
Expand Down

0 comments on commit 83acf93

Please sign in to comment.