def _apply_css(config): if OSDWindow.css_provider: Gtk.StyleContext.remove_provider_for_screen( Gdk.Screen.get_default(), OSDWindow.css_provider) colors = {} for x in config['osk_colors'] : colors["osk_%s" % (x,)] = config['osk_colors'][x] for x in config['osd_colors'] : colors[x] = config['osd_colors'][x] colors = OSDCssMagic(colors) try: css_file = os.path.join(get_share_path(), "osd-styles", config["osd_style"]) css = file(css_file, "r").read() if ((Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 20)): css += OSDWindow.CSS_3_20 OSDWindow.css_provider = Gtk.CssProvider() OSDWindow.css_provider.load_from_data((css % colors).encode("utf-8")) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), OSDWindow.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER) except GLib.Error, e: log.error("Failed to apply css with user settings:") log.error(e) log.error("Retrying with default values") OSDWindow.css_provider = Gtk.CssProvider() css_file = os.path.join(get_share_path(), "osd-styles", "Classic.gtkstyle.css") css = file(css_file, "r").read() if ((Gtk.get_major_version(), Gtk.get_minor_version()) > (3, 20)): css += OSDWindow.CSS_3_20 OSDWindow.css_provider.load_from_data((css % colors).encode("utf-8")) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), OSDWindow.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
def __init__(self, cls="osd-menu"): OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.feedback = None self.controller = None self.xdisplay = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Magic cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursor = Gtk.Image.new_from_file(cursor) self.cursor.set_name("osd-menu-cursor") self.parent = self.create_parent() self.f = Gtk.Fixed() self.f.add(self.parent) self.add(self.f) self._submenu = None self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._is_submenu = False self._selected = None self._menuid = None self._use_cursor = False self._eh_ids = [] self._control_with = STICK self._control_with_dpad = False self._confirm_with = 'A' self._cancel_with = 'B'
def __init__(self, cls="osd-menu"): OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.xdisplay = X.Display(hash( GdkX11.x11_get_default_xdisplay())) # Magic cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursor = Gtk.Image.new_from_file(cursor) self.cursor.set_name("osd-menu-cursor") self.parent = self.create_parent() self.f = Gtk.Fixed() self.f.add(self.parent) self.add(self.f) self._submenu = None self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._is_submenu = False self._selected = None self._menuid = None self._use_cursor = False self._eh_ids = [] self._control_with = STICK self._confirm_with = 'A' self._cancel_with = 'B'
def create_parent(self): background = os.path.join(get_share_path(), "images", 'radial-menu.svg') self.b = SVGWidget(background) self.b.connect('size-allocate', self.on_size_allocate) self.recolor() return self.b
def __init__(self): OSDWindow.__init__(self, "osd-keyboard") TimerManager.__init__(self) self.daemon = None self.mapper = None self.keymap = Gdk.Keymap.get_default() self.keymap.connect('state-changed', self.on_state_changed) self.profile = Profile(TalkingActionParser()) kbimage = os.path.join(get_config_path(), 'keyboard.svg') if not os.path.exists(kbimage): # Prefer image in ~/.config/scc, but load default one as fallback kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg') self.background = SVGWidget(self, kbimage) self.limits = {} self.limits[LEFT] = self.background.get_rect_area( self.background.get_element("LIMIT_LEFT")) self.limits[RIGHT] = self.background.get_rect_area( self.background.get_element("LIMIT_RIGHT")) cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = {} self.cursors[LEFT] = Gtk.Image.new_from_file(cursor) self.cursors[LEFT].set_name("osd-keyboard-cursor") self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor) self.cursors[RIGHT].set_name("osd-keyboard-cursor") self._eh_ids = [] self._stick = 0, 0 self._hovers = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None} self._pressed = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None} self.c = Gtk.Box() self.c.set_name("osd-keyboard-container") self.f = Gtk.Fixed() self.f.add(self.background) self.f.add(self.cursors[LEFT]) self.f.add(self.cursors[RIGHT]) self.c.add(self.f) self.add(self.c) self.timer('labels', 0.1, self.update_labels)
def set_help(self): """ Updates help shown on keyboard image. Keyboard bindings don't change on the fly, so this is done only right after start or when daemon is reconfigured. """ if self._controller is None: # Not yet connected return gui_config = self._controller.load_gui_config( os.path.join(get_share_path(), "images")) l_lines, r_lines, used = [], [], set() def add_action(side, button, a): if not a: return if isinstance(a, scc.osd.osk_actions.OSKCursorAction): if a.side != CPAD: return if isinstance(a, ModeModifier): for x in a.get_child_actions(): add_action(side, button, x) return desc = a.describe(Action.AC_OSK) if desc in used: if isinstance(a, scc.osd.osk_actions.OSKPressAction): # Special case, both triggers are set to "press a key" pass else: return icon = self._controller.get_button_name(gui_config, button) side.append((icon, desc)) used.add(desc) def add_button(side, b): add_action(side, b, self.profile.buttons[b]) if self._controller.get_flags() & ControllerFlags.NO_GRIPS == 0: add_button(l_lines, SCButtons.LGRIP) add_button(r_lines, SCButtons.RGRIP) add_action(l_lines, SCButtons.LT, self.profile.triggers[LEFT]) add_action(r_lines, SCButtons.RT, self.profile.triggers[RIGHT]) for b in (SCButtons.LB, SCButtons.Y, SCButtons.X): add_button(l_lines, b) for b in (SCButtons.RB, SCButtons.B, SCButtons.A): add_button(r_lines, b) if self._controller.get_flags() & ControllerFlags.HAS_CPAD != 0: for lst in (l_lines, r_lines): while len(lst) > 3: lst.pop() while len(lst) < 3: lst.append((None, "")) add_action(r_lines, CPAD, self.profile.pads[CPAD]) add_action(l_lines, SCButtons.STICKPRESS, self.profile.stick) self.background.set_help(l_lines, r_lines)
def __init__(self): OSDWindow.__init__(self, "osd-keyboard") TimerManager.__init__(self) self.daemon = None self.keyboard = None self.keymap = Gdk.Keymap.get_default() self.keymap.connect('state-changed', self.on_state_changed) kbimage = os.path.join(get_config_path(), 'keyboard.svg') if not os.path.exists(kbimage): # Prefer image in ~/.config/scc, but load default one as fallback kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg') self.background = SVGWidget(self, kbimage) self.limit_left = self.background.get_rect_area(self.background.get_element("LIMIT_LEFT")) self.limit_right = self.background.get_rect_area(self.background.get_element("LIMIT_RIGHT")) cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursor_left = Gtk.Image.new_from_file(cursor) self.cursor_left.set_name("osd-keyboard-cursor") self.cursor_right = Gtk.Image.new_from_file(cursor) self.cursor_right.set_name("osd-keyboard-cursor") self._eh_ids = [] self._stick = 0, 0 self._hovers = { self.cursor_left : None, self.cursor_right : None } self._pressed = { self.cursor_left : None, self.cursor_right : None } self.c = Gtk.Box() self.c.set_name("osd-keyboard-container") self.f = Gtk.Fixed() self.f.add(self.background) self.f.add(self.cursor_left) self.f.add(self.cursor_right) self.c.add(self.f) self.add(self.c) self.set_cursor_position(0, 0, self.cursor_left, self.limit_left) self.set_cursor_position(0, 0, self.cursor_right, self.limit_right) self.timer('labels', 0.1, self.update_labels)
def recolor(self): config = Config() source_colors = {} try: # Try to read json file and bail out if it fails desc = os.path.join(get_share_path(), "images", 'radial-menu.svg.json') source_colors = json.loads(open(desc, "r").read())['colors'] except Exception, e: log.warning("Failed to load keyboard description") log.warning(e) return
def __init__(self, config=None): self.kbimage = os.path.join(get_config_path(), 'keyboard.svg') if not os.path.exists(self.kbimage): # Prefer image in ~/.config/scc, but load default one as fallback self.kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg') TimerManager.__init__(self) OSDWindow.__init__(self, "osd-keyboard") self.daemon = None self.mapper = None self.keymap = Gdk.Keymap.get_default() self.keymap.connect('state-changed', self.on_keymap_state_changed) Action.register_all(sys.modules['scc.osd.osk_actions'], prefix="OSK") self.profile = Profile(TalkingActionParser()) self.config = config or Config() self.dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) self.group = None self.limits = {} self.background = None cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = {} self.cursors[LEFT] = Gtk.Image.new_from_file(cursor) self.cursors[LEFT].set_name("osd-keyboard-cursor") self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor) self.cursors[RIGHT].set_name("osd-keyboard-cursor") self.cursors[CPAD] = Gtk.Image.new_from_file(cursor) self.cursors[CPAD].set_name("osd-keyboard-cursor") self._eh_ids = [] self._controller = None self._stick = 0, 0 self._hovers = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None} self._pressed = {self.cursors[LEFT]: None, self.cursors[RIGHT]: None} self._pressed_areas = {} self.c = Gtk.Box() self.c.set_name("osd-keyboard-container") self.f = Gtk.Fixed()
def set_help(self): """ Updates help shown on keyboard image. Keyboard bindings don't change on the fly, so this is done only right after start or when daemon is reconfigured. """ if self._controller is None: # Not yet connected return gui_config = self._controller.load_gui_config(os.path.join(get_share_path(), "images")) l_lines, r_lines, used = [], [], set() def add_action(side, button, a): if not a: return if isinstance(a, scc.osd.osk_actions.OSKCursorAction): if a.side != CPAD: return if isinstance(a, ModeModifier): for x in a.get_child_actions(): add_action(side, button, x) return desc = a.describe(Action.AC_OSK) if desc in used: if isinstance(a, scc.osd.osk_actions.OSKPressAction): # Special case, both triggers are set to "press a key" pass else: return icon = self._controller.get_button_name(gui_config, button) side.append(( icon, desc )) used.add(desc) def add_button(side, b): add_action(side, b, self.profile.buttons[b]) if self._controller.get_flags() & ControllerFlags.NO_GRIPS == 0: add_button(l_lines, SCButtons.LGRIP) add_button(r_lines, SCButtons.RGRIP) add_action(l_lines, SCButtons.LT, self.profile.triggers[LEFT]) add_action(r_lines, SCButtons.RT, self.profile.triggers[RIGHT]) for b in (SCButtons.LB, SCButtons.Y, SCButtons.X): add_button(l_lines, b) for b in (SCButtons.RB, SCButtons.B, SCButtons.A): add_button(r_lines, b) if self._controller.get_flags() & ControllerFlags.HAS_CPAD != 0: for lst in (l_lines, r_lines): while len(lst) > 3: lst.pop() while len(lst) < 3: lst.append((None, "")) add_action(r_lines, CPAD, self.profile.pads[CPAD]) add_action(l_lines, SCButtons.STICKPRESS, self.profile.stick) self.background.set_help(l_lines, r_lines)
def __init__(self, config=None): self.kbimage = os.path.join(get_config_path(), 'keyboard.svg') if not os.path.exists(self.kbimage): # Prefer image in ~/.config/scc, but load default one as fallback self.kbimage = os.path.join(get_share_path(), "images", 'keyboard.svg') TimerManager.__init__(self) OSDWindow.__init__(self, "osd-keyboard") self.daemon = None self.mapper = None self.keymap = Gdk.Keymap.get_default() self.keymap.connect('state-changed', self.on_keymap_state_changed) Action.register_all(sys.modules['scc.osd.osk_actions'], prefix="OSK") self.profile = Profile(TalkingActionParser()) self.config = config or Config() self.dpy = X.Display(hash(GdkX11.x11_get_default_xdisplay())) self.group = None self.limits = {} self.background = None cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = {} self.cursors[LEFT] = Gtk.Image.new_from_file(cursor) self.cursors[LEFT].set_name("osd-keyboard-cursor") self.cursors[RIGHT] = Gtk.Image.new_from_file(cursor) self.cursors[RIGHT].set_name("osd-keyboard-cursor") self.cursors[CPAD] = Gtk.Image.new_from_file(cursor) self.cursors[CPAD].set_name("osd-keyboard-cursor") self._eh_ids = [] self._controller = None self._stick = 0, 0 self._hovers = { self.cursors[LEFT]: None, self.cursors[RIGHT]: None } self._pressed = { self.cursors[LEFT]: None, self.cursors[RIGHT]: None } self._pressed_areas = {} self.c = Gtk.Box() self.c.set_name("osd-keyboard-container") self.f = Gtk.Fixed()
def success(*a): log.error("Sucessfully locked input") config = self.controller.load_gui_config(os.path.join( get_share_path(), "images")) if config and config["gui"] and config["gui"]["buttons"]: buttons = config["gui"]["buttons"] try: for i in xrange(len(self._icons)): icon = self._icons[i] name = buttons[self.BUTTON_INDEXES[i]] filename, trash = find_icon("buttons/%s" % name) icon.set_filename(filename) icon.queue_draw() except IndexError: pass
def success(*a): log.error("Sucessfully locked input") config = self.controller.load_gui_config( os.path.join(get_share_path(), "images")) if config and config["gui"] and config["gui"]["buttons"]: buttons = config["gui"]["buttons"] try: for i in xrange(len(self._icons)): icon = self._icons[i] name = buttons[self.BUTTON_INDEXES[i]] filename, trash = find_icon("buttons/%s" % name) icon.set_filename(filename) icon.queue_draw() except IndexError: pass
def on_cbOSDColorPreset_changed(self, cb): theme = cb.get_model().get_value(cb.get_active_iter(), 0) if theme in (None, "None"): return filename = os.path.join(get_share_path(), "osd-styles", theme) data = json.loads(file(filename, "r").read()) # Transfer values from json to config for grp in ("osd_colors", "osk_colors"): if grp in data: for subkey in self.app.config[grp]: if subkey in data[grp]: self.app.config[grp][subkey] = data[grp][subkey] # Save self.app.config["osd_color_theme"] = theme self.app.save_config()
def __init__(self, cls="osd-menu"): self._buttons = None self._string = "" OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.feedback = None self.controller = None self.xdisplay = X.Display(hash( GdkX11.x11_get_default_xdisplay())) # Magic self.create_parent() self.create_app_list() self.create_buttons() cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = [ Gtk.Image.new_from_file(cursor), Gtk.Image.new_from_file(cursor) ] for c in self.cursors: c.set_name("osd-menu-cursor") c.selected = None self.f.add(c) self.f.show_all() self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._selected = None self._menuid = None self._eh_ids = [] self._confirm_with = 'A' self._cancel_with = 'B' if Launcher._app_db is None: Launcher._app_db = [] for x in Launcher.BUTTONS: for c in x: Launcher.CHAR_TO_NUMBER[c] = x[0] for x in Gio.AppInfo.get_all(): try: Launcher._app_db.append((Launcher.name_to_keys(x), x)) except UnicodeDecodeError: # Just f**k them... pass
def __init__(self, config=None): self.bdisplay = os.path.join(get_config_path(), 'binding-display.svg') if not os.path.exists(self.bdisplay): # Prefer image in ~/.config/scc, but load default one as fallback self.bdisplay = os.path.join(get_share_path(), "images", 'binding-display.svg') OSDWindow.__init__(self, "osd-keyboard") self.daemon = None self.config = config or Config() self.group = None self.limits = {} self.background = None self._eh_ids = [] self._stick = 0, 0 self.c = Gtk.Box() self.c.set_name("osd-keyboard-container")
def __init__(self, cls="osd-menu"): self._buttons = None self._string = "" OSDWindow.__init__(self, cls) self.daemon = None self.config = None self.feedback = None self.controller = None self.xdisplay = X.Display(hash(GdkX11.x11_get_default_xdisplay())) # Magic self.create_parent() self.create_app_list() self.create_buttons() cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursors = [ Gtk.Image.new_from_file(cursor), Gtk.Image.new_from_file(cursor) ] for c in self.cursors: c.set_name("osd-menu-cursor") c.selected = None self.f.add(c) self.f.show_all() self._scon = StickController() self._scon.connect("direction", self.on_stick_direction) self._selected = None self._menuid = None self._eh_ids = [] self._confirm_with = 'A' self._cancel_with = 'B' if Launcher._app_db is None: Launcher._app_db = [] for x in Launcher.BUTTONS: for c in x: Launcher.CHAR_TO_NUMBER[c] = x[0] for x in Gio.AppInfo.get_all(): try: Launcher._app_db.append(( Launcher.name_to_keys(x), x )) except UnicodeDecodeError: # Just f**k them... pass
def __init__(self): OSDWindow.__init__(self, "osd-menu") TimerManager.__init__(self) self.daemon = None cursor = os.path.join(get_share_path(), "images", 'menu-cursor.svg') self.cursor = Gtk.Image.new_from_file(cursor) self.cursor.set_name("osd-menu-cursor") self.parent = self.create_parent() self.f = Gtk.Fixed() self.f.add(self.parent) self.add(self.f) self._direction = 0 # Movement direction self._selected = None self._menuid = None self._use_cursor = False self._eh_ids = [] self._control_with = STICK self._confirm_with = 'A' self._cancel_with = 'B'
def on_cbOSDStyle_changed(self, cb): color_keys = self.app.config['osk_colors'].keys( ) + self.app.config['osd_colors'].keys() osd_style = cb.get_model().get_value(cb.get_active_iter(), 0) css_file = os.path.join(get_share_path(), "osd-styles", osd_style) first_line = file(css_file, "r").read().split("\n")[0] used_colors = None # None means "all" if "Used colors:" in first_line: used_colors = set( first_line.split(":", 1)[1].strip(" */").split(" ")) if "all" in used_colors: used_colors = None # None means "all" for key in color_keys: cb = self.builder.get_object("cb%s" % (key, )) lbl = self.builder.get_object("lbl%s" % (key, )) if cb: cb.set_sensitive((used_colors is None) or (key in used_colors)) if lbl: lbl.set_sensitive((used_colors is None) or (key in used_colors)) self.app.config["osd_style"] = osd_style self.app.save_config()
def create_parent(self): background = os.path.join(get_share_path(), "images", 'radial-menu.svg') self.b = SVGWidget(self, background) return self.b