Skip to content

Commit

Permalink
working on taskbar icon
Browse files Browse the repository at this point in the history
  • Loading branch information
vesellov committed Dec 17, 2015
1 parent c03316f commit 6a5e71d
Show file tree
Hide file tree
Showing 22 changed files with 335 additions and 120 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.~vsd
*.orig
.identities/
release/
screenshots/
plugins/
web/*.db
docs.teamlab/
Expand Down
5 changes: 5 additions & 0 deletions deploy/windows_innosetup/bitdust.iss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ DisableDirPage=yes
DisableProgramGroupPage=yes
SetupIconFile=.\build\icons\desktop.ico
UsePreviousAppDir=no
WizardImageStretch=no
WizardImageFile=bitdust128.bmp
WizardSmallImageFile=bitdust48.bmp
WizardImageBackColor=$ffffff


[Files]
Source: ".\build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Expand Down
Binary file added deploy/windows_innosetup/bitdust128.bmp
Binary file not shown.
Binary file added deploy/windows_innosetup/bitdust48.bmp
Binary file not shown.
Binary file added icons/connected16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/connected24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/error16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/error24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/off16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/off24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/sync16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/sync24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/updated16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/updated24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 1 addition & 13 deletions main/bpmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,10 @@ def run(UI='', options=None, args=None, overDict=None):
USE_TRAY_ICON = False
lg.out(4, ' USE_TRAY_ICON='+str(USE_TRAY_ICON))
if USE_TRAY_ICON:
if bpio.Linux():
icons_dict = {
'red': 'icon-red-24x24.png',
'yellow': 'icon-yellow-24x24.png',
'green': 'icon-green-24x24.png',
'gray': 'icon-gray-24x24.png', }
else:
icons_dict = {
'red': 'icon-red-16x16.png',
'yellow': 'icon-yellow-16x16.png',
'green': 'icon-green-16x16.png',
'gray': 'icon-gray-16x16.png', }
from system import tray_icon
icons_path = bpio.portablePath(os.path.join(bpio.getExecutableDir(), 'icons'))
lg.out(4, 'bpmain.run call tray_icon.init(%s)' % icons_path)
tray_icon.init(icons_path, icons_dict)
tray_icon.init(icons_path)
def _tray_control_func(cmd):
if cmd == 'exit':
import shutdowner
Expand Down
65 changes: 63 additions & 2 deletions main/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def doShowGUI(self, arg):
if USE_TRAY_ICON:
from system import tray_icon
if settings.NewWebGUI():
tray_icon.SetControlFunc(control.on_tray_icon_command)
# tray_icon.SetControlFunc(control.on_tray_icon_command)
tray_icon.SetControlFunc(self._on_tray_icon_command)
else:
tray_icon.SetControlFunc(webcontrol.OnTrayIconCommand)
if not settings.NewWebGUI():
Expand All @@ -290,6 +291,13 @@ def doPrintMessage(self, arg):

def doDestroyMe(self, arg):
global _Initializer
try:
from system.tray_icon import USE_TRAY_ICON
except:
USE_TRAY_ICON = False
if USE_TRAY_ICON:
from system import tray_icon
tray_icon.SetControlFunc(None)
del _Initializer
_Initializer = None
self.destroy()
Expand Down Expand Up @@ -395,7 +403,60 @@ def _init_modules(self):
# os_windows_update.SetNewVersionNotifyFunc(webcontrol.OnGlobalVersionReceived)
# reactor.callLater(0, os_windows_update.init)
reactor.callLater(0, webcontrol.OnInitFinalDone)



def _on_tray_icon_command(self, cmd):
lg.out(2,"initializer._on_tray_icon_command : [%s]" % cmd)
try:
if cmd == 'exit':
shutdowner.A('stop', 'exit')

elif cmd == 'restart':
# appList = bpio.find_process(['bpgui.',])
# if len(appList) > 0:
# shutdowner.A('stop', 'restartnshow') # ('restart', 'show'))
# else:
# shutdowner.A('stop', 'restart') # ('restart', ''))
shutdowner.A('stop', 'restart')

elif cmd == 'reconnect':
from p2p import network_connector
network_connector.A('reconnect')

elif cmd == 'show':
from web import control
control.show()

elif cmd == 'sync':
try:
from updates import git_proc
from system import tray_icon
def _sync_callback(result):
if result == 'error':
tray_icon.draw_icon('error')
reactor.callLater(5, tray_icon.restore_icon)
return
elif result == 'new-data':
tray_icon.draw_icon('updated')
reactor.callLater(5, tray_icon.restore_icon)
return
tray_icon.restore_icon()
tray_icon.draw_icon('sync')
git_proc.sync(_sync_callback)
except:
lg.exc()

elif cmd == 'hide':
pass

elif cmd == 'toolbar':
pass

else:
lg.warn('wrong command: ' + str(cmd))
except:
lg.exc()

#------------------------------------------------------------------------------

class MyTwistedOutputLog:
Expand Down
1 change: 0 additions & 1 deletion system/bpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ def getExecutableDir():
path = os.path.dirname(os.path.abspath(sys.executable))
else:
try:
# one level up from "lib"
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
except:
path = os.path.dirname(os.path.abspath(sys.argv[0]))
Expand Down
4 changes: 4 additions & 0 deletions system/child_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def errReceived(self, inp):
def processEnded(self, reason):
lg.out(2, 'child process [%s] FINISHED' % self.name)

#------------------------------------------------------------------------------

def run(child_name, params=[], base_dir='.', process_protocol=None):
"""
Expand Down Expand Up @@ -125,6 +126,7 @@ def kill_child(child_name):
killed = True
return killed

#------------------------------------------------------------------------------

def pipe(cmdargs):
"""
Expand Down Expand Up @@ -159,6 +161,8 @@ def pipe(cmdargs):


def detach(cmdargs):
"""
"""
lg.out(2, "child_process.detach %s" % str(cmdargs))
try:
if bpio.Windows():
Expand Down
116 changes: 76 additions & 40 deletions system/tray_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import sys
import platform

#------------------------------------------------------------------------------

Expand All @@ -28,16 +29,46 @@

_IconObject = None
_ControlFunc = None
_CurrentIcon = 'off'

_IconsDict = {
'red': 'icon-red-24x24.png',
'green': 'icon-green-24x24.png',
'gray': 'icon-gray-24x24.png',
'yellow': 'icon-yellow-24x24.png',
_IconsDict = {}

_LinuxIcons = {
'off': 'off24x24.png',
'connected': 'connected24x24.png',
'sync': 'sync24x24.png',
'error': 'error24x24.png',
'updated': 'updated24x24.png',
}

_WindowsIcons = {
'off': 'off16x16.png',
'connected': 'connected16x16.png',
'sync': 'sync16x16.png',
'error': 'error16x16.png',
'updated': 'updated16x16.png',
}

_PopUpIconsDict = {
'open': 'expand24x24.png',
'sync': 'synchronize24x24.png',
'restart': 'restart24x24.png',
'reconnect': 'network24x24.png',
'shutdown': 'shutdown24x24.png',
}

#------------------------------------------------------------------------------

def icons_dict():
global _IconsDict
return _IconsDict

def popup_icons_dict():
global _PopUpIconsDict
return _PopUpIconsDict

#------------------------------------------------------------------------------

def shutdown():
global _IconObject
global USE_TRAY_ICON
Expand All @@ -61,6 +92,11 @@ def init(icons_path, icons_files=None):

if icons_files:
_IconsDict = icons_files
else:
if platform.uname()[0] == 'Linux':
_IconsDict = _LinuxIcons
else:
_IconsDict = _WindowsIcons

import wx

Expand All @@ -70,21 +106,20 @@ def create_menu_item(menu, label, func, icon=None):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
if icon is not None:
item.SetBitmap(wx.Bitmap(icon))
item.SetBitmap(icon)
menu.AppendItem(item)
return item

def icons_dict():
global _IconsDict
return _IconsDict

class MyTaskBarIcon(wx.TaskBarIcon):
def __init__(self, icons_path, current_icon_name=None):
super(MyTaskBarIcon, self).__init__()
self.icons_path = icons_path
self.icons = {}
self.popup_icons = {}
for name, filename in icons_dict().items():
self.icons[name] = wx.IconFromBitmap(wx.Bitmap(os.path.join(icons_path, filename)))
for name, filename in popup_icons_dict().items():
self.popup_icons[name] = wx.Bitmap(os.path.join(icons_path, filename))
if len(self.icons) == 0:
self.icons['default'] = ''
if current_icon_name is not None and current_icon_name in self.icons.keys():
Expand All @@ -96,23 +131,11 @@ def __init__(self, icons_path, current_icon_name=None):

def CreatePopupMenu(self):
menu = wx.Menu()
icons = {
'show': os.path.join(self.icons_path, 'expand24x24.png'),
'sync': os.path.join(self.icons_path, 'synchronize24x24.png'),
'hide': os.path.join(self.icons_path, 'collapse24x24.png'),
'toolbar': os.path.join(self.icons_path, 'tools24x24.png'),
'restart': os.path.join(self.icons_path, 'restart24x24.png'),
'reconnect':os.path.join(self.icons_path, 'network24x24.png'),
'shutdown': os.path.join(self.icons_path, 'shutdown24x24.png'),
}
create_menu_item(menu, 'open', self.on_show, icons.get('show', None))
create_menu_item(menu, 'synchronize', self.on_sync, icons.get('sync', None))
# create_menu_item(menu, 'hide', self.on_hide, icons.get('hide', None))
# create_menu_item(menu, 'toolbar', self.on_toolbar, icons.get('toolbar', None))
# menu.AppendSeparator()
create_menu_item(menu, 'reconnect', self.on_reconnect, icons.get('reconnect', None))
create_menu_item(menu, 'restart', self.on_restart, icons.get('restart', None))
create_menu_item(menu, 'shutdown', self.on_exit, icons.get('shutdown', None))
create_menu_item(menu, 'open', self.on_show, self.popup_icons.get('open', None))
create_menu_item(menu, 'synchronize', self.on_sync, self.popup_icons.get('sync', None))
create_menu_item(menu, 'reconnect', self.on_reconnect, self.popup_icons.get('reconnect', None))
create_menu_item(menu, 'restart', self.on_restart, self.popup_icons.get('restart', None))
create_menu_item(menu, 'exit', self.on_exit, self.popup_icons.get('shutdown', None))
self.menu = menu
return menu

Expand Down Expand Up @@ -141,6 +164,7 @@ def on_toolbar(self, event):
control('toolbar')

def select_icon(self, icon_name):
# print 'select_icon', icon_name, self.icons
if icon_name in self.icons.keys():
self.current = icon_name
self.SetIcon(self.icons.get(self.current, self.icons.values()[0]), LABEL)
Expand Down Expand Up @@ -201,26 +225,38 @@ def control(cmd):
_ControlFunc(cmd)


def set_icon(name):
def draw_icon(name):
global _IconObject
if _IconObject is not None:
_IconObject.SetIcon(name)



def set_icon(name):
global _CurrentIcon
_CurrentIcon = name
draw_icon(name)


def restore_icon():
global _CurrentIcon
draw_icon(_CurrentIcon)


def state_changed(network, p2p):
if network == 'DISCONNECTED':
set_icon('gray')
return
# print 'state_changed', network, p2p
if [ network, p2p, ].count('CONNECTED') == 2:
set_icon('green')
return
if network == 'CONECTED' and p2p == 'DISCONNECTED':
set_icon('red')
return
if [ network, p2p ].count('CONNECTED') == 1:
set_icon('yellow')
set_icon('connected')
return
set_icon('gray')
# if network == 'DISCONNECTED':
# set_icon('off')
# return
# if network == 'CONECTED' and p2p == 'DISCONNECTED':
# set_icon('red')
# return
# if [ network, p2p ].count('CONNECTED') == 1:
# set_icon('yellow')
# return
set_icon('off')


def SetControlFunc(f):
Expand Down
Loading

0 comments on commit 6a5e71d

Please sign in to comment.