From c54422d771f5f053c2405861a761f72e7bca37f1 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 8 Oct 2022 19:23:51 +0200 Subject: [PATCH] Improved dropdown behaviour and widget allocation --- sbapp/main.py | 1 - sbapp/ui/announces.py | 2 ++ sbapp/ui/conversations.py | 74 ++++++++++++++++++++++----------------- sbapp/ui/layouts.py | 1 + sbapp/ui/messages.py | 2 ++ 5 files changed, 47 insertions(+), 33 deletions(-) diff --git a/sbapp/main.py b/sbapp/main.py index e7497ad..a753bc5 100644 --- a/sbapp/main.py +++ b/sbapp/main.py @@ -480,7 +480,6 @@ class SidebandApp(MDApp): self.root.ids.messages_scrollview.effect_cls = ScrollEffect for child in self.root.ids.messages_scrollview.children: self.root.ids.messages_scrollview.remove_widget(child) - RNS.log("Removed "+str(child)) list_widget = self.messages_view.get_widget() diff --git a/sbapp/ui/announces.py b/sbapp/ui/announces.py index 26c85c2..99709af 100644 --- a/sbapp/ui/announces.py +++ b/sbapp/ui/announces.py @@ -201,6 +201,8 @@ class Announces(): width_mult=4, elevation=1, radius=dp(3), + opening_transition="linear", + opening_time=0.0, ) def callback_factory(ref): diff --git a/sbapp/ui/conversations.py b/sbapp/ui/conversations.py index 8574de5..9d2afa6 100644 --- a/sbapp/ui/conversations.py +++ b/sbapp/ui/conversations.py @@ -32,6 +32,7 @@ class Conversations(): self.context_dests = [] self.added_item_dests = [] self.list = None + self.conversation_dropdown = None self.update() def reload(self): @@ -85,6 +86,7 @@ class Conversations(): def gen_edit(dest, item): def x(): + dest = self.conversation_dropdown.context_dest try: disp_name = self.app.sideband.raw_display_name(dest) is_trusted = self.app.sideband.is_trusted(dest) @@ -140,6 +142,7 @@ class Conversations(): def gen_clear(dest, item): def x(): + dest = self.conversation_dropdown.context_dest yes_button = MDFlatButton( text="Yes", ) @@ -178,7 +181,7 @@ class Conversations(): ) def dl_yes(s): dialog.dismiss() - self.app.sideband.delete_conversation(dest) + self.app.sideband.delete_conversation(self.conversation_dropdown.context_dest) self.reload() def dl_no(s): dialog.dismiss() @@ -189,44 +192,51 @@ class Conversations(): dialog.open() return x - dm_items = [ - { - "viewclass": "OneLineListItem", - "text": "Edit", - "height": dp(40), - "on_release": gen_edit(context_dest, item) - }, - { - "text": "Clear Messages", - "viewclass": "OneLineListItem", - "height": dp(40), - "on_release": gen_clear(context_dest, item) - }, - { - "text": "Delete Conversation", - "viewclass": "OneLineListItem", - "height": dp(40), - "on_release": gen_del(context_dest, item) - } - ] + if self.conversation_dropdown == None: + dmi_h = 40 + dm_items = [ + { + "viewclass": "OneLineListItem", + "text": "Edit", + "height": dp(dmi_h), + "on_release": gen_edit(context_dest, item) + }, + { + "text": "Clear Messages", + "viewclass": "OneLineListItem", + "height": dp(dmi_h), + "on_release": gen_clear(context_dest, item) + }, + { + "text": "Delete Conversation", + "viewclass": "OneLineListItem", + "height": dp(dmi_h), + "on_release": gen_del(context_dest, item) + } + ] + + self.conversation_dropdown = MDDropdownMenu( + caller=None, + items=dm_items, + position="auto", + width_mult=4, + elevation=1, + radius=dp(3), + opening_transition="linear", + opening_time=0.0, + ) item.iconr = IconRightWidget(icon="dots-vertical"); - - item.dmenu = MDDropdownMenu( - caller=item.iconr, - items=dm_items, - position="auto", - width_mult=4, - elevation=1, - radius=dp(3), - ) + item.dmenu = self.conversation_dropdown - def callback_factory(ref): + def callback_factory(ref, dest): def x(sender): + self.conversation_dropdown.context_dest = dest + ref.dmenu.caller = ref.iconr ref.dmenu.open() return x - item.iconr.bind(on_release=callback_factory(item)) + item.iconr.bind(on_release=callback_factory(item, context_dest)) item.add_widget(item.iconr) diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py index d29206b..fb8e706 100644 --- a/sbapp/ui/layouts.py +++ b/sbapp/ui/layouts.py @@ -925,6 +925,7 @@ MDNavigationLayout: ContentNavigationDrawer: ScrollView: + id: nav_scrollview DrawerList: id: md_list diff --git a/sbapp/ui/messages.py b/sbapp/ui/messages.py index b9c8e04..63cf631 100644 --- a/sbapp/ui/messages.py +++ b/sbapp/ui/messages.py @@ -214,6 +214,8 @@ class Messages(): width_mult=4, elevation=1, radius=dp(3), + opening_transition="linear", + opening_time=0.0, ) def callback_factory(ref):