Skip to content

Commit

Permalink
Rename dialog refs in action classes (#539)
Browse files Browse the repository at this point in the history
1. ui_class -> dialog_cls
2. dialog -> dialog_cls
3. ui -> dialog_obj
  • Loading branch information
nirizr committed Nov 27, 2018
1 parent 54c0cac commit 8278467
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
22 changes: 11 additions & 11 deletions idaplugin/rematch/actions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@


class Action(object):
dialog = None
dialog_cls = None
reject_handler = None
accept_handler = None
finish_handler = None
submit_handler = None
response_handler = None
exception_handler = None

def __init__(self, ui_class=None):
def __init__(self, dialog_cls=None):
super(Action, self).__init__()
if ui_class:
self.dialog = ui_class
self.ui = None
if dialog_cls:
self.dialog_cls = dialog_cls
self.dialog_obj = None
self._running = False

def __repr__(self):
return "<{}: {}>".format(self.__class__.__name__, self.dialog)
return "<{}: {}>".format(self.__class__.__name__, self.dialog_cls)

def running(self):
return self._running
Expand Down Expand Up @@ -125,17 +125,17 @@ def activate(self, ctx=None):
return
self._running = True

if callable(self.dialog):
if callable(self.dialog_cls):
try:
self.ui = self.dialog(action=self)
self.ui.show()
self.dialog_obj = self.dialog_cls(action=self)
self.dialog_obj.show()
except Exception:
log('actions').exception("Exception thrown while showing dialog")
self._running = False
self.ui = None
self.dialog_obj = None
else:
raise NotImplementedError("Activation called on an action class with no "
"dialog defined")
"dialog_cls defined")

def finish_handler(self, status):
del status
Expand Down
10 changes: 5 additions & 5 deletions idaplugin/rematch/actions/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class LoginAction(base.UnauthAction):
name = "&Login"
group = "User"
dialog = LoginDialog
dialog_cls = LoginDialog

def __init__(self, *args, **kwargs):
super(LoginAction, self).__init__(*args, **kwargs)
Expand All @@ -34,7 +34,7 @@ def submit_handler(self, username, password, server, remember):
def handle_login(self, response):
del response

self.ui.set_status("Connected!", color="green")
self.dialog_obj.set_status("Connected!", color="green")

config['login']['username'] = self.username
config['login']['server'] = self.server
Expand All @@ -44,17 +44,17 @@ def handle_login(self, response):
config['login']['password'] = ""
config.save()

self.ui.accept()
self.dialog_obj.accept()

def handle_exception(self, exception, traceback):
del traceback

if isinstance(exception, (exceptions.ConnectionException,
exceptions.ServerException)):
self.ui.set_status("Connection to server failed.", color="blue")
self.dialog_obj.set_status("Connection to server failed.", color="blue")
elif isinstance(exception, (exceptions.QueryException,
exceptions.AuthenticationException)):
self.ui.set_status("Invalid user name or password.", color="red")
self.dialog_obj.set_status("Invalid user name or password.", color="red")


class LogoutAction(base.AuthAction):
Expand Down
2 changes: 1 addition & 1 deletion idaplugin/rematch/actions/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class MatchAction(base.BoundFileAction):
name = "&Match"
dialog = MatchDialog
dialog_cls = MatchDialog

