Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from obulat/icons
Added Icons, menus and toolbars to Winforms backend.
- Loading branch information
Showing
11 changed files
with
151 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,30 @@ | ||
import os | ||
|
||
from toga import Icon as toga_Icon | ||
from toga_cocoa.libs import NSImage | ||
|
||
|
||
class Icon: | ||
def __init__(self, interface): | ||
self.interface = interface | ||
interface.__impl = self | ||
self.native = NSImage.alloc().initWithContentsOfFile(interface.filename) | ||
self.interface._impl = self | ||
file_path, file_extension = os.path.splitext(self.interface.filename) | ||
valid_icon_extensions = ('.png', '.bmp', '.ico') | ||
|
||
if file_extension == '.icns': | ||
self.native = NSImage.alloc().initWithContentsOfFile(self.interface.filename) | ||
elif os.path.isfile(file_path + '.icns'): | ||
self.native = NSImage.alloc().initWithContentsOfFile(file_path + '.icns') | ||
elif file_extension in valid_icon_extensions: | ||
self.native = NSImage.alloc().initWithContentsOfFile(self.interface.filename) | ||
elif os.path.isfile(file_path + '.png'): | ||
self.native = NSImage.alloc().initWithContentsOfFile(file_path + '.png') | ||
elif os.path.isfile(file_path + '.bmp'): | ||
self.native = NSImage.alloc().initWithContentsOfFile(file_path + '.bmp') | ||
else: | ||
print("[Cocoa] No valid icon format available for {}; " | ||
"fall back on Tiberius instead".format( | ||
self.interface.filename)) | ||
tiberius_file = toga_Icon.TIBERIUS_ICON.filename + '.icns' | ||
self.interface.icon = toga_Icon.TIBERIUS_ICON | ||
self.native = NSImage.alloc().initWithContentsOfFile(tiberius_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
#from .widgets.icon import Icon | ||
from toga.widgets.icon import Icon as CoreIcon | ||
|
||
class Command: | ||
def __init__(self, interface): | ||
self.interface = interface | ||
|
||
# if self.interface.icon_id: | ||
# self.icon = Icon.load(self.interface.icon_id) | ||
# else: | ||
# self.icon = None | ||
self.native = None | ||
if self.interface.icon_id: | ||
# If icon_id is an icon, not a filepath | ||
if type(self.interface.icon_id) is not str: | ||
self.interface.icon = self.interface.icon_id | ||
else: | ||
self.interface.icon = CoreIcon(self.interface.icon_id) | ||
else: | ||
self.interface.icon = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,41 @@ | ||
# from ..libs import NSImage | ||
import os | ||
|
||
from toga import Icon as toga_Icon | ||
from toga_winforms.libs import Bitmap, WinIcon | ||
|
||
|
||
class Icon: | ||
def __init__(self, interface): | ||
|
||
def create_icon_from_file(filename): | ||
icon_bitmap = Bitmap(self.interface.filename) | ||
icon_handle = icon_bitmap.GetHicon() | ||
return WinIcon.FromHandle(icon_handle) | ||
|
||
self.interface = interface | ||
interface._impl = self | ||
# self.native = NSImage.alloc().initWithContentsOfFile(interface.filename) | ||
self.interface._impl = self | ||
valid_icon_extensions = ('.png', '.bmp', '.ico') | ||
file_path, file_extension = os.path.splitext(self.interface.filename) | ||
|
||
if file_extension == '.ico': | ||
self.native = WinIcon(self.interface.filename) | ||
|
||
elif os.path.isfile(file_path + '.ico'): | ||
self.native = WinIcon(file_path + '.ico') | ||
|
||
elif file_extension in valid_icon_extensions: | ||
self.native = create_icon_from_file(self.interface.filename) | ||
|
||
elif os.path.isfile(file_path + '.png'): | ||
self.native = create_icon_from_file(file_path + '.png') | ||
|
||
elif os.path.isfile(file_path + '.bmp'): | ||
self.native = create_icon_from_file(file_path + '.bmp') | ||
|
||
else: | ||
print("[Winforms] No valid icon format available for {}; " | ||
"fall back on Tiberius instead".format( | ||
self.interface.filename)) | ||
tiberius_file = toga_Icon.TIBERIUS_ICON.filename + '.ico' | ||
self.interface.icon = toga_Icon.TIBERIUS_ICON | ||
self.native = WinIcon(tiberius_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters