diff --git a/xinput_gui/__main__.py b/xinput_gui/__main__.py index 7433025..58bcdf1 100644 --- a/xinput_gui/__main__.py +++ b/xinput_gui/__main__.py @@ -26,3 +26,7 @@ def main(): view_controller = ViewController() view_controller.start() + + +if __name__ == "__main__": + main() diff --git a/xinput_gui/gui/device_list.py b/xinput_gui/gui/device_list.py index 6d1d24b..35e27af 100644 --- a/xinput_gui/gui/device_list.py +++ b/xinput_gui/gui/device_list.py @@ -23,7 +23,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename +from importlib.resources import as_file, files from ..settings import Settings from ..xinput.devices import Device, DeviceType @@ -60,12 +60,14 @@ def __init__(self, controller: 'ViewController', main_window: 'MainWindow', sett def get_builder(self) -> Gtk.Builder: '''Get device list Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['grid_device_list', 'store_devices']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['grid_device_list', 'store_devices']) + return builder def apply_settings(self) -> None: '''Apply current settings.''' diff --git a/xinput_gui/gui/dialog_about.py b/xinput_gui/gui/dialog_about.py index eea9bfb..529bb0a 100644 --- a/xinput_gui/gui/dialog_about.py +++ b/xinput_gui/gui/dialog_about.py @@ -21,10 +21,11 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import require, resource_filename +from importlib.resources import as_file, files +from importlib.metadata import version -__version__ = require('xinput_gui')[0].version +__version__ = version('xinput_gui') class AboutDialog: @@ -44,12 +45,14 @@ def __init__(self, main_window) -> None: def get_builder(self) -> Gtk.Builder: '''Get about dialog Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['dialog_about']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['dialog_about']) + return builder def show(self) -> None: '''Show the about dialog.''' diff --git a/xinput_gui/gui/dialog_create_master.py b/xinput_gui/gui/dialog_create_master.py index c396819..edc0814 100644 --- a/xinput_gui/gui/dialog_create_master.py +++ b/xinput_gui/gui/dialog_create_master.py @@ -23,7 +23,8 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename + +from importlib.resources import files, as_file if TYPE_CHECKING: from ..view_controller import ViewController @@ -51,11 +52,14 @@ def __init__(self, controller: 'ViewController', main_window: 'MainWindow') -> N def get_builder(self) -> Gtk.Builder: '''Get create master device dialog Gtk Builder.''' - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['dialog_create_master']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['dialog_create_master']) + return builder def show(self) -> Gtk.ResponseType: '''Show the create master device dialog.''' diff --git a/xinput_gui/gui/dialog_device_info.py b/xinput_gui/gui/dialog_device_info.py index 29b5f8c..7222f0c 100644 --- a/xinput_gui/gui/dialog_device_info.py +++ b/xinput_gui/gui/dialog_device_info.py @@ -23,10 +23,11 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename from ..xinput.devices import Device +from importlib.resources import as_file, files + if TYPE_CHECKING: from ..view_controller import ViewController from .win_main import MainWindow @@ -49,12 +50,14 @@ def __init__(self, controller: 'ViewController', main_window: 'MainWindow') -> N def get_builder(self) -> Gtk.Builder: '''Get device info dialog Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['dialog_device_info', 'buffer_device_info']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['dialog_device_info', 'buffer_device_info']) + return builder def show(self, device: Device) -> None: '''Show the device info dialog. diff --git a/xinput_gui/gui/dialog_edit.py b/xinput_gui/gui/dialog_edit.py index 2871b16..bc010cb 100644 --- a/xinput_gui/gui/dialog_edit.py +++ b/xinput_gui/gui/dialog_edit.py @@ -23,7 +23,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename +from importlib.resources import files, as_file from ..xinput.devices import Device, Prop @@ -54,12 +54,14 @@ def __init__(self, controller: 'ViewController', main_window: 'MainWindow') -> N def get_builder(self) -> Gtk.Builder: '''Get edit dialog Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['dialog_edit']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['dialog_edit']) + return builder def show(self, device: Device, diff --git a/xinput_gui/gui/dialog_reattach.py b/xinput_gui/gui/dialog_reattach.py index 984f446..88b53dd 100644 --- a/xinput_gui/gui/dialog_reattach.py +++ b/xinput_gui/gui/dialog_reattach.py @@ -23,7 +23,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename +from importlib.resources import as_file, files from ..xinput.devices import Device, DeviceType @@ -53,11 +53,14 @@ def __init__(self, controller: 'ViewController', main_window: 'MainWindow') -> N def get_builder(self) -> Gtk.Builder: '''Get reattach dialog Gtk Builder.''' - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['dialog_reattach', 'store_reattach']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['dialog_reattach', 'store_reattach']) + return builder def show(self, selected_device: Device, devices: List[Device]) -> Gtk.ResponseType: '''Show the reattach dialog. diff --git a/xinput_gui/gui/log.py b/xinput_gui/gui/log.py index 51657d6..181c43c 100644 --- a/xinput_gui/gui/log.py +++ b/xinput_gui/gui/log.py @@ -23,7 +23,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename +from importlib.resources import as_file, files if TYPE_CHECKING: from .win_main import MainWindow @@ -48,12 +48,14 @@ def __init__(self, main_window: 'MainWindow'): def get_builder(self) -> Gtk.Builder: '''Get device list Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['grid_log', 'buffer_log']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['grid_log', 'buffer_log']) + return builder def clear_log(self) -> None: '''Clear the log.''' diff --git a/xinput_gui/gui/prop_list.py b/xinput_gui/gui/prop_list.py index 70ec164..5b33307 100644 --- a/xinput_gui/gui/prop_list.py +++ b/xinput_gui/gui/prop_list.py @@ -23,7 +23,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename +from importlib.resources import as_file, files from ..settings import Settings from ..xinput.devices import Device @@ -60,12 +60,14 @@ def __init__(self, controller: 'ViewController', main_window: 'MainWindow', sett def get_builder(self) -> Gtk.Builder: '''Get prop list Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['grid_prop_list', 'store_props']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['grid_prop_list', 'store_props']) + return builder def apply_settings(self) -> None: '''Apply current settings.''' diff --git a/xinput_gui/gui/win_main.py b/xinput_gui/gui/win_main.py index 7b6f2a8..0f1f9c5 100644 --- a/xinput_gui/gui/win_main.py +++ b/xinput_gui/gui/win_main.py @@ -23,7 +23,8 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import require, resource_filename +from importlib.resources import as_file, files +from importlib.metadata import version from ..settings import Settings from .device_list import DeviceList @@ -36,7 +37,7 @@ from ..view_controller import ViewController -__version__ = require('xinput_gui')[0].version +__version__ = version("xinput_gui") class MainWindow: @@ -77,12 +78,13 @@ def __init__(self, controller: 'ViewController', settings: Settings) -> None: def get_builder(self) -> Gtk.Builder: '''Get main window Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['win_main']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['win_main']) + return builder def apply_settings(self) -> None: '''Apply current settings.''' diff --git a/xinput_gui/gui/win_settings.py b/xinput_gui/gui/win_settings.py index 1daf6b5..e7149a7 100644 --- a/xinput_gui/gui/win_settings.py +++ b/xinput_gui/gui/win_settings.py @@ -21,10 +21,10 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk -from pkg_resources import resource_filename - from ..settings import Settings +from importlib.resources import files, as_file + class SettingsWindow: '''Settings window.''' @@ -50,12 +50,14 @@ def __init__(self, main_window, settings: Settings) -> None: def get_builder(self) -> Gtk.Builder: '''Get settings window Gtk Builder.''' - - builder = Gtk.Builder() - builder.add_objects_from_file( - resource_filename('xinput_gui', 'res/xinput-gui.ui'), - ['win_settings']) - return builder + ref = files('xinput_gui') / 'res/xinput-gui.ui' + with as_file(ref) as path: + + builder = Gtk.Builder() + builder.add_objects_from_file( + str(path), + ['win_settings']) + return builder def show(self) -> None: '''Show the settings window.''' diff --git a/xinput_gui/settings.py b/xinput_gui/settings.py index 9ab9e6f..7bca02d 100644 --- a/xinput_gui/settings.py +++ b/xinput_gui/settings.py @@ -23,8 +23,7 @@ import json import os -from pkg_resources import resource_filename - +from importlib.resources import as_file, files CONFIG_PATH = Path(os.environ['HOME']).joinpath('.xinput-gui.json') @@ -46,10 +45,11 @@ def __init__(self): def load_config(self): '''Load config file.''' + ref = files('xinput_gui') / 'res/config.json' + with as_file(ref) as path: - # Create config if needed - if not CONFIG_PATH.is_file(): - copyfile(resource_filename('xinput_gui', 'res/config.json'), CONFIG_PATH) + if not CONFIG_PATH.is_file(): + copyfile(path, CONFIG_PATH) with open(CONFIG_PATH) as config_file: self.config = json.load(config_file)