Skip to content

Commit

Permalink
Moved add_handler function to winforms.libs, added app.exit() impleme…
Browse files Browse the repository at this point in the history
…ntation

Signed-off-by: obulat <obulat@gmail.com>
  • Loading branch information
obulat authored and freakboy3742 committed Apr 7, 2018
1 parent 358788d commit f1fcd07
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/winforms/toga_winforms/app.py
Expand Up @@ -42,9 +42,6 @@ def open_document(self, fileURL):
'''Add a new document to this app.'''
print("STUB: If you want to handle opening documents, implement App.open_document(fileURL)")

def create_menus(self):
self.interface.factory.not_implemented('App.create_menus()')

def run_app(self):
self.create()
self.native.Run(self.interface.main_window._impl.native)
Expand All @@ -56,4 +53,4 @@ def main_loop(self):
thread.Join()

def exit(self):
self.interface.factory.not_implemented('App.exit()')
self.native.Exit()
9 changes: 9 additions & 0 deletions src/winforms/toga_winforms/libs.py
Expand Up @@ -19,3 +19,12 @@ def TextAlignment(value):
CENTER: ContentAlignment.MiddleCenter,
JUSTIFY: ContentAlignment.MiddleLeft,
}[value]


def add_handler(cmd):
action = cmd.action

def handler(sender, event):
return action(None)

return handler
18 changes: 1 addition & 17 deletions src/winforms/toga_winforms/window.py
Expand Up @@ -2,7 +2,7 @@
from toga import GROUP_BREAK, SECTION_BREAK
from travertino.layout import Viewport

from .libs import WinForms, Size
from .libs import WinForms, Size, add_handler


class WinFormsViewport:
Expand Down Expand Up @@ -51,28 +51,12 @@ def create_toolbar(self):
else:
item = WinForms.ToolStripMenuItem(cmd.label)

def add_handler(cmd):
action = cmd.action

def handler(sender, event):
return action(None)

return handler

item.Click += add_handler(cmd)
self.toolbar_native.Items.Add(item)

def create_menus(self):
toga.Group.FILE.order = 0

def add_handler(cmd):
action = cmd.action

def handler(sender, event):
return action(None)

return handler

# Only create the menu if the menu item index has been created.
if hasattr(self, '_menu_items'):
self._menu_items = {}
Expand Down

0 comments on commit f1fcd07

Please sign in to comment.