Skip to content

Commit

Permalink
Add bundle dialog opens almost instantly
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
UnsignedArduino committed Dec 5, 2021
1 parent 8b4d607 commit 937f3ae
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions ui/dialogs/add_bundle.py
Expand Up @@ -69,33 +69,17 @@ def __init__(self, parent, cpybm: CircuitPythonBundleManager):
self.destroy()
return
self.token = cpybm.cred_manager.get_github_token()
try:
self.gm = GitHubManager(self.token, BUNDLE_REPO, BUNDLES_PATH)
except BadCredentialsException as e:
logger.exception("Bad token!")
show_error(self, title="CircuitPython Bundle Manager v2: Error!",
message="Bad token! Please go to Other --> Go to "
"credential settings --> Open credential "
"manager and fill and save a valid GitHub "
"token!",
detail=str(e))
self.destroy()
return
except Exception as e:
logger.exception("Error while authenticating with GitHub!")
show_error(self, title="CircuitPython Bundle Manager v2: Error!",
message="Error while authenticating with GitHub!",
detail=str(e))
self.destroy()
return
self.values = {}
self.curr_page = 0
self.max_page = self.gm.max_page
self.max_page = 0
self.create_gui()
self.bind("<Escape>", lambda _: self.close())
self.enabled = False
self.lift()
self.focus_force()
self.grab_focus()
self.update_idletasks()
self.after(10, lambda: self.update_first_time())
self.wait_till_destroyed()

def make_sidebar(self):
Expand Down Expand Up @@ -316,9 +300,37 @@ def create_gui(self):
"""
self.make_listbox()
self.make_sidebar()

def update_first_time(self):
"""
Update the GUI for the first time.
"""
self.update_idletasks()
try:
self.gm = GitHubManager(self.token, BUNDLE_REPO, BUNDLES_PATH)
except BadCredentialsException as e:
logger.exception("Bad token!")
show_error(self, title="CircuitPython Bundle Manager v2: Error!",
message="Bad token! Please go to Other --> Go to "
"credential settings --> Open credential "
"manager and fill and save a valid GitHub "
"token!",
detail=str(e))
self.destroy()
return
except Exception as e:
logger.exception("Error while authenticating with GitHub!")
show_error(self, title="CircuitPython Bundle Manager v2: Error!",
message="Error while authenticating with GitHub!",
detail=str(e))
self.destroy()
return
self.max_page = self.gm.max_page
self.update_page()
self.enabled = True
self.update_sidebar()
self.update_navigation()
self.update_page()
self.update_idletasks()


def add_bundle_dialog(parent, cpybm: CircuitPythonBundleManager):
Expand Down

0 comments on commit 937f3ae

Please sign in to comment.