Skip to content

Commit

Permalink
Update to v0.0.3
Browse files Browse the repository at this point in the history
- Binaries updated to v0.3.0.0 (Aomori)

- Add system tray icon/notification. Wallet to hide to system tray
instead quitting when main window closes
  • Loading branch information
sumoprojects committed Apr 3, 2018
1 parent f9db8ce commit 7e8aea5
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 7 deletions.
Binary file added Resources/icons/sumokoin_16x16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/icons/sumokoin_16x16_mac.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/icons/sumokoin_32x32_ubuntu.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions settings/__init__.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
## Copyright (c) 2017, The Sumokoin Project (www.sumokoin.org)
## Copyright (c) 2017-2018, The Sumokoin Project (www.sumokoin.org)
'''
App top-level settings
'''
Expand All @@ -14,8 +14,8 @@
from utils.common import getHomeDir, makeDir

USER_AGENT = "Sumokoin GUI Wallet"
APP_NAME = "Sumokoin Wallet"
VERSION = [0, 0, 1]
APP_NAME = "Sumokoin GUI Wallet"
VERSION = [0, 0, 3]


_data_dir = makeDir(os.path.join(getHomeDir(), 'SumokoinGUIWallet'))
Expand Down
125 changes: 121 additions & 4 deletions webui/__init__.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
## Copyright (c) 2017, The Sumokoin Project (www.sumokoin.org)
## Copyright (c) 2017-2018, The Sumokoin Project (www.sumokoin.org)
'''
App UIs
'''
Expand Down Expand Up @@ -28,6 +28,11 @@
from utils.logger import log, LEVEL_DEBUG, LEVEL_ERROR, LEVEL_INFO
from utils.common import readFile

from utils.notify import Notify
MSG_TYPE_INFO = 1
MSG_TYPE_WARNING = 2
MSG_TYPE_CRITICAL = 3

from manager.ProcessManager import SumokoindManager, WalletRPCManager
from rpc import RPCRequest, DaemonRPCRequest

Expand All @@ -38,6 +43,7 @@

TIMER2_INTERVAL = 60000
MAX_NEW_SUBADDRESSES = 10
tray_icon_tooltip = "%s v%d.%d.%s" % (APP_NAME, VERSION[0], VERSION[1], VERSION[2])

