Ejemplo n.º 1
0
    def __init__(self):
        self.dbus = get_dbus_interface()

        self.selected_device = None
        self.selected_preset = None

        css_provider = Gtk.CssProvider()
        with open(get_data_path('style.css'), 'r') as file:
            data = (file.read() + '\n.changed{background-color:' +
                    get_selected_row_bg() + ';}\n')
            css_provider.load_from_data(bytes(data, encoding='UTF-8'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), css_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        gladefile = get_data_path('key-mapper.glade')
        builder = Gtk.Builder()
        builder.add_from_file(gladefile)
        builder.connect_signals(self)
        self.builder = builder

        window = self.get('window')
        window.show()
        # hide everything until stuff is populated
        self.get('vertical-wrapper').set_opacity(0)
        self.window = window

        # if any of the next steps take a bit to complete, have the window
        # already visible (without content) to make it look more responsive.
        gtk_iteration()

        permission_errors = permissions.can_read_devices()
        if len(permission_errors) > 0:
            permission_errors = [
                ('Usually, key-mapper-gtk should be started with pkexec '
                 'or sudo.')
            ] + permission_errors
            self.show_status(CTX_ERROR, 'Permission error, hover for info',
                             '\n\n'.join(permission_errors))

        # this is not set to invisible in glade to give the ui a default
        # height that doesn't jump when a gamepad is selected
        self.get('gamepad_separator').hide()
        self.get('gamepad_config').hide()

        self.populate_devices()
        self.select_newest_preset()

        self.timeouts = [
            GLib.timeout_add(100, self.check_add_row),
            GLib.timeout_add(1000 / 30, self.consume_newest_keycode)
        ]

        # now show the proper finished content of the window
        self.get('vertical-wrapper').set_opacity(1)

        self.ctrl = 0
Ejemplo n.º 2
0
    def test_data_usr(self):
        path = '/usr/some/where/python3.8/dist-packages/'
        pkg_resources.require('key-mapper')[0].location = path

        self.assertTrue(get_data_path().startswith('/usr/'))
        self.assertTrue(get_data_path().endswith('key-mapper/'))

        self.assertTrue(get_data_path('a').startswith('/usr/'))
        self.assertTrue(get_data_path('a').endswith('key-mapper/a'))
Ejemplo n.º 3
0
def unsaved_changes_dialog():
    """Blocks until the user decided about an action."""
    gladefile = get_data_path('key-mapper.glade')
    builder = Gtk.Builder()
    builder.add_from_file(gladefile)
    dialog = builder.get_object('unsaved_changes')
    dialog.show()
    response = dialog.run()
    dialog.hide()

    if response == Gtk.ResponseType.ACCEPT:
        return CONTINUE

    return GO_BACK
Ejemplo n.º 4
0
    def __init__(self):
        self.dbus = None

        self.start_processes()

        self.selected_device = None
        self.selected_preset = None

        css_provider = Gtk.CssProvider()
        with open(get_data_path('style.css'), 'r') as file:
            css_provider.load_from_data(bytes(file.read(), encoding='UTF-8'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), css_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        gladefile = get_data_path('key-mapper.glade')
        builder = Gtk.Builder()
        builder.add_from_file(gladefile)
        builder.connect_signals(self)
        self.builder = builder

        # set up the device selection
        # https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html#the-view
        combobox = self.get('device_selection')
        self.device_store = Gtk.ListStore(str, str)
        combobox.set_model(self.device_store)
        renderer_icon = Gtk.CellRendererPixbuf()
        renderer_text = Gtk.CellRendererText()
        renderer_text.set_padding(5, 0)
        combobox.set_id_column(1)
        combobox.pack_start(renderer_icon, False)
        combobox.pack_start(renderer_text, False)
        combobox.add_attribute(renderer_icon, 'icon-name', 0)
        combobox.add_attribute(renderer_text, 'text', 1)

        self.confirm_delete = builder.get_object('confirm-delete')
        self.about = builder.get_object('about-dialog')
        self.about.connect('delete-event', on_close_about)
        # set_position needs to be done once initially, otherwise the
        # dialog is not centered when it is opened for the first time
        self.about.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)

        self.get('version-label').set_text(
            f'key-mapper {VERSION} {COMMIT_HASH[:7]}'
            f'\npython-evdev {EVDEV_VERSION}' if EVDEV_VERSION else '')

        window = self.get('window')
        window.show()
        # hide everything until stuff is populated
        self.get('vertical-wrapper').set_opacity(0)
        self.window = window

        # if any of the next steps take a bit to complete, have the window
        # already visible (without content) to make it look more responsive.
        gtk_iteration()

        # this is not set to invisible in glade to give the ui a default
        # height that doesn't jump when a gamepad is selected
        self.get('gamepad_separator').hide()
        self.get('gamepad_config').hide()

        self.populate_devices()

        self.timeouts = [
            GLib.timeout_add(100, self.check_add_row),
            GLib.timeout_add(1000 / 30, self.consume_newest_keycode)
        ]

        # now show the proper finished content of the window
        self.get('vertical-wrapper').set_opacity(1)

        self.ctrl = False
        self.unreleased_warn = False
        self.button_left_warn = False

        if not is_helper_running():
            self.show_status(CTX_ERROR, 'The helper did not start')
Ejemplo n.º 5
0
 def test_data_editable(self):
     path = os.getcwd()
     pkg_resources.require('key-mapper')[0].location = path
     self.assertEqual(get_data_path(), path + '/data/')
     self.assertEqual(get_data_path('a'), path + '/data/a')