Mercurial > system76-keyboard-colors
changeset 1:b6d0a1e6ba3a
Linter cleanup
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Tue, 02 Feb 2021 19:46:01 -0500 |
parents | 11a9d346aa7a |
children | 091a1f59a79c |
files | keyboard_colors/color_profile.py keyboard_colors/custom/custom.py main.py setup.cfg ui/main_window.py |
diffstat | 5 files changed, 123 insertions(+), 114 deletions(-) [+] |
line wrap: on
line diff
--- a/keyboard_colors/color_profile.py Wed Jan 27 21:02:30 2021 -0500 +++ b/keyboard_colors/color_profile.py Tue Feb 02 19:46:01 2021 -0500 @@ -4,62 +4,66 @@ import os import pathlib import sys +import types import uuid gi.require_version("Gtk", "3.0") -from gi.repository import Gtk -from gi.repository import GLib +from gi.repository import Gtk # noqa: E402 +from gi.repository import GLib # noqa: E402 + class ColorProfileBase: - type_name = '(no name)' + type_name = '(no name)' - def __init__(self): - self.name = '' - self.id = uuid.uuid4().hex + def __init__(self): + self.name = '' + self.id = uuid.uuid4().hex - def build_settings_ui(self): - glade_file = sys.modules[self.__module__].__file__.replace('.py', '.glade') - builder = Gtk.Builder() - builder.add_from_file(glade_file) - return builder.get_object('edit_profile_container') + def build_settings_ui(self): + glade_file = sys.modules[self.__module__].__file__.replace('.py', '.glade') + builder = Gtk.Builder() + builder.add_from_file(glade_file) + return builder.get_object('edit_profile_container') + class ProfileManager: - def __init__(self): - self.profiles = self.load_profiles() - self.save_profiles() + def __init__(self): + self.profiles = self.load_profiles() + self.save_profiles() - def get_types(self): - types = [] - profile_directory = os.path.dirname(os.path.realpath(__file__)) - (_, dirnames, _) = next(os.walk(profile_directory)) - for dirname in dirnames: - module_file = os.path.join(profile_directory, dirname, dirname + '.py') - if os.path.isfile(module_file): - profile_module = importlib.import_module('keyboard_colors.' + dirname + '.' + dirname) - profile_class = getattr(profile_module, 'ColorProfile') - types.append(profile_class) - return types + def get_types(self): + types = [] + profile_directory = os.path.dirname(os.path.realpath(__file__)) + (_, dirnames, _) = next(os.walk(profile_directory)) + for dirname in dirnames: + module_file = os.path.join(profile_directory, dirname, dirname + '.py') + if os.path.isfile(module_file): + module_name = 'keyboard_colors.' + dirname + '.' + dirname + profile_module = importlib.import_module(module_name) + profile_class = getattr(profile_module, 'ColorProfile') + types.append(profile_class) + return types - def config_path(self): - dir = GLib.get_user_config_dir() - if not os.path.isdir(dir): - os.mkdir(dir) - return os.path.join(dir, 'keyboard-color-profiles.conf') + def config_path(self): + dir = GLib.get_user_config_dir() + if not os.path.isdir(dir): + os.mkdir(dir) + return os.path.join(dir, 'keyboard-color-profiles.conf') - def load_profiles(self): - if os.path.isfile(self.config_path()): - data = pathlib.Path(self.config_path()).read_text('utf-8') - try: - return json.loads(data, object_hook=lambda d: SimpleNamespace(**d)) - except json.decoder.JSONDecodeError: - return [] - else: - return [] + def load_profiles(self): + if os.path.isfile(self.config_path()): + data = pathlib.Path(self.config_path()).read_text('utf-8') + try: + return json.loads(data, object_hook=lambda d: types.SimpleNamespace(**d)) + except json.decoder.JSONDecodeError: + return [] + else: + return [] - def save_profiles(self): - data = json.dumps(self.profiles, default=lambda o: o.__dict__) - pathlib.Path(self.config_path()).write_text(data, 'utf-8') + def save_profiles(self): + data = json.dumps(self.profiles, default=lambda o: o.__dict__) + pathlib.Path(self.config_path()).write_text(data, 'utf-8') - def get_profiles(self): - return self.profiles \ No newline at end of file + def get_profiles(self): + return self.profiles
--- a/keyboard_colors/custom/custom.py Wed Jan 27 21:02:30 2021 -0500 +++ b/keyboard_colors/custom/custom.py Tue Feb 02 19:46:01 2021 -0500 @@ -1,8 +1,9 @@ from keyboard_colors.color_profile import ColorProfileBase + class ColorProfile(ColorProfileBase): - type_name = 'Custom colors' + type_name = 'Custom colors' - def __init__(self): - super().__init__() \ No newline at end of file + def __init__(self): + super().__init__()
--- a/main.py Wed Jan 27 21:02:30 2021 -0500 +++ b/main.py Tue Feb 02 19:46:01 2021 -0500 @@ -1,7 +1,7 @@ from ui.main_window import MainWindow def main(): - MainWindow().init() + MainWindow().init() if __name__ == "__main__": - main() + main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.cfg Tue Feb 02 19:46:01 2021 -0500 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 99
--- a/ui/main_window.py Wed Jan 27 21:02:30 2021 -0500 +++ b/ui/main_window.py Tue Feb 02 19:46:01 2021 -0500 @@ -1,91 +1,93 @@ import gi import os -gi.require_version("Gtk", "3.0") from gi.repository import Gtk from keyboard_colors.color_profile import ProfileManager +gi.require_version("Gtk", "3.0") # from ui.keyboard_section import KeyboardSection + class MainWindow: - def init(self): - self.profile_manager = ProfileManager() + def init(self): + self.profile_manager = ProfileManager() - self.builder = Gtk.Builder() - dirname = os.path.dirname(os.path.realpath(__file__)) - self.builder.add_from_file(os.path.join(dirname, 'MainWindow.glade')) - self.builder.connect_signals(self) - window = self.builder.get_object('main_window') + self.builder = Gtk.Builder() + dirname = os.path.dirname(os.path.realpath(__file__)) + self.builder.add_from_file(os.path.join(dirname, 'MainWindow.glade')) + self.builder.connect_signals(self) + window = self.builder.get_object('main_window') - color_profile_list_store = self.builder.get_object('color_profile_list_store') - # color_profile_list_store.append(["1", "test"]) + color_profile_list_store = self.builder.get_object('color_profile_list_store') + # color_profile_list_store.append(["1", "test"]) - keyboard_section = self.builder.get_object('keyboard_section') - keyboard_section.pack_start(KeyboardSection(color_profile_list_store), False, False, 0) - keyboard_section.pack_start(KeyboardSection(color_profile_list_store), False, False, 0) - keyboard_section.pack_start(KeyboardSection(color_profile_list_store), False, False, 0) + keyboard_section = self.builder.get_object('keyboard_section') + keyboard_section.pack_start(KeyboardSection(color_profile_list_store), False, False, 0) + keyboard_section.pack_start(KeyboardSection(color_profile_list_store), False, False, 0) + keyboard_section.pack_start(KeyboardSection(color_profile_list_store), False, False, 0) - # for profile_id, profile_type in self.profile_manager.get_types().items(): + # for profile_id, profile_type in self.profile_manager.get_types().items(): - menu = Gtk.Menu() - menu.set_halign(Gtk.Align.CENTER) - for profile_type in self.profile_manager.get_types(): - item = Gtk.MenuItem.new_with_label(profile_type.type_name) - item.connect('activate', self.create_profile, profile_type) - item.show() - menu.append(item) - add_button = Gtk.MenuButton() - add_button.set_popup(menu) - add_profile_button_contents = self.builder.get_object('add_profile_button_contents') - add_button.add(add_profile_button_contents) + menu = Gtk.Menu() + menu.set_halign(Gtk.Align.CENTER) + for profile_type in self.profile_manager.get_types(): + item = Gtk.MenuItem.new_with_label(profile_type.type_name) + item.connect('activate', self.create_profile, profile_type) + item.show() + menu.append(item) + add_button = Gtk.MenuButton() + add_button.set_popup(menu) + add_profile_button_contents = self.builder.get_object('add_profile_button_contents') + add_button.add(add_profile_button_contents) - profile_pane = self.builder.get_object('profile_pane') - profile_pane.add(add_button) + profile_pane = self.builder.get_object('profile_pane') + profile_pane.add(add_button) - window.show_all() - Gtk.main() + window.show_all() + Gtk.main() - def create_profile(self, widget, profile_type): - profile = profile_type() - color_profile_list_store = self.builder.get_object('color_profile_list_store') - color_profile_list_store.append([profile.id, 'New ' + profile.type_name]) - self.builder.get_object('profile_tree_view').set_cursor(len(color_profile_list_store) - 1) - self.edit_profile(profile) - self.builder.get_object('edit_profile_name_entry').grab_focus() + def create_profile(self, widget, profile_type): + profile = profile_type() + color_profile_list_store = self.builder.get_object('color_profile_list_store') + color_profile_list_store.append([profile.id, 'New ' + profile.type_name]) + self.builder.get_object('profile_tree_view').set_cursor(len(color_profile_list_store) - 1) + self.edit_profile(profile) + self.builder.get_object('edit_profile_name_entry').grab_focus() - def edit_profile(self, profile): - self.builder.get_object('edit_profile_box').show() + def edit_profile(self, profile): + self.builder.get_object('edit_profile_box').show() - self.builder.get_object('edit_profile_type_name_label').set_text(profile.type_name) - self.builder.get_object('edit_profile_name_entry').set_text(profile.name) + self.builder.get_object('edit_profile_type_name_label').set_text(profile.type_name) + self.builder.get_object('edit_profile_name_entry').set_text(profile.name) - edit_profile_details_box = self.builder.get_object('edit_profile_details_box') - for child in edit_profile_details_box.get_children(): - edit_profile_details_box.remove(child) - edit_profile_details_box.add(profile.build_settings_ui()) + edit_profile_details_box = self.builder.get_object('edit_profile_details_box') + for child in edit_profile_details_box.get_children(): + edit_profile_details_box.remove(child) + edit_profile_details_box.add(profile.build_settings_ui()) - def edit_profile_name_changed(self, entry): - profile_name = entry.get_text() - color_profile_list_store = self.builder.get_object('color_profile_list_store') - selection = self.builder.get_object('profile_tree_view').get_selection() - (model, tree_iter) = selection.get_selected() - model.set_value(tree_iter, 1, profile_name) + def edit_profile_name_changed(self, entry): + profile_name = entry.get_text() + color_profile_list_store = self.builder.get_object('color_profile_list_store') + selection = self.builder.get_object('profile_tree_view').get_selection() + (model, tree_iter) = selection.get_selected() + model.set_value(tree_iter, 1, profile_name) - def edit_profile_name_entry_focus_out(self, entry, event): - pass + def edit_profile_name_entry_focus_out(self, entry, event): + pass + class KeyboardSection(Gtk.Grid): - def __init__(self, model): - super().__init__() + def __init__(self, model): + super().__init__() - profile_label = Gtk.Label('Color profile') - # profile_combo_box = Gtk.ComboBox(model) - profile_combo_box = Gtk.ComboBox.new_with_model(model) - # profile_combo_box.set_entry_text_column(1) - # profile_combo_box.append_text('asdf') - renderer_text = Gtk.CellRendererText() - profile_combo_box.pack_start(renderer_text, True) - profile_combo_box.add_attribute(renderer_text, 'text', 1) + profile_label = Gtk.Label('Color profile') + # profile_combo_box = Gtk.ComboBox(model) + profile_combo_box = Gtk.ComboBox.new_with_model(model) + # profile_combo_box.set_entry_text_column(1) + # profile_combo_box.append_text('asdf') + renderer_text = Gtk.CellRendererText() + profile_combo_box.pack_start(renderer_text, True) + profile_combo_box.add_attribute(renderer_text, 'text', 1) - self.add(profile_label) - self.add(profile_combo_box) + self.add(profile_label) + self.add(profile_combo_box)