Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* move paths and extension definition code to platforms module
* re-use this code for audio tagging so we don't need a tray to access the icon
* don't setup the tray then hide it: just set it up when we're ready to show it

git-svn-id: https://xpra.org/svn/Xpra/trunk@13734 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 15, 2016
1 parent 433f907 commit 3212001
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
15 changes: 3 additions & 12 deletions src/xpra/client/tray_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os.path

from xpra.platform.paths import get_icon_dir
from xpra.platform.paths import get_icon_dir, get_tray_icon_filename, get_default_icon_extension
from xpra.log import Logger
from collections import deque
log = Logger("tray")
Expand All @@ -28,8 +28,6 @@ def __init__(self, client, menu, tooltip, icon_filename, size_changed_cb, click_
self.exit_cb = exit_cb
self.tray_widget = None
self.default_icon_filename = icon_filename
self.default_icon_extension = "png"
self.default_icon_name = "xpra.png"
#some implementations need this for guessing the geometry (see recalculate_geometry):
self.geometry_guess = None
self.tray_event_locations = deque(maxlen=512)
Expand All @@ -40,14 +38,7 @@ def cleanup(self):
self.tray_widget = None

def get_tray_icon_filename(self, cmdlineoverride=None):
if cmdlineoverride and os.path.exists(cmdlineoverride):
log("get_tray_icon_filename using %s from command line", cmdlineoverride)
return cmdlineoverride
f = os.path.join(get_icon_dir(), self.default_icon_name)
if os.path.exists(f):
log("get_tray_icon_filename using default: %s", f)
return f
return None
return get_tray_icon_filename(cmdlineoverride)

def ready(self):
pass
Expand Down Expand Up @@ -89,7 +80,7 @@ def set_icon(self, basefilename=None):
filename = self.default_icon_filename or self.get_tray_icon_filename()
else:
#create full path + filename from basefilename:
with_ext = "%s.%s" % (basefilename, self.default_icon_extension)
with_ext = "%s.%s" % (basefilename, get_default_icon_extension())
icon_dir = get_icon_dir()
filename = os.path.join(icon_dir, with_ext)
if not filename or not os.path.exists(filename):
Expand Down
23 changes: 9 additions & 14 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from xpra.platform.gui import (ready as gui_ready, get_vrefresh, get_antialias_info, get_icc_info, get_double_click_time, show_desktop, get_cursor_size,
get_double_click_distance, get_native_notifier_classes, get_native_tray_classes, get_native_system_tray_classes,
get_native_tray_menu_helper_classes, get_xdpi, get_ydpi, get_number_of_desktops, get_desktop_names, get_wm_name, ClientExtras)
from xpra.platform.paths import get_tray_icon_filename
from xpra.codecs.loader import load_codecs, codec_versions, has_codec, get_codec, PREFERED_ENCODING_ORDER, PROBLEMATIC_ENCODINGS
from xpra.codecs.video_helper import getVideoHelper, NO_GFX_CSC_OPTIONS
from xpra.scripts.main import sound_option
Expand Down Expand Up @@ -440,22 +441,16 @@ def noauto(v):
overrides = [noauto(getattr(opts, "keyboard_%s" % x)) for x in ("layout", "layouts", "variant", "variants", "options")]
self.keyboard_helper = self.keyboard_helper_class(self.send, opts.keyboard_sync, opts.key_shortcut, opts.keyboard_raw, *overrides)

tray_icon_filename = opts.tray_icon
tray_icon_filename = get_tray_icon_filename(opts.tray_icon)
if opts.tray:
self.menu_helper = self.make_tray_menu_helper()
self.tray = self.setup_xpra_tray(opts.tray_icon)
if self.tray:
tray_icon_filename = self.tray.get_tray_icon_filename(tray_icon_filename)
#keep tray widget hidden until:
self.tray.hide()
if opts.delay_tray:
def show_tray(*args):
traylog("first ui received, showing tray %s", self.tray)
self.tray.show()
self.connect("first-ui-received", show_tray)
else:
#show when the main loop is running:
self.idle_add(self.tray.show)
def setup_xpra_tray():
self.tray = self.setup_xpra_tray(opts.tray_icon)
if opts.delay_tray:
self.connect("first-ui-received", setup_xpra_tray)
else:
#show when the main loop is running:
self.idle_add(setup_xpra_tray)

notifylog("client_supports_notifications=%s", self.client_supports_notifications)
if self.client_supports_notifications:
Expand Down
18 changes: 18 additions & 0 deletions src/xpra/platform/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ def get_icon(name):
return get_icon_from_file(filename)


def get_default_icon_extension():
return "png"

def get_default_tray_icon_name():
return "xpra.png"

def get_tray_icon_filename(cmdlineoverride=None):
if cmdlineoverride and os.path.exists(cmdlineoverride):
return cmdlineoverride
f = os.path.join(get_icon_dir(), get_default_tray_icon_name())
if os.path.exists(f):
return f
return None


LICENSE_TEXT = None
def get_license_text(self):
global LICENSE_TEXT
Expand Down Expand Up @@ -227,6 +242,9 @@ def do_get_sound_command():
"do_get_app_dir",
"do_get_icon_dir")
platform_import(globals(), "paths", False,
"get_default_icon_extension",
"get_default_tray_icon_name",
"get_tray_icon_filename",
"do_get_sshpass_command",
"do_get_xpra_command",
"do_get_sound_command",
Expand Down
7 changes: 7 additions & 0 deletions src/xpra/platform/win32/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ def _get_data_dir():
os.mkdir(data_dir)
return data_dir


def do_get_icon_dir():
from xpra.platform.paths import get_app_dir
return os.path.join(get_app_dir(), "icons")

def get_default_icon_extension():
return "ico"

def get_default_tray_icon_name():
return "xpra.ico"


def do_get_system_conf_dirs():
#ie: "C:\Documents and Settings\All Users\Application Data\Xpra" with XP
Expand Down
2 changes: 0 additions & 2 deletions src/xpra/platform/win32/win32_tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Win32Tray(TrayBase):

def __init__(self, *args):
TrayBase.__init__(self, *args)
self.default_icon_extension = "ico"
self.default_icon_name = "xpra.ico"
self.calculate_offset()
icon_filename = self.get_tray_icon_filename(self.default_icon_filename)
self.tray_widget = win32NotifyIcon(self.tooltip, self.move_cb, self.click_cb, self.exit_cb, None, icon_filename)
Expand Down

0 comments on commit 3212001

Please sign in to comment.