Skip to content

Commit

Permalink
Make init_window_content compatible with the way async calls work in GTK
Browse files Browse the repository at this point in the history
though the async call itself is commented. Related to #377
  • Loading branch information
maoschanz committed May 26, 2021
1 parent 90ce77e commit e3eeb7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ def open_window_with_content(self, gfile, get_cb):
clipboard content."""
win = DrWindow(application=self)
win.present()
win.init_window_content(gfile, get_cb) # this optimization has no effect
# because of GLib unknown magic, but should be kept anyway because the
# window is presented to the user regardless of loading errors, making
# any issue in `init_window_content` very explicit, and more likely to
# be reported.

content_params = {'gfile': gfile, 'get_cb': get_cb}
# Parameters are: time in milliseconds, method, data # XXX todo?
# GLib.timeout_add(10, win.init_window_content_async, content_params)
win.init_window_content_async(content_params)
return win

def on_activate(self, *args):
Expand Down
16 changes: 14 additions & 2 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,22 @@ def __init__(self, **kwargs):
# self.resize(720, 288)
self._set_ui_bars()

def init_window_content(self, gfile, get_cb):
def init_window_content_async(self, content_params):
"""Initialize the window's content, such as the minimap, the color
popovers, the tools, their options, and a new image. Depending on the
parameters, the new image can be imported from the clipboard, loaded
from a GioFile, or (else) it can be a blank image."""
from a GioFile, or (else) it can be a blank image.
This method is called asynchronously, which isn't *correct* (not very
thread-safe or anything) but it allows the window to be shown quicker.
If it fails, a window is here anyway because this is independant from
the object constructor."""

self.prompt_action(_("Error starting the application, please report this bug."))

gfile = content_params['gfile']
get_cb = content_params['get_cb']

self.tools = {}
self.minimap = DrMinimap(self, None)
self.options_manager = DrOptionsManager(self)
Expand Down Expand Up @@ -148,6 +157,9 @@ def init_window_content(self, gfile, get_cb):
self.set_picture_title()
self._try_show_release_notes()

# has to return False to be removed from the mainloop immediatly
return False

def _try_show_release_notes(self):
last_version = self.gsettings.get_string('last-version')
current_version = self.app.get_current_version()
Expand Down

0 comments on commit e3eeb7e

Please sign in to comment.