Skip to content

Commit

Permalink
Error reporting and UI freeze on focus lost. All taken from ejpi
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 13, 2011
1 parent 992b2ee commit 36d0fb4
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions src/util/qwrappers.py
Expand Up @@ -73,6 +73,10 @@ def save_settings(self):
def _new_main_window(self):
raise NotImplementedError("Booh")

@property
def qapp(self):
return self._qapp

@property
def constants(self):
return self._constants
Expand Down Expand Up @@ -122,26 +126,30 @@ def _on_child_close(self, obj = None):

@misc_utils.log_exception(_moduleLogger)
def _on_toggle_fullscreen(self, checked = False):
self._mainWindow.set_fullscreen(checked)
with qui_utils.notify_error(self._errorLog):
self._mainWindow.set_fullscreen(checked)

@misc_utils.log_exception(_moduleLogger)
def _on_toggle_orientation(self, checked = False):
self._mainWindow.set_orientation(checked)
with qui_utils.notify_error(self._errorLog):
self._mainWindow.set_orientation(checked)

@misc_utils.log_exception(_moduleLogger)
def _on_about(self, checked = True):
raise NotImplementedError("Booh")

@misc_utils.log_exception(_moduleLogger)
def _on_log(self, checked = False):
with open(self._constants._user_logpath_, "r") as f:
logLines = f.xreadlines()
log = "".join(logLines)
self._clipboard.setText(log)
with qui_utils.notify_error(self._errorLog):
with open(self._constants._user_logpath_, "r") as f:
logLines = f.xreadlines()
log = "".join(logLines)
self._clipboard.setText(log)

@misc_utils.log_exception(_moduleLogger)
def _on_quit(self, checked = False):
self._close_windows()
with qui_utils.notify_error(self._errorLog):
self._close_windows()


class WindowWrapper(object):
Expand Down Expand Up @@ -227,4 +235,29 @@ def _on_child_close(self):

@misc_utils.log_exception(_moduleLogger)
def _on_close_window(self, checked = True):
self.close()
with qui_utils.notify_error(self._errorLog):
self.close()


class AutoFreezeWindowFeature(object):

def __init__(self, app, window):
self._app = app
self._window = window
self._app.qapp.focusChanged.connect(self._on_focus_changed)
if self._app.qapp.focusWidget() is not None:
self._window.setUpdatesEnabled(True)
else:
self._window.setUpdatesEnabled(False)

def close(self):
self._app.qapp.focusChanged.disconnect(self._on_focus_changed)
self._window.setUpdatesEnabled(True)

@misc_utils.log_exception(_moduleLogger)
def _on_focus_changed(self, oldWindow, newWindow):
with qui_utils.notify_error(self._app.errorLog):
if oldWindow is None and newWindow is not None:
self._window.setUpdatesEnabled(True)
elif oldWindow is not None and newWindow is None:
self._window.setUpdatesEnabled(False)

0 comments on commit 36d0fb4

Please sign in to comment.