Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
image = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
image_notification = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon_Notification.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
icon = pystray.Icon("Type.World", image, "Type.World", menu)
if MAC:
class Delegate(NSObject):
def applicationDidFinishLaunching_(self, aNotification):
icon.run()
NSUserNotificationCenterDelegate = objc.protocolNamed('NSUserNotificationCenterDelegate')
class NotificationDelegate(NSObject, protocols=[NSUserNotificationCenterDelegate]):
def userNotificationCenter_didActivateNotification_(self, center, aNotification):
openApp()
app = NSApplication.sharedApplication()
delegate = Delegate.alloc().init()
app.setDelegate_(delegate)
image = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
image_notification = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon_Notification.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
icon = pystray.Icon("Type.World", image, "Type.World", menu)
if MAC:
class Delegate(NSObject):
def applicationDidFinishLaunching_(self, aNotification):
icon.run()
NSUserNotificationCenterDelegate = objc.protocolNamed('NSUserNotificationCenterDelegate')
class NotificationDelegate(NSObject, protocols=[NSUserNotificationCenterDelegate]):
def userNotificationCenter_didActivateNotification_(self, center, aNotification):
intercomApp.open()
nsApp = NSApplication.sharedApplication()
delegate = Delegate.alloc().init()
nsApp.setDelegate_(delegate)
# exit()
menu = (item(localize('Open Type.World App'), openApp, default=True), item(localize('Check for font updates now'), checkForUpdates))#, pystray.Menu.SEPARATOR, item('Quit', quitIcon))
if MAC:
image = NSImage.alloc().initWithContentsOfFile_(NSBundle.mainBundle().pathForResource_ofType_('MacSystemTrayIcon', 'pdf'))
image.setTemplate_(True)
image_notification = NSImage.alloc().initWithContentsOfFile_(NSBundle.mainBundle().pathForResource_ofType_('MacSystemTrayIcon_Notification', 'pdf'))
image_notification.setTemplate_(True)
if WIN:
image = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
image_notification = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon_Notification.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
icon = pystray.Icon("Type.World", image, "Type.World", menu)
if MAC:
class Delegate(NSObject):
# app.terminate_(None)
# if WIN:
# exit()
menu = (item(localize('Open Type.World App'), openApp, default=True), item(localize('Check for font updates now'), checkForUpdates))#, pystray.Menu.SEPARATOR, item('Quit', quitIcon))
if MAC:
image = NSImage.alloc().initWithContentsOfFile_(NSBundle.mainBundle().pathForResource_ofType_('MacSystemTrayIcon', 'pdf'))
image.setTemplate_(True)
image_notification = NSImage.alloc().initWithContentsOfFile_(NSBundle.mainBundle().pathForResource_ofType_('MacSystemTrayIcon_Notification', 'pdf'))
image_notification.setTemplate_(True)
if WIN:
image = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
image_notification = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon_Notification.ico'),
win32.IMAGE_ICON,
0,
0,
win32.LR_DEFAULTSIZE | win32.LR_LOADFROMFILE)
icon = pystray.Icon("Type.World", image, "Type.World", menu)
def _run(self):
# Make sure there is an NSApplication instance
self._app = AppKit.NSApplication.sharedApplication()
# Make sure we have a delegate to handle the acttion events
self._delegate = IconDelegate.alloc().init()
self._delegate.icon = self
self._status_bar = AppKit.NSStatusBar.systemStatusBar()
self._status_item = self._status_bar.statusItemWithLength_(
AppKit.NSVariableStatusItemLength)
self._status_item.button().setTarget_(self._delegate)
self._status_item.button().setAction_(self._ACTION_SELECTOR)
# Notify the setup callback
self._mark_ready()
def sigint(*args):
self.stop()
if previous_sigint:
previous_sigint(*args)
import AppKit
import PyObjCTools.MachSignals
import signal
from pystray._darwin import Icon as pystray_Icon, IconDelegate
class Icon(pystray_Icon):
def _run(self):
# Make sure there is an NSApplication instance
self._app = AppKit.NSApplication.sharedApplication()
# Make sure we have a delegate to handle the acttion events
self._delegate = IconDelegate.alloc().init()
self._delegate.icon = self
self._status_bar = AppKit.NSStatusBar.systemStatusBar()
self._status_item = self._status_bar.statusItemWithLength_(
AppKit.NSVariableStatusItemLength)
self._status_item.button().setTarget_(self._delegate)
self._status_item.button().setAction_(self._ACTION_SELECTOR)
for handle, client in self._clients.items():
fn_names = ", ".join(client.fn_names)
items.append(
pystray.MenuItem(
f"{fn_names} ({client.nickname})",
pystray.Menu(
pystray.MenuItem(
f"Iterations: {client.iterations}", None, enabled=False
),
pystray.MenuItem(
f"Improvements found: {client.improvements}",
None,
enabled=False,
),
pystray.MenuItem("Stop", partial(self._remove_client, handle)),
),
),
)
items.append(pystray.MenuItem("Quit", self._quit))
self._update_menu(items, flush)
def _update(self, flush: bool = True) -> None:
title = "Currently permuting:" if self._clients else ""
items: List[pystray.MenuItem] = [
pystray.MenuItem(title, None, enabled=False),
]
for handle, client in self._clients.items():
fn_names = ", ".join(client.fn_names)
items.append(
pystray.MenuItem(
f"{fn_names} ({client.nickname})",
pystray.Menu(
pystray.MenuItem(
f"Iterations: {client.iterations}", None, enabled=False
),
pystray.MenuItem(
f"Improvements found: {client.improvements}",
None,
enabled=False,
),
pystray.MenuItem("Stop", partial(self._remove_client, handle)),
),
),
)
items.append(pystray.MenuItem("Quit", self._quit))
def quitIcon():
closeListenerThread = Thread(target=closeListener)
closeListenerThread.start()
time.sleep(1)
t.stop()
t.join()
icon.stop()
menu = (
item(localize('Open Type.World App'), openApp, default=True),
item(localize('Check for font updates now'), checkForUpdates),
)#, pystray.Menu.SEPARATOR, item('Quit', quitIcon))
if MAC:
image = NSImage.alloc().initWithContentsOfFile_(NSBundle.mainBundle().pathForResource_ofType_('MacSystemTrayIcon', 'pdf'))
image.setTemplate_(True)
image_notification = NSImage.alloc().initWithContentsOfFile_(NSBundle.mainBundle().pathForResource_ofType_('MacSystemTrayIcon_Notification', 'pdf'))
image_notification.setTemplate_(True)
if WIN:
image = win32.LoadImage(
None,
os.path.join(os.path.dirname(__file__), 'icon', 'TaskbarIcon.ico'),
win32.IMAGE_ICON,
0,
0,
configuration.ACCESS_TOKEN = (
None if configuration.ACCESS_TOKEN is not None
else generate_access_token())
return pystray.Icon(
__name__,
title='Virtual Touchpad - {}'.format(
configuration.SERVER_URL),
icon=PIL.Image.open(
resource.open_stream(
{
'darwin': 'icon-dark.png',
'linux': 'icon-light.png',
'win32': 'icon-light.png'}[sys.platform])),
menu=menu(
item(
_('Connect mobile device...'),
href('qr')),
item(
_('Require access code to connect'),
access_token_toggle,
checked=lambda i: bool(configuration.ACCESS_TOKEN)),
menu.SEPARATOR,
item(
_('Help'),
href('help')),
menu.SEPARATOR,
item(
_('Exit'),
lambda icon: icon.server.stop())))