Start a small refactor in GUI code

This commit is contained in:
Manuel Cortez 2022-07-29 17:54:34 -05:00
parent f9f7a32f90
commit 4b627a13ff
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import webbrowser import webbrowser
import threading
import logging import logging
import sound_lib import sound_lib
import paths import paths
@ -307,6 +308,13 @@ class accountSettingsController(globalSettingsController):
def on_autocompletion_scan(self, *args, **kwargs): def on_autocompletion_scan(self, *args, **kwargs):
configuration = scan.autocompletionScan(self.buffer.session.settings, self.buffer, self.window) configuration = scan.autocompletionScan(self.buffer.session.settings, self.buffer, self.window)
to_scan = configuration.show_dialog()
if to_scan == True:
configuration.prepare_progress_dialog()
t = threading.Thread(target=configuration.scan)
t.start()
def on_autocompletion_manage(self, *args, **kwargs): def on_autocompletion_manage(self, *args, **kwargs):
configuration = manage.autocompletionManage(self.buffer.session) configuration = manage.autocompletionManage(self.buffer.session)

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" Scanning code for autocompletion feature on TWBlue. This module can retrieve user objects from the selected Twitter account automatically. """ """ Scanning code for autocompletion feature on TWBlue. This module can retrieve user objects from the selected Twitter account automatically. """
import time import time
import threading
import wx import wx
import widgetUtils import widgetUtils
import output import output
@ -27,17 +26,19 @@ class autocompletionScan(object):
self.config = config self.config = config
self.buffer = buffer self.buffer = buffer
self.window = window self.window = window
def show_dialog(self):
self.dialog = wx_scan.autocompletionScanDialog() self.dialog = wx_scan.autocompletionScanDialog()
self.dialog.set("friends", self.config["mysc"]["save_friends_in_autocompletion_db"]) self.dialog.set("friends", self.config["mysc"]["save_friends_in_autocompletion_db"])
self.dialog.set("followers", self.config["mysc"]["save_followers_in_autocompletion_db"]) self.dialog.set("followers", self.config["mysc"]["save_followers_in_autocompletion_db"])
if self.dialog.get_response() == widgetUtils.OK: if self.dialog.get_response() == widgetUtils.OK:
confirmation = wx_scan.confirm() confirmation = wx_scan.confirm()
if confirmation == True: return confirmation
def prepare_progress_dialog(self):
self.progress_dialog = wx_scan.get_progress_dialog(parent=self.dialog) self.progress_dialog = wx_scan.get_progress_dialog(parent=self.dialog)
# connect method to update progress dialog # connect method to update progress dialog
pub.subscribe(self.on_update_progress, "on-update-progress") pub.subscribe(self.on_update_progress, "on-update-progress")
scanner = threading.Thread(target=self.scan)
scanner.start()
def on_update_progress(self, percent): def on_update_progress(self, percent):
if percent > 100: if percent > 100:
@ -77,7 +78,6 @@ class autocompletionScan(object):
results = selff.buffer.session.twitter.lookup_users(user_id=z) results = selff.buffer.session.twitter.lookup_users(user_id=z)
except NameError: except NameError:
wx.CallAfter(wx_scan.show_error) wx.CallAfter(wx_scan.show_error)
wx.CallAfter(self.dialog.SetFocus)
return self.done() return self.done()
users.extend(results) users.extend(results)
time.sleep(1) time.sleep(1)