-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic keyboard shortcuts and native systray
- Loading branch information
1 parent
c9e75cc
commit 7567fe6
Showing
6 changed files
with
203 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
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
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 |
---|---|---|
|
@@ -9,15 +9,30 @@ | |
|
||
__author__ = 'Raphaël Doursenaud <[email protected]>' | ||
|
||
__version__ = '0.3.0' # FIXME: use setuptools | ||
__version__ = '0.4.0' # FIXME: use setuptools | ||
|
||
import logging | ||
|
||
import PIL.Image | ||
import pystray | ||
|
||
from config import DEBUG, GUI | ||
|
||
logger = logging.getLogger() | ||
|
||
|
||
def resource_path(relative_path): | ||
""" Get absolute path to resource, works for dev and for PyInstaller """ | ||
import os, sys | ||
if hasattr(sys, '_MEIPASS'): | ||
# PyInstaller creates a temp folder and stores path in _MEIPASS | ||
base_path = sys._MEIPASS | ||
else: | ||
base_path = os.getcwd() | ||
|
||
return os.path.join(base_path, relative_path) | ||
|
||
|
||
def init_logging(): | ||
global logger | ||
|
||
|
@@ -35,22 +50,60 @@ def init_logging(): | |
logger.setLevel(kivy.logger.LOG_LEVELS['debug']) | ||
else: | ||
logger.setLevel(kivy.logger.LOG_LEVELS['info']) | ||
logging.getLogger('denon.dn500av').setLevel(logging.WARNING) # Silence module’s logging | ||
|
||
|
||
def run_from_systray(): | ||
default_menu_item = pystray.MenuItem('Denon Remote', systray_clicked, default=True, visible=False) | ||
quit_menu_item = pystray.MenuItem('Quit', quit_systray) | ||
systray_menu = pystray.Menu(default_menu_item, quit_menu_item) | ||
systray = pystray.Icon('Denon Remote', menu=systray_menu) | ||
systray.icon = PIL.Image.open(resource_path(r'images/icon.png')) | ||
systray.run(setup=run_gui) | ||
|
||
|
||
def run_gui(systray): | ||
import kivy.config | ||
kivy.config.Config.set('kivy', 'window_icon', 'images/icon.png') | ||
# Fixed size window | ||
kivy.config.Config.set('graphics', 'resizable', False) | ||
# Start hidden | ||
kivy.config.Config.set('graphics', 'window_state', 'hidden') | ||
# wm_pen and wm_touch conflicts with hidden window state. See https://github.com/kivy/kivy/issues/6428 | ||
kivy.config.Config.remove_option('input', 'wm_pen') | ||
kivy.config.Config.remove_option('input', 'wm_touch') | ||
kivy.config.Config.write() | ||
|
||
from gui import DenonRemoteApp | ||
DenonRemoteApp().run_with_systray(systray) | ||
|
||
|
||
def systray_clicked(icon: pystray.Icon, menu: pystray.MenuItem): | ||
import kivy.app | ||
app = kivy.app.App.get_running_app() | ||
if app.hidden: | ||
app.show() | ||
else: | ||
app.hide() | ||
|
||
|
||
def quit_systray(icon: pystray.Icon, menu: pystray.MenuItem): | ||
import kivy.app | ||
kivy.app.App.get_running_app().stop() | ||
icon.stop() | ||
|
||
|
||
def run_cli(): | ||
from cli import DenonRemoteApp | ||
DenonRemoteApp().run() | ||
|
||
|
||
def run(): | ||
# FIXME: autodetect when running from CLI | ||
if GUI: | ||
from gui import DenonRemoteApp | ||
|
||
# PyInstaller data support | ||
import os, sys | ||
import kivy.resources | ||
if hasattr(sys, '_MEIPASS'): | ||
kivy.resources.resource_add_path(os.path.join(sys._MEIPASS)) | ||
run_from_systray() | ||
else: | ||
from cli import DenonRemoteApp | ||
|
||
DenonRemoteApp().run() | ||
run_cli() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
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,3 +1,4 @@ | ||
twisted | ||
kivy | ||
pystray | ||
PyInstaller |