Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtk3ui and macos fixes #273

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ deluge/ui/web/js/extjs/ext-extensions*.js
osx/app
RELEASE-VERSION
.venv*
/packaging/osx/app
/packaging/osx/py2app-build
*.app
/py2app-build
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ recursive-exclude deluge/tests *.pyc

graft deluge/ui/data
recursive-exclude deluge/ui/data *.desktop *.xml
graft deluge/ui/gtkui/glade
graft deluge/ui/gtk3/glade

include deluge/ui/web/index.html
include deluge/ui/web/css/*.css
Expand Down
2 changes: 1 addition & 1 deletion deluge/i18n/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def setup_translation():
log.error(exception)
setup_mock_translation()
elif deluge.common.osx_check():
libintl = ctypes.cdll.LoadLibrary('libintl.dylib')
libintl = ctypes.cdll.LoadLibrary('libintl.8.dylib')

if libintl:
libintl.bindtextdomain(
Expand Down
1 change: 1 addition & 0 deletions deluge/ui/gtk3/glade/create_torrent_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@
<property name="receives_default">True</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="on_button_cancel_clicked" swapped="no"/>
<accelerator key="Escape" signal="clicked"/>
</object>
<packing>
<property name="expand">False</property>
Expand Down
15 changes: 4 additions & 11 deletions deluge/ui/gtk3/glade/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<child type="submenu">
<object class="GtkMenu" id="menuitem1_menu1">
<property name="can_focus">False</property>
<property name="accel_group">accelgroup1</property>
<child>
<object class="GtkImageMenuItem" id="menuitem_addtorrent">
<property name="label" translatable="yes">_Add Torrent</property>
Expand All @@ -126,7 +127,6 @@
<property name="image">add-image</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_addtorrent_activate" swapped="no"/>
<accelerator key="O" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
Expand All @@ -138,7 +138,6 @@
<property name="image">new-image</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_createtorrent_activate" swapped="no"/>
<accelerator key="N" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
Expand All @@ -155,7 +154,6 @@
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="on_menuitem_quitdaemon_activate" swapped="no"/>
<accelerator key="Q" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
</object>
</child>
<child>
Expand All @@ -172,7 +170,6 @@
<property name="use_underline">True</property>
<property name="image">quit_image</property>
<property name="use_stock">False</property>
<property name="accel_group">accelgroup1</property>
<signal name="activate" handler="on_menuitem_quit_activate" swapped="no"/>
<accelerator key="Q" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
Expand All @@ -191,6 +188,7 @@
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="accel_group">accelgroup1</property>
<child>
<object class="GtkImageMenuItem" id="menuitem_preferences">
<property name="label" translatable="yes">_Preferences</property>
Expand All @@ -199,9 +197,7 @@
<property name="use_underline">True</property>
<property name="image">prefs-image</property>
<property name="use_stock">False</property>
<property name="accel_group">accelgroup1</property>
<signal name="activate" handler="on_menuitem_preferences_activate" swapped="no"/>
<accelerator key="P" signal="activate" modifiers="GDK_CONTROL_MASK"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if these accelerator keys were not removed from the glade files and instead we found an alternative way to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to implement portable shortcuts without removing them from the glade files.

</object>
</child>
<child>
Expand All @@ -213,7 +209,6 @@
<property name="image">connection-image</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_connectionmanager_activate" swapped="no"/>
<accelerator key="M" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
</object>
Expand All @@ -237,6 +232,7 @@
<object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="accel_group">accelgroup1</property>
<child>
<object class="GtkCheckMenuItem" id="menuitem_toolbar">
<property name="visible">True</property>
Expand Down Expand Up @@ -297,7 +293,6 @@
<property name="label" translatable="yes">_Find ...</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_search_filter_toggle" swapped="no"/>
<accelerator key="f" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
Expand All @@ -312,6 +307,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="accel_group">accelgroup1</property>
<child>
<object class="GtkCheckMenuItem" id="sidebar_show_zero">
<property name="visible">True</property>
Expand Down Expand Up @@ -377,7 +373,6 @@
<property name="use_underline">True</property>
<property name="use_stock">False</property>
<signal name="activate" handler="on_menuitem_faq_activate" swapped="no"/>
<accelerator key="F1" signal="activate"/>
</object>
</child>
<child>
Expand Down Expand Up @@ -405,7 +400,6 @@
<property name="use_underline">True</property>
<property name="image">about-image</property>
<property name="use_stock">False</property>
<property name="accel_group">accelgroup1</property>
<signal name="activate" handler="on_menuitem_about_activate" swapped="no"/>
</object>
</child>
Expand Down Expand Up @@ -467,7 +461,6 @@ This will filter torrents for the current selection on the sidebar.</property>
<property name="label" translatable="yes">Filter</property>
<property name="icon_name">system-search-symbolic</property>
<signal name="clicked" handler="on_search_filter_toggle" swapped="no"/>
<accelerator key="f" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object>
<packing>
<property name="expand">False</property>
Expand Down
13 changes: 10 additions & 3 deletions deluge/ui/gtk3/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ def on_die(*args):
log.debug('Win32 "die" handler registered')
elif osx_check() and windowing('quartz'):
try:
import gtkosx_application
gi.require_version('GtkosxApplication', '1.0')
from gi.repository import GtkosxApplication
except ImportError:
pass
else:
self.osxapp = gtkosx_application.gtkosx_application_get()
self.osxapp = GtkosxApplication.Application()
self.osxapp.connect('NSApplicationWillTerminate', on_die)
log.debug('OSX quartz "die" handler registered')

if os.getenv('DELUGE_IS_RUNNING_BUNDLE') != "":
launcherpath = os.path.join(os.path.dirname(sys.argv[0]), 'Deluge')
sys.argv[0] = launcherpath

# Set process name again to fix gtk issue
setproctitle(getproctitle())

Expand All @@ -182,6 +187,8 @@ def on_die(*args):
# Set language
if self.config['language'] is not None:
set_language(self.config['language'])
elif osx_check() and os.getenv('DELUGE_IS_RUNNING_BUNDLE') != "":
set_language(os.getenv('LANG'))

# Start the IPC Interface before anything else.. Just in case we are
# already running.
Expand Down Expand Up @@ -210,7 +217,7 @@ def on_die(*args):

def nsapp_open_file(osxapp, filename):
# Ignore command name which is raised at app launch (python opening main script).
if filename == sys.argv[0]:
if (filename == sys.argv[0] or filename == sys.argv[0]+"-bin"):
return True
process_args([filename])

Expand Down
36 changes: 35 additions & 1 deletion deluge/ui/gtk3/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
import logging
import os.path

from gi.repository import Gtk
from gi import require_version

require_version('Gtk', '3.0')
require_version('Gdk', '3.0')

from gi.repository import Gtk, Gdk

import deluge.common
import deluge.component as component
Expand Down Expand Up @@ -141,6 +146,35 @@ def __init__(self):
self.builder.connect_signals(self)

self.change_sensitivity = ['menuitem_addtorrent']
menubar = self.main_builder.get_object('menubar')
group = Gtk.accel_groups_from_object(self.mainwindow.window)[0]

file_menu = self.main_builder.get_object('menu_file').get_submenu()
edit_menu = self.main_builder.get_object('menu_edit').get_submenu()
torrent_menu = self.main_builder.get_object('menu_torrent').get_submenu()
view_menu = self.main_builder.get_object('menu_view').get_submenu()
help_menu = self.main_builder.get_object('menu_help').get_submenu()

Gtk.Menu.set_accel_group(file_menu, group)
Gtk.Menu.set_accel_group(edit_menu, group)
Gtk.Menu.set_accel_group(torrent_menu, group)
Gtk.Menu.set_accel_group(view_menu, group)
Gtk.Menu.set_accel_group(help_menu, group)

Gtk.Menu.set_accel_path(file_menu, "<DelugeMainWindow>/File")
Gtk.Menu.set_accel_path(edit_menu, "<DelugeMainWindow>/Edit")
Gtk.Menu.set_accel_path(torrent_menu, "<DelugeMainWindow>/Torrent")
Gtk.Menu.set_accel_path(view_menu, "<DelugeMainWindow>/View")
Gtk.Menu.set_accel_path(help_menu, "<DelugeMainWindow>/Help")

Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('menuitem_addtorrent')), Gdk.unicode_to_keyval(ord('o')), Gdk.ModifierType.CONTROL_MASK)
Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('menuitem_createtorrent')), Gdk.unicode_to_keyval(ord('n')), Gdk.ModifierType.CONTROL_MASK)
Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('menuitem_quitdaemon')), Gdk.unicode_to_keyval(ord('q')), Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.CONTROL_MASK)
Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('menuitem_preferences')), Gdk.unicode_to_keyval(ord('p')), Gdk.ModifierType.CONTROL_MASK)
Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('menuitem_connectionmanager')), Gdk.unicode_to_keyval(ord('m')), Gdk.ModifierType.CONTROL_MASK)
Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('find_menuitem')), Gdk.unicode_to_keyval(ord('f')), Gdk.ModifierType.CONTROL_MASK)
Gtk.AccelMap.add_entry(Gtk.MenuItem.get_accel_path(self.main_builder.get_object('menuitem_faq')), Gdk.keyval_from_name('F1'), 0)


def start(self):
for widget in self.change_sensitivity:
Expand Down
58 changes: 22 additions & 36 deletions deluge/ui/gtk3/menubar_osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,39 @@
#

from __future__ import unicode_literals
from gi import require_version

from gi.repository.Gdk import ModifierType
from gi.repository.Gtk import SeparatorMenuItem, accel_groups_from_object
from gi.repository.Gtk.AccelFlags import VISIBLE
require_version('Gtk', '3.0')
require_version('Gdk', '3.0')

from deluge.configmanager import ConfigManager


def accel_swap(item, group, skey, smod, dkey, dmod):
# Accel map hack broken, see ticket #3078
# item.remove_accelerator(group, ord(skey), smod)
item.add_accelerator('activate', group, ord(dkey), dmod, VISIBLE)
from gi.repository import Gtk, Gdk

from deluge.configmanager import ConfigManager

def accel_meta(item, group, key):
accel_swap(item, group, key, ModifierType.CONTROL_MASK, key, ModifierType.META_MASK)
def menubar_osx(gtkui, osxapp):

def accel_swap(item, key, modifier):
Gtk.AccelMap.change_entry(Gtk.MenuItem.get_accel_path(main_builder.get_object(item)), Gdk.keyval_from_name(key), modifier, True)

def menubar_osx(gtkui, osxapp):
main_builder = gtkui.mainwindow.get_builder()
menubar = main_builder.get_object('menubar')
group = accel_groups_from_object(gtkui.mainwindow.window)[0]
group = Gtk.accel_groups_from_object(gtkui.mainwindow.window)[0]

config = ConfigManager('gtk3ui.conf')

# NOTE: accel maps doesn't work with glade file format
# because of libglade not setting MenuItem accel groups
# That's why we remove / set accelerators by hand... (dirty)
# Clean solution: migrate glades files to gtkbuilder format
file_menu = main_builder.get_object('menu_file').get_submenu()
file_items = file_menu.get_children()
accel_meta(file_items[0], group, 'o')
accel_meta(file_items[1], group, 'n')
quit_all_item = file_items[3]
accel_swap(
quit_all_item,
group,
'q',
ModifierType.SHIFT_MASK | ModifierType.CONTROL_MASK,
'q',
ModifierType.SHIFT_MASK | ModifierType.META_MASK,
)

for item in range(2, len(file_items)): # remove quits
file_menu.remove(file_items[item])

menu_widget = main_builder.get_object('menu_edit')
edit_menu = menu_widget.get_submenu()
edit_items = edit_menu.get_children()
pref_item = edit_items[0]
accel_swap(
pref_item, group, 'p', ModifierType.CONTROL_MASK, ',', ModifierType.META_MASK
)
edit_menu.remove(pref_item)

conn_item = edit_items[1]
accel_meta(conn_item, group, 'm')
edit_menu.remove(conn_item)

menubar.remove(menu_widget)
Expand All @@ -74,14 +51,23 @@ def menubar_osx(gtkui, osxapp):
help_menu.remove(about_item)
help_menu.remove(help_items[3]) # separator

# Change accelerators
accel_swap('menuitem_addtorrent', 'o', Gdk.ModifierType.META_MASK)
accel_swap('menuitem_createtorrent', 'n', Gdk.ModifierType.META_MASK)
accel_swap('menuitem_quitdaemon', 'q', Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.META_MASK)
accel_swap('menuitem_preferences', 'comma', Gdk.ModifierType.META_MASK)
accel_swap('menuitem_connectionmanager', 'm', Gdk.ModifierType.META_MASK)
accel_swap('find_menuitem', 'f', Gdk.ModifierType.META_MASK)
accel_swap('menuitem_faq', 'question', Gdk.ModifierType.META_MASK)

menubar.hide()
osxapp.set_menu_bar(menubar)
# populate app menu
osxapp.insert_app_menu_item(about_item, 0)
osxapp.insert_app_menu_item(SeparatorMenuItem(), 1)
osxapp.insert_app_menu_item(Gtk.SeparatorMenuItem(), 1)
osxapp.insert_app_menu_item(pref_item, 2)
if not config['standalone']:
osxapp.insert_app_menu_item(conn_item, 3)
if quit_all_item.get_visible():
osxapp.insert_app_menu_item(SeparatorMenuItem(), 4)
osxapp.insert_app_menu_item(quit_all_item, 5)
osxapp.insert_app_menu_item(Gtk.SeparatorMenuItem(), 4)
osxapp.insert_app_menu_item(quit_all_item, 5)
11 changes: 11 additions & 0 deletions packaging/osx/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,16 @@
</array>
</dict>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>BitTorrent Magnet URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>magnet</string>
</array>
</dict>
</array>
</dict>
</plist>
Loading