log_text_tmpl = """
<index>
Expand Down Expand Up @@ -177,6 +183,17 @@ def __init__(self, app, hub, debug):
self.agent = '%s v.%s' % (USER_AGENT, '.'.join(str(v) for v in VERSION))
log("Starting [%s]..." % self.agent, LEVEL_INFO)

# Setup the system tray icon
if sys.platform == 'darwin':
tray_icon = 'sumokoin_16x16_mac.png'
elif sys.platform == "win32":
tray_icon = 'sumokoin_16x16.png'
else:
tray_icon = 'sumokoin_32x32_ubuntu.png'

self.trayIcon = QSystemTrayIcon(self._getQIcon(tray_icon))
self.trayIcon.setToolTip(tray_icon_tooltip)

self.app = app
self.debug = debug
self.hub = hub
Expand All @@ -199,9 +216,48 @@ def __init__(self, app, hub, debug):
self.target_height = self.app_settings.settings['blockchain']['height']
self.current_height = 0

# Setup the tray icon context menu
self.trayMenu = QMenu()

self.showAppAction = QAction('&Show %s' % APP_NAME, self)
f = self.showAppAction.font()
f.setBold(True)
self.showAppAction.setFont(f)
self.trayMenu.addAction(self.showAppAction)


self.aboutAction = QAction('&About...', self)
self.trayMenu.addAction(self.aboutAction)

self.trayMenu.addSeparator()
self.exitAction = QAction('&Exit', self)
self.trayMenu.addAction(self.exitAction)
# Add menu to tray icon
self.trayIcon.setContextMenu(self.trayMenu)

# connect signals
self.trayIcon.activated.connect(self._handleTrayIconActivate)
self.exitAction.triggered.connect(self.handleExitAction)
self.aboutAction.triggered.connect(self.handleAboutAction)
self.showAppAction.triggered.connect(self._handleShowAppAction)
self.app.aboutToQuit.connect(self._handleAboutToQuit)

# Setup notification support
self.system_tray_running_notified = False
self.notifier = Notify(APP_NAME)
self.trayIcon.show()


def closeEvent(self, event):
""" Override QT close event
"""
event.ignore()
self.hide()
if not self.system_tray_running_notified:
self.notify("%s is still running at system tray." % APP_NAME,
"Running Status")
self.system_tray_running_notified = True

def run(self):
self.view.loadFinished.connect(self.load_finished)
# self.view.load(qt_core.QUrl(self.url))
Expand Down Expand Up @@ -236,8 +292,13 @@ def show_wallet(self):
self.timer2.stop()
self.timer2.start(TIMER2_INTERVAL)
self.show()
self.trayIcon.show()


def hide_wallet(self):
self.hide()
self.trayIcon.hide()

def run_wallet_rpc(self, wallet_password, log_level=0):
# first, try to stop any wallet RPC server running
try:
Expand Down Expand Up @@ -276,6 +337,13 @@ def _update_daemon_status(self):
}

self.hub.update_daemon_status(json.dumps(info))

sync_status = "Disconnected" if sumokoind_info['status'] != "OK" else "Synchronizing..."
if sumokoind_info['status'] == "OK" and self.current_height == self.target_height:
sync_status = "Network synchronized"

self.trayIcon.setToolTip("%s\n%s (%d/%d)" % (tray_icon_tooltip, sync_status,
self.current_height, self.target_height))


def update_wallet_info(self):
Expand Down Expand Up @@ -389,7 +457,7 @@ def update_wallet_info(self):

def show_new_wallet_ui(self):
self.reset_wallet(delete_files=False)
self.hide()
self.hide_wallet()
self.new_wallet_ui = NewWalletWebUI(self.app, self.hub, self.debug)
self.hub.setNewWalletUI(self.new_wallet_ui)
self.new_wallet_ui.run()
Expand All @@ -413,9 +481,32 @@ def reset_wallet(self, delete_files=True):
self.hub.on_new_wallet_ui_reset_event.emit()
self.hub.on_main_wallet_ui_reset_event.emit()

def notify(self, message, title="", icon=None, msg_type=None):
if self.notifier.notifier is not None:
self.notifier.notify(title, message, icon)
else:
self.showMessage(message, title, msg_type)

def showMessage(self, message, title="", msg_type=None, timeout=2000):
"""Displays 'message' through the tray icon's showMessage function,
with title 'title'. 'type' is one of the enumerations of
'common.MessageTypes'.
"""
if msg_type is None or msg_type == MSG_TYPE_INFO:
icon = QSystemTrayIcon.Information

elif msg_type == MSG_TYPE_WARNING:
icon = QSystemTrayIcon.Warning

elif msg_type == MSG_TYPE_CRITICAL:
icon = QSystemTrayIcon.Critical

title = "%s - %s" % (APP_NAME, title) if title else APP_NAME
self.trayIcon.showMessage(title, message, icon, timeout)

def about(self):
QMessageBox.about(self, "About", \
u"%s <br><br>Copyright© 2017 - Sumokoin Projects (www.sumokoin.org)" % self.agent)
u"%s <br><br>Copyright© 2017 -2018 - Sumokoin Projects (www.sumokoin.org)" % self.agent)

def _load_wallet(self):
if self.wallet_info.load():
Expand All @@ -439,7 +530,8 @@ def _load_wallet(self):
"Do you want to create (or restore to) a new wallet instead?", \
QMessageBox.Yes | QMessageBox.No, defaultButton=QMessageBox.No)
if result == QMessageBox.No:
self.close()
self.trayIcon.hide()
QTimer.singleShot(250, self.app.quit)
else:
self.show_new_wallet_ui()
return
Expand All @@ -463,12 +555,37 @@ def _load_wallet(self):
self.timer2.stop()
self.timer2.start(TIMER2_INTERVAL)
else:
self.hide_wallet()
self.new_wallet_ui = NewWalletWebUI(self.app, self.hub, self.debug)
self.hub.setNewWalletUI(self.new_wallet_ui)
self.new_wallet_ui.run()

def _handleTrayIconActivate(self, reason):
if reason == QSystemTrayIcon.DoubleClick:
self.showNormal()
self.activateWindow()

def handleExitAction(self, show_confirmation=True):
reply = QMessageBox.No
if show_confirmation:
self._handleShowAppAction()
reply=QMessageBox.question(self,'Exit %s?' % APP_NAME,
"Are you sure to exit %s?" % APP_NAME, QMessageBox.Yes,QMessageBox.No)
if not show_confirmation or reply==QMessageBox.Yes:
self.trayIcon.hide()
QTimer.singleShot(250, self.app.quit)

def _handleShowAppAction(self):
self.showNormal()
self.activateWindow()

def handleAboutAction(self):
self._handleShowAppAction()
self.about()


def _handleAboutToQuit(self):
self.hide_wallet()
log("%s is about to quit..." % APP_NAME, LEVEL_INFO)
if hasattr(self, "timer"):
self.timer.stop()
Expand Down

0 comments on commit 7e8aea5

Please sign in to comment.