Skip to content

Commit

Permalink
Merge pull request beeware#737 from beeware/phildini-background-task
Browse files Browse the repository at this point in the history
Add a background task interface for Toga
  • Loading branch information
freakboy3742 authored Sep 26, 2019
2 parents 6117ce7 + 8e1f674 commit 61f7c01
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/android/toga_android/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ def exit(self):

def set_on_exit(self, value):
pass

def add_background_task(self, handler):
self.interface.factory.not_implemented('App.add_background_task()')
17 changes: 10 additions & 7 deletions src/cocoa/toga_cocoa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from urllib.parse import unquote, urlparse

import toga
from rubicon.objc import objc_method, NSMutableArray, NSMutableDictionary, NSObject, SEL
from rubicon.objc.eventloop import EventLoopPolicy, CocoaLifecycle
from rubicon.objc import (SEL, NSMutableArray, NSMutableDictionary, NSObject,
objc_method)
from rubicon.objc.eventloop import CocoaLifecycle, EventLoopPolicy
from toga.handlers import wrapped_handler

from .keys import cocoa_key
from .libs import (
NSURL, NSBundle, NSOpenPanel, NSDocumentController, NSString, NSApplication,
NSApplicationActivationPolicyRegular, NSNumber, NSMenu, NSMenuItem, NSScreen,
NSCursor
)
from .libs import (NSURL, NSApplication, NSApplicationActivationPolicyRegular,
NSBundle, NSCursor, NSDocumentController, NSMenu,
NSMenuItem, NSNumber, NSOpenPanel, NSScreen, NSString)
from .window import Window


Expand Down Expand Up @@ -223,6 +223,9 @@ def hide_cursor(self):

self._cursor_visible = False

def add_background_task(self, handler):
self.loop.call_soon(wrapped_handler(self, handler), self)


class DocumentApp(App):
def _create_app_commands(self):
Expand Down
4 changes: 4 additions & 0 deletions src/core/toga/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def on_exit(self, handler):
self._on_exit = wrapped_handler(self, handler)
self._impl.set_on_exit(self._on_exit)

def add_background_task(self, handler):
self._impl.add_background_task(handler)


class DocumentApp(App):
"""
Expand All @@ -222,6 +225,7 @@ class DocumentApp(App):
document_types (:obj:`list` of :obj:`str`): Document types.
"""

def __init__(self, name, app_id,
id=None, icon=None, startup=None, document_types=None, on_exit=None, factory=None):

Expand Down
4 changes: 3 additions & 1 deletion src/django/toga_django/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def on_close(self, widget, data):
class App(AppInterface):
_MAIN_WINDOW_CLASS = MainWindow


def __init__(self, interface):
self.interface = interface
self.interface._impl = self
Expand Down Expand Up @@ -138,3 +137,6 @@ def home(self, request):
}
}
return render(request, 'toga/app.html', context)

def add_background_task(self, handler):
self.interface.factory.not_implemented('App.add_background_task()')
5 changes: 4 additions & 1 deletion src/dummy/toga_dummy/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .utils import not_required_on, LoggedObject
from .utils import LoggedObject, not_required_on
from .window import Window


Expand Down Expand Up @@ -49,6 +49,9 @@ def show_cursor(self):
def hide_cursor(self):
self._action('hide_cursor')

def add_background_task(self, handler):
self._action('add_background_task', handler=handler)


@not_required_on('mobile', 'web')
class DocumentApp(App):
Expand Down
10 changes: 6 additions & 4 deletions src/gtk/toga_gtk/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import asyncio
import signal
import sys
import os
import os.path
import signal
import sys
from urllib.parse import unquote, urlparse

import gbulb

import toga
from toga import Icon
from toga.command import GROUP_BREAK, SECTION_BREAK, Command

from .keys import gtk_accel
from .libs import Gtk, Gio, GLib
from .libs import Gio, GLib, Gtk
from .window import Window


Expand Down Expand Up @@ -199,6 +198,9 @@ def show_cursor(self):
def hide_cursor(self):
self.interface.factory.not_implemented('App.hide_cursor()')

def add_background_task(self, handler):
self.interface.factory.not_implemented('App.add_background_task()')


class DocumentApp(App):
def _create_app_commands(self):
Expand Down
16 changes: 7 additions & 9 deletions src/iOS/toga_iOS/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

from rubicon.objc import objc_method
from rubicon.objc.eventloop import EventLoopPolicy, iOSLifecycle
from toga.handlers import wrapped_handler

from .libs import (
NSNotificationCenter,
SEL,
UIKeyboardFrameEndUserInfoKey,
UIKeyboardWillHideNotification,
UIKeyboardWillShowNotification,
UIResponder
)

from .libs import (SEL, NSNotificationCenter, UIKeyboardFrameEndUserInfoKey,
UIKeyboardWillHideNotification,
UIKeyboardWillShowNotification, UIResponder)
from .window import Window


Expand Down Expand Up @@ -120,3 +115,6 @@ def exit(self):

def set_on_exit(self, value):
pass

def add_background_task(self, handler):
self.loop.call_soon(wrapped_handler(self, handler), self)
6 changes: 5 additions & 1 deletion src/win32/toga_win32/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .libs import *
from .libs import (MSG, NULL, WA_INACTIVE, WM_ACTIVATE, WM_SETFOCUS, ctypes,
user32)
from .window import Window


Expand Down Expand Up @@ -46,3 +47,6 @@ def on_set_focus(self, msg, old_focus, wParam):
def on_activate(self, msg, state, lParam):
if state == WA_INACTIVE:
self.last_focus = user32.GetFocus()

def add_background_task(self, handler):
self.interface.factory.not_implemented('App.add_background_task()')
3 changes: 3 additions & 0 deletions src/winforms/toga_winforms/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def show_cursor(self):
def hide_cursor(self):
self.interface.factory.not_implemented('App.hide_cursor()')

def add_background_task(self, handler):
self.interface.factory.not_implemented('App.add_background_task()')


class DocumentApp(App):
def _create_app_commands(self):
Expand Down

0 comments on commit 61f7c01

Please sign in to comment.