From d530d3ff47bbff0e7452ab0d793f981ea782a921 Mon Sep 17 00:00:00 2001 From: Michael Altfield Date: Sun, 17 Mar 2024 02:59:28 -0500 Subject: [PATCH] attempting to use RecycleView This is not working. The biggest issue that I'm having with getting RecycleView working is that I used positional arguments for the creation of BusKillOptionItem() My understanding is that RecycleView maintains a list of some type of widget. In my case, I want RecycleView to be a set of my custom widget = BusKillOptionItem()s. But the way that RecycleView creates & recycles these objects is by a dictionary, which gets passed into the objects when they're created as kwargs. So in this commit I tried changing from positional args to kwargs, but it doesn't appear to be working yet. For more info, see: * https://github.com/BusKill/buskill-app/issues/55#issuecomment-2002321283 * https://groups.google.com/g/kivy-users/c/TLZoBXX5zZs * https://kivy.org/doc/stable/api-kivy.uix.recycleview.html --- src/buskill.kv | 7 +++++-- src/buskill_gui.py | 51 +++++++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/buskill.kv b/src/buskill.kv index e7b10d1c..16df4c52 100644 --- a/src/buskill.kv +++ b/src/buskill.kv @@ -430,6 +430,7 @@ actionbar: actionbar actionview: actionview content: content + rv: rv # sets the background from black to grey canvas.before: @@ -471,11 +472,13 @@ ActionOverflow: overflow_image: 'images/overflow_white.png' - ScrollView: + RecycleView: + viewclass: 'BusKillOptionItem' do_scroll_x: False + id: rv container: content - GridLayout: + RecycleGridLayout: id: content cols: 1 size_hint_y: None diff --git a/src/buskill_gui.py b/src/buskill_gui.py index a56f52be..e60bd54f 100755 --- a/src/buskill_gui.py +++ b/src/buskill_gui.py @@ -503,24 +503,35 @@ def fileBugReport( self ): # by the BusKillSettingComplexOptions class below class BusKillOptionItem(FloatLayout): - def __init__(self, title, value, desc, confirmation, icon, parent_option, manager, **kwargs): + #def __init__(self, title, value, desc, confirmation, icon, parent_option, manager, **kwargs): + def __init__(self, **kwargs): - self.title = title - self.desc = desc - self.confirmation = confirmation - self.icon = icon - self.value = value - self.parent_option = parent_option - self.manager = manager + print( "kwargs:|" +str(kwargs)+ "|" ) + + #self.title = kwargs['title'] + self.title = StringProperty('') + print( "title:|" +str(self.title)+ "|" ) + #self.desc = kwargs['desc'] + self.desc = StringProperty('') + #self.confirmation = kwargs['confirmation'] + self.confirmation = StringProperty('') + #self.icon = kwargs['icon'] + self.icon = StringProperty('') + #self.value = kwargs['value'] + self.value = StringProperty('') + #self.parent_option = kwargs['parent_option'] + parent_option = StringProperty('') + #self.manager = kwargs['manager'] + manager = ObjectProperty() # the "main" screen - self.main_screen = self.manager.get_screen('main') +# self.main_screen = self.manager.get_screen('main') # we steal (reuse) the instance field referencing the "modal dialog" from # the "main" screen - self.dialog = self.main_screen.dialog +# self.dialog = self.main_screen.dialog - super(BusKillOptionItem, self).__init__(**kwargs) + super(BusKillOptionItem, self).__init__() # this is called when the user clicks on this OptionItem (eg choosing the # 'soft-shutdown' trigger) @@ -683,24 +694,32 @@ def _choose_settings_screen(self, instance): # create an OptionItem for each of the possible values for this # setting option, and add them to the new ComplexOption sub-screen - option_item = BusKillOptionItem( self.key, value, desc, confirmation, icon, self, manager ) + option_item = BusKillOptionItem( title = self.key, value = value, desc = desc, confirmation = confirmation, icon = icon, parent_option = self, manager = manager ) setting_screen.content.add_widget( option_item ) # handle the "font" option if self.key == 'font': # first we must determine what fonts are available on this system + option_items = [] font_paths = [] for fonts_dir_path in LabelBase.get_system_fonts_dir(): for root, dirs, files in os.walk(fonts_dir_path): - for file in files: + for file in files[0:10]: if file.lower().endswith(".ttf"): font_path = str(os.path.join(root, file)) + print(font_path) font_paths.append( font_path ) - option_item = BusKillOptionItem( self.key, font_path, 'desc', '', '', self, manager ) - - setting_screen.content.add_widget( option_item ) + #option_item = BusKillOptionItem( self.key, font_path, 'desc', '', '', self, manager ) + #option_item = BusKillOptionItem( title = self.key, value = font_path, desc = 'test desc', confirmation = '', icon = '', parent_option = self, manager = manager ) + + #setting_screen.content.add_widget( option_item ) + #setting_screen.rv.data = [{'text': str(x)} for x in range(4)] + option_items.append( {'title': 'title', 'value':'value', 'icon':'icon', 'desc':'desc' } ) + option_items = option_items[0:2] + print( "DEBUG: adding data:|" +str(option_items)+ "|" ) + setting_screen.rv.data = option_items # add the new ComplexOption sub-screen to the Screen Manager manager.add_widget( setting_screen )