Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
fix(ui): 🐛 reselect modpack after select modpack version (fix #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jun 16, 2022
1 parent 4ab0ea1 commit a76b236
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
7 changes: 7 additions & 0 deletions utils/window/frames/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def __init__(self, master: 'Main'):
# Update list when combobox selected
self.sort_combobox.bind('<<ComboboxSelected>>', self.on_select)
self.game_version_combobox.bind('<<ComboboxSelected>>', self.on_select)
self.modpack_version_combobox.bind(
'<<ComboboxSelected>>',
self.on_modpack_version_select
)

self.sort_label.pack(side='left')
self.sort_combobox.pack(side='left')
Expand Down Expand Up @@ -58,3 +62,6 @@ def set_modpack_version(self, values: List[str]):

def on_select(self, event=None):
self.main_window.show_frame.update_list()

def on_modpack_version_select(self, event=None):
self.main_window.show_frame.reselect()
32 changes: 23 additions & 9 deletions utils/window/frames/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, master: 'Main'):

self.__main_window = master
self.__search_index = 0
self.__selected_index = -1
self.__updating = False
self.__data: List[Dict] = []

Expand Down Expand Up @@ -53,6 +54,7 @@ def run():

# Refresh list or append
if not append:
self.__selected_index = -1
self.__data = []
self.__list_listbox.delete(0, 'end')
else:
Expand Down Expand Up @@ -92,24 +94,30 @@ def run():
files = Requester.files(_id).json()

# Storage into data
self.__data[index]['files'] = {}
self.__data[self.selected_index]['files'] = {}
for i in files:
self.__data[index]['files'][i['displayName']] = i
display_name = i['displayName']
self.__data[self.selected_index]['files'][display_name] = i

# Set filter combobox
self.__main_window.filters_frame.set_modpack_version(
list(self.__data[index]['files'].keys())
list(self.__data[self.selected_index]['files'].keys())
)

index = self.selected_index
if index != -1:
_id = self.__data[index].get('id')
Thread(target=run, name=f'Get Modpack Versions ({_id})').start()
old_index = self.selected_index

selection = self.__list_listbox.curselection()
if selection:
self.__selected_index = selection[0]
if self.selected_index == old_index:
return
else:
_id = self.__data[self.selected_index].get('id')
Thread(target=run, name=f'Get Modpack Versions ({_id})').start()

@property
def selected_index(self) -> int:
selection = self.__list_listbox.curselection()
return selection[0] if selection else -1
return self.__selected_index

@property
def selected_modpack_id(self) -> int:
Expand Down Expand Up @@ -141,3 +149,9 @@ def selected_avatar_url(self) -> str:
if display_name != '' and self.selected_files is not None:
return self.__data[self.selected_index]['attachments'][0]['url']
return ''

def reselect(self):
"""
Reselect item in list.
"""
self.__list_listbox.select_set(self.selected_index)

0 comments on commit a76b236

Please sign in to comment.