def __init__(self, *args, **kwargs):
super(MatchAction, self).__init__(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions idaplugin/rematch/actions/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class AddProjectAction(base.AuthAction):
name = "&Add project"
group = "Project"
dialog = AddProjectDialog
dialog_cls = AddProjectDialog

@staticmethod
def submit_handler(name, description, private, bind_current):
Expand All @@ -26,7 +26,7 @@ def submit_handler(name, description, private, bind_current):
class AddFileAction(base.UnboundFileAction):
name = "&Add file"
group = "Project"
dialog = AddFileDialog
dialog_cls = AddFileDialog

@staticmethod
def submit_handler(project, name, md5hash, description, shareidb):
Expand Down
30 changes: 16 additions & 14 deletions idaplugin/rematch/actions/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ResultAction(base.BoundFileAction):
name = "&Result"
dialog = ResultDialog
dialog_cls = ResultDialog

def __init__(self, task_data=None, *args, **kwargs):
super(ResultAction, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -46,10 +46,10 @@ def activate(self, ctx=None):
self.start_results()

def start_results(self):
self.ui.set_status("Receiving match results...")
self.ui.progress.setRange(0, (self.local_count + self.remote_count +
self.match_count))
self.ui.progress.setValue(0)
self.dialog_obj.set_status("Receiving match results...")
total_count = (self.local_count + self.remote_count + self.match_count)
self.dialog_obj.progress.setRange(0, total_count)
self.dialog_obj.progress.setValue(0)

log('result').info("Result download started")
params = {'from_matches__task': self.task_id}
Expand Down Expand Up @@ -113,21 +113,22 @@ def handle_matches(self, response):
self.handle_page(len(response['results']))

def handle_page(self, results_count):
self.ui.progress.setValue(self.ui.progress.value() + results_count)
self.dialog_obj.progress.setValue(self.dialog_obj.progress.value() +
results_count)
log('result').info("result download progress: {} / {}"
"".format(self.ui.progress.value(),
self.ui.progress.maximum()))
if self.ui.progress.value() >= self.ui.progress.maximum():
"".format(self.dialog_obj.progress.value(),
self.dialog_obj.progress.maximum()))
if self.dialog_obj.progress.value() >= self.dialog_obj.progress.maximum():
self.download_complete()

def download_complete(self):
# TODO: perform the following while data comes in instead of after it
# arrived. Also, schedule execution using a timer to not hang
self.populate_tree()
self.ui.set_checks()
self.dialog_obj.set_checks()

log('result').info("Result download completed successfully")
self.ui.set_status("Result download complete")
self.dialog_obj.set_status("Result download complete")

def build_context(self, local, match=None, remote=None):
log('result').info("building context %s %s %s", local, match, remote)
Expand Down Expand Up @@ -169,21 +170,22 @@ def should_filter(self, local, match=None, remote=None):

def populate_tree(self):
# clear tree before populating it
self.ui.tree.clear()
self.dialog_obj.tree.clear()

for local_obj in self.locals.values():
if self.should_filter(local_obj):
continue

local_item = self.ui.populate_item(None, local_obj)
local_item = self.dialog_obj.populate_item(None, local_obj)
local_item.instance_id = local_obj['id']
for match_obj in local_obj['matches']:
remote_obj = self.remotes[match_obj['remote_id']]

if self.should_filter(local_obj, match_obj, remote_obj):
continue

remote_item = self.ui.populate_item(local_item, remote_obj, match_obj)
remote_item = self.dialog_obj.populate_item(local_item, remote_obj,
match_obj)
remote_item.instance_id = remote_obj['id']

def get_obj(self, obj_id):
Expand Down
2 changes: 1 addition & 1 deletion idaplugin/rematch/actions/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class SettingsAction(base.IDAAction):
name = "&Settings"
dialog = SettingsDialog
dialog_cls = SettingsDialog

@staticmethod
def submit_handler(autocheck, autoupdate, autologin, autologout, debug,
Expand Down
10 changes: 5 additions & 5 deletions idaplugin/rematch/actions/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class UploadAction(base.BoundFileAction):
name = "&Upload"
dialog = UploadDialog
dialog_cls = UploadDialog

def __init__(self, *args, **kwargs):
super(UploadAction, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -62,7 +62,7 @@ def calc_file_version_hash():
def submit_handler(self, force_update, upload_annotations):
self.upload_annotations = upload_annotations

self.ui.set_status("Uploading...")
self.dialog_obj.set_status("Uploading...")

endpoint = "collab/file_versions/"
if force_update:
Expand All @@ -85,7 +85,7 @@ def start_upload(self):
self.instances = set((FunctionInstance, f) for f in idautils.Functions())
self.instances.add((UniversalInstance, (s[0] for s in idautils.Structs())))

self.ui.increase_maximum(len(self.instances))
self.dialog_obj.increase_maximum(len(self.instances))

self.timer.timeout.connect(self.perform_upload)
self.timer.start(0)
Expand All @@ -109,12 +109,12 @@ def perform_upload(self):
self.delayed_queries.append(q)

self.instance_objs = []
self.ui.increase_maximum()
self.dialog_obj.increase_maximum()
self.progress_advance()

def progress_advance(self, result=None):
del result
self.ui.advance()
self.dialog_obj.advance()

def accept_handler(self):
self.clean()
Expand Down

0 comments on commit 8278467

Please sign in to comment.