diff ui/main_window.py @ 2:091a1f59a79c

Load profiles into list view
author Brad Greco <brad@bgreco.net>
date Tue, 02 Mar 2021 20:17:36 -0500
parents b6d0a1e6ba3a
children eb2aa09653bd
line wrap: on
line diff
--- a/ui/main_window.py	Tue Feb 02 19:46:01 2021 -0500
+++ b/ui/main_window.py	Tue Mar 02 20:17:36 2021 -0500
@@ -1,8 +1,8 @@
 import gi
 import os
-from gi.repository import Gtk
 from keyboard_colors.color_profile import ProfileManager
 gi.require_version("Gtk", "3.0")
+from gi.repository import Gtk
 # from ui.keyboard_section import KeyboardSection
 
 
@@ -10,6 +10,7 @@
 
     def init(self):
         self.profile_manager = ProfileManager()
+        # self.profile_manager.save_profiles()
 
         self.builder = Gtk.Builder()
         dirname = os.path.dirname(os.path.realpath(__file__))
@@ -17,15 +18,19 @@
         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"])
+        self.color_profile_list_store = self.builder.get_object('color_profile_list_store')
+        self.load_color_profiles()
 
         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():
+        keyboard_section.pack_start(
+            KeyboardSection(self.color_profile_list_store), False, False, 0
+        )
+        keyboard_section.pack_start(
+            KeyboardSection(self.color_profile_list_store), False, False, 0
+        )
+        keyboard_section.pack_start(
+            KeyboardSection(self.color_profile_list_store), False, False, 0
+        )
 
         menu = Gtk.Menu()
         menu.set_halign(Gtk.Align.CENTER)
@@ -46,10 +51,12 @@
         Gtk.main()
 
     def create_profile(self, widget, profile_type):
+        # todo move to profile manager
         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.color_profile_list_store.append([profile.id, 'New ' + profile.type_name])
+        self.builder.get_object('profile_tree_view').set_cursor(
+            len(self.color_profile_list_store) - 1
+        )
         self.edit_profile(profile)
         self.builder.get_object('edit_profile_name_entry').grab_focus()
 
@@ -64,9 +71,13 @@
             edit_profile_details_box.remove(child)
         edit_profile_details_box.add(profile.build_settings_ui())
 
+    def profile_tree_view_selection_changed(self, selection):
+        (model, tree_iter) = selection.get_selected()
+        profile_id = model.get_value(tree_iter, 0)
+        self.edit_profile(self.profile_manager.get_profile(profile_id))
+
     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)
@@ -74,6 +85,9 @@
     def edit_profile_name_entry_focus_out(self, entry, event):
         pass
 
+    def load_color_profiles(self):
+        for profile in self.profile_manager.get_profiles().values():
+            self.color_profile_list_store.append([profile.id, profile.name])
 
 class KeyboardSection(Gtk.Grid):