def process_key_event(self, send_key_action_cb, wid, key_event): if self.swap_keys: trans = self.key_translations.get(key_event.keyname) if trans: log("swap keys: translating key '%s' to %s", key_event, trans) key_event.keycode, key_event.keyname = trans if key_event.keycode==self.num_lock_keycode and not key_event.pressed: log("toggling numlock") self.num_lock_state = not self.num_lock_state getOSXMenuHelper().update_numlock(self.num_lock_state) send_key_action_cb(wid, key_event)
def process_key_event(self, send_key_action_cb, wid, key_event): if self.swap_keys or key_event.keyname in ALWAYS_SWAP: trans = self.key_translations.get(key_event.keyname) if trans: log("swap keys: translating key '%s' to %s", key_event, trans) key_event.keycode, key_event.keyname = trans if key_event.keycode == self.num_lock_keycode: if not key_event.pressed: log("toggling numlock") self.num_lock_state = not self.num_lock_state getOSXMenuHelper().update_numlock(self.num_lock_state) #do not forward the "Escape" key that numlock usually comes up as return send_key_action_cb(wid, key_event)
def do_init(): osxapp = get_OSXApplication() icon = get_icon("xpra.png") if icon: osxapp.set_dock_icon_pixbuf(icon) mh = getOSXMenuHelper(None) osxapp.set_dock_menu(mh.build_dock_menu()) osxapp.set_menu_bar(mh.rebuild())
def set_global_menu(self): mh = getOSXMenuHelper() if mh.build()!=self.menu: log.error("the menu (%s) is not from the menu helper!", self.menu) return #redundant: the menu bar has already been set during gui init #using the basic the simple menu from build_menu_bar() self.macapp.set_menu_bar(self.menu) mh.add_full_menu() debug("OSXTray.set_global_menu() done")
def do_init(): osxapp = get_OSXApplication() log("do_init() osxapp=%s", osxapp) from xpra.platform.paths import get_icon icon = get_icon("xpra.png") log("do_init() icon=%s", icon) if icon: osxapp.set_dock_icon_pixbuf(icon) from xpra.platform.darwin.osx_menu import getOSXMenuHelper mh = getOSXMenuHelper(None) log("do_init() menu helper=%s", mh) osxapp.set_dock_menu(mh.build_dock_menu()) osxapp.set_menu_bar(mh.rebuild())
def set_global_menu(self): mh = getOSXMenuHelper() if mh.build() != self.menu: log.error("the menu (%s) is not from the menu helper!", self.menu) return #redundant: the menu bar has already been set during gui init #using the basic the simple menu from build_menu_bar() import warnings with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=".*invalid cast from 'GtkMenuBar'") self.macapp.set_menu_bar(self.menu) mh.add_full_menu() log("OSXTray.set_global_menu() done")
def do_init(): osxapp = get_OSXApplication() log("do_init() osxapp=%s", osxapp) if not osxapp: return #not much else we can do here from xpra.platform.paths import get_icon from xpra.platform.gui import get_default_icon filename = get_default_icon() icon = get_icon(filename) log("do_init() icon=%s", icon) if icon: osxapp.set_dock_icon_pixbuf(icon) from xpra.platform.darwin.osx_menu import getOSXMenuHelper mh = getOSXMenuHelper(None) log("do_init() menu helper=%s", mh) osxapp.set_dock_menu(mh.build_dock_menu()) osxapp.set_menu_bar(mh.rebuild())
def do_init(): osxapp = get_OSXApplication() log("do_init() osxapp=%s", osxapp) if not osxapp: return #not much else we can do here from xpra.platform.paths import get_icon from xpra.platform.gui import get_default_icon filename = get_default_icon() icon = get_icon(filename) log("do_init() icon=%s", icon) if icon: osxapp.set_dock_icon_pixbuf(icon) from xpra.platform.darwin.osx_menu import getOSXMenuHelper mh = getOSXMenuHelper(None) log("do_init() menu helper=%s", mh) osxapp.set_dock_menu(mh.build_dock_menu()) import warnings with warnings.catch_warnings(): warnings.filterwarnings("ignore", message=".*invalid cast from 'GtkMenuBar'") osxapp.set_menu_bar(mh.rebuild())
def window_focused(window, event): global window_menus wid = window._id menu_data = window_menus.get(wid) log("window_focused(%s, %s) menu(%s)=%s", window, event, wid, menu_data) application_actions, window_menu = None, None if menu_data: menus, application_action_callback, window_action_callback = menu_data application_actions = menus.get("application-actions") window_actions = menus.get("window-actions") window_menu = menus.get("window-menu") from xpra.platform.darwin.osx_menu import getOSXMenuHelper mh = getOSXMenuHelper() mh.rebuild() mh.add_full_menu() if not menu_data or (not application_actions and not window_actions) or not window_menu: return #add the application menus after that: #ie: menu = { # 'enabled': True, # 'application-id': 'org.xpra.ExampleMenu', # 'application-actions': {'quit': (True, '', ()), 'about': (True, '', ()), 'help': (True, '', ()), 'custom': (True, '', ()), 'activate-tab': (True, 's', ()), 'preferences': (True, '', ())}, # 'window-actions': {'edit-profile': (True, 's', ()), 'reset': (True, 'b', ()), 'about': (True, '', ()), 'help': (True, '', ()), 'fullscreen': (True, '', (0,)), 'detach-tab': (True, '', ()), 'save-contents': (True, '', ()), 'zoom': (True, 'i', ()), 'move-tab': (True, 'i', ()), 'new-terminal': (True, '(ss)', ()), 'switch-tab': (True, 'i', ()), 'new-profile': (True, '', ()), 'close': (True, 's', ()), 'show-menubar': (True, '', (1,)), 'select-all': (True, '', ()), 'copy': (True, '', ()), 'paste': (True, 's', ()), 'find': (True, 's', ()), 'preferences': (True, '', ())}, # 'window-menu': {0: # {0: ({':section': (0, 1)}, {':section': (0, 2)}, {':section': (0, 3)}), # 1: ({'action': 'win.new-terminal', 'target': ('default', 'default'), 'label': '_New Terminal'},), # 2: ({'action': 'app.preferences', 'label': '_Preferences'},), # 3: ({'action': 'app.help', 'label': '_Help'}, {'action': 'app.about', 'label': '_About'}, {'action': 'app.quit', 'label': '_Quit'}), # } # } # } #go through all the groups (not sure how we would get more than one with gtk menus.. but still): def cb(menu_item): #find the action for this item: action = getattr(menu_item, "_action", "undefined") log("application menu cb %s, action=%s", menu_item, action) if action.startswith("app."): callback = application_action_callback actions = application_actions action = action[4:] elif action.startswith("win."): callback = window_action_callback actions = window_actions action = action[4:] else: log.warn("Warning: unknown action type '%s'", action) return action_def = actions.get(action) if action_def is None: log.warn("Warning: cannot find action '%s'", action) return enabled, state, pdata = action_def[:3] if not enabled: log("action %s: %s is not enabled", action, action_def) return if len(action_def) >= 4: callback = action_def[3] #use action supplied callback log( "OSX application menu item %s, action=%s, action_def=%s, callback=%s", menu_item, action, action_def, callback) if callback: callback(menu_item, action, state, pdata) for group_id in sorted(window_menu.keys()): group = window_menu[group_id] try: title = str(window._metadata.get("title")) assert title except: title = window.get_title() or "Application" app_menu = mh.make_menu() for menuid in sorted(group.keys()): menu_entries = group[menuid] for d in menu_entries: action = d.get("action") if not action: continue label = d.get("label") or action item = mh.menuitem(label, cb=cb) item._action = action item._target = d.get("target") app_menu.add(item) log("added %s to %s menu for %s", label, title, window) mh.add_to_menu_bar(title, app_menu)
def window_focused(window, event): global window_menus wid = window._id menu_data = window_menus.get(wid) log("window_focused(%s, %s) menu(%s)=%s", window, event, wid, menu_data) application_actions, window_menu = None, None if menu_data: menus, application_action_callback, window_action_callback = menu_data application_actions = menus.get("application-actions") window_actions = menus.get("window-actions") window_menu = menus.get("window-menu") from xpra.platform.darwin.osx_menu import getOSXMenuHelper mh = getOSXMenuHelper() mh.rebuild() mh.add_full_menu() if not menu_data or (not application_actions and not window_actions) or not window_menu: return #add the application menus after that: #ie: menu = { # 'enabled': True, # 'application-id': 'org.xpra.ExampleMenu', # 'application-actions': {'quit': (True, '', ()), 'about': (True, '', ()), 'help': (True, '', ()), 'custom': (True, '', ()), 'activate-tab': (True, 's', ()), 'preferences': (True, '', ())}, # 'window-actions': {'edit-profile': (True, 's', ()), 'reset': (True, 'b', ()), 'about': (True, '', ()), 'help': (True, '', ()), 'fullscreen': (True, '', (0,)), 'detach-tab': (True, '', ()), 'save-contents': (True, '', ()), 'zoom': (True, 'i', ()), 'move-tab': (True, 'i', ()), 'new-terminal': (True, '(ss)', ()), 'switch-tab': (True, 'i', ()), 'new-profile': (True, '', ()), 'close': (True, 's', ()), 'show-menubar': (True, '', (1,)), 'select-all': (True, '', ()), 'copy': (True, '', ()), 'paste': (True, 's', ()), 'find': (True, 's', ()), 'preferences': (True, '', ())}, # 'window-menu': {0: # {0: ({':section': (0, 1)}, {':section': (0, 2)}, {':section': (0, 3)}), # 1: ({'action': 'win.new-terminal', 'target': ('default', 'default'), 'label': '_New Terminal'},), # 2: ({'action': 'app.preferences', 'label': '_Preferences'},), # 3: ({'action': 'app.help', 'label': '_Help'}, {'action': 'app.about', 'label': '_About'}, {'action': 'app.quit', 'label': '_Quit'}), # } # } # } #go through all the groups (not sure how we would get more than one with gtk menus.. but still): def cb(menu_item): #find the action for this item: action = getattr(menu_item, "_action", "undefined") log("application menu cb %s, action=%s", menu_item, action) if action.startswith("app."): callback = application_action_callback actions = application_actions action = action[4:] elif action.startswith("win."): callback = window_action_callback actions = window_actions action = action[4:] else: log.warn("Warning: unknown action type '%s'", action) return action_def = actions.get(action) if action_def is None: log.warn("Warning: cannot find action '%s'", action) return enabled, state, pdata = action_def[:3] if not enabled: log("action %s: %s is not enabled", action, action_def) return if len(action_def)>=4: callback = action_def[3] #use action supplied callback log("OSX application menu item %s, action=%s, action_def=%s, callback=%s", menu_item, action, action_def, callback) if callback: callback(menu_item, action, state, pdata) for group_id in sorted(window_menu.keys()): group = window_menu[group_id] try: title = str(window._metadata.get("title")) assert title except: title = window.get_title() or "Application" app_menu = mh.make_menu() for menuid in sorted(group.keys()): menu_entries = group[menuid] for d in menu_entries: action = d.get("action") if not action: continue label = d.get("label") or action item = mh.menuitem(label, cb=cb) item._action = action item._target = d.get("target") app_menu.add(item) log("added %s to %s menu for %s", label, title, window) mh.add_to_menu_bar(title, app_menu)