[#3441|GTKUI] Add a torrentdetails tabs position menu

The tabs placement for the torrentdetails notebook might not be to
everyone's liking so add a menu item to configure it.

Default the position back to top.
This commit is contained in:
Calum Lind 2021-02-20 14:48:58 +00:00
parent 291540b601
commit 1022448e4f
4 changed files with 40 additions and 5 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkAdjustment" id="spin_max_connections_adjustment">
@ -38,14 +38,14 @@
</object>
<object class="GtkWindow" id="tabs">
<property name="can_focus">False</property>
<child>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkNotebook" id="dummy_nb_see_main_win_torrent_info">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tab_pos">left</property>
<property name="enable_popup">True</property>
<child>
<object class="GtkScrolledWindow" id="status_tab">
<property name="visible">True</property>

View File

@ -121,6 +121,7 @@ DEFAULT_PREFS = {
'show_toolbar': True,
'show_statusbar': True,
'show_tabsbar': True,
'tabsbar_tab_pos': 'left',
'tabsbar_position': 235,
'sidebar_show_zero': False,
'sidebar_show_trackers': True,

View File

@ -108,6 +108,7 @@ class MainWindow(component.Component):
self.window = self.main_builder.get_object('main_window')
self.window.set_icon(get_deluge_icon())
self.tabsbar_pane = self.main_builder.get_object('tabsbar_pane')
self.tabsbar_torrent_info = self.main_builder.get_object('torrent_info')
self.sidebar_pane = self.main_builder.get_object('sidebar_pane')
# Keep a list of components to pause and resume when changing window state.
@ -154,6 +155,10 @@ class MainWindow(component.Component):
self.main_builder.prev_connect_signals(self.gtk_builder_signals_holder)
self.sidebar_pane.set_position(self.config['sidebar_position'])
self.tabsbar_pane.set_position(self.config['tabsbar_position'])
tab_pos = self.config['tabsbar_tab_pos']
self.tabsbar_torrent_info.set_tab_pos(
getattr(Gtk.PositionType, tab_pos.upper())
)
if not (
self.config['start_in_tray'] and self.config['enable_system_tray']

View File

@ -14,7 +14,14 @@ from __future__ import unicode_literals
import logging
from collections import namedtuple
from gi.repository.Gtk import CheckMenuItem, Menu, SeparatorMenuItem
from gi.repository.Gtk import (
CheckMenuItem,
Menu,
MenuItem,
PositionType,
RadioMenuItem,
SeparatorMenuItem,
)
import deluge.component as component
from deluge.ui.client import client
@ -100,6 +107,7 @@ class TorrentDetails(component.Component):
def __init__(self):
component.Component.__init__(self, 'TorrentDetails', interval=2)
main_builder = component.get('MainWindow').get_builder()
self.config = component.get('MainWindow').config
self.notebook = main_builder.get_object('torrent_info')
@ -175,7 +183,6 @@ class TorrentDetails(component.Component):
# Generate the checklist menu
self.generate_menu()
self.config = component.get('MainWindow').config
self.visible(self.config['show_tabsbar'])
def tab_insert_position(self, weight):
@ -314,9 +321,24 @@ class TorrentDetails(component.Component):
self.generate_menu()
self.visible(True)
def create_tab_pos_menuitem(self):
"""Returns a menu to select which side of the notebook the tabs should be shown"""
tab_pos_menu = Menu()
tab_pos_menuitem = MenuItem(_('Position'))
group = []
for pos in ('top', 'right', 'bottom', 'left'):
menuitem = RadioMenuItem.new_with_mnemonic(group, _(pos.capitalize()))
group = menuitem.get_group()
menuitem.connect('toggled', self._on_tabs_pos_toggled, pos)
menuitem.set_active(pos == self.notebook.get_tab_pos().value_nick)
tab_pos_menu.append(menuitem)
tab_pos_menuitem.set_submenu(tab_pos_menu)
return tab_pos_menuitem
def generate_menu(self):
"""Generates the checklist menu for all the tabs and attaches it"""
menu = Menu()
# Create 'All' menuitem and a separator
menuitem = CheckMenuItem.new_with_mnemonic(self.translate_tabs['All'])
menuitem.set_name('All')
@ -347,6 +369,9 @@ class TorrentDetails(component.Component):
menuitem.connect('toggled', self._on_menuitem_toggled)
menu.append(menuitem)
menu.append(SeparatorMenuItem())
menu.append(self.create_tab_pos_menuitem())
self.menu_tabs.set_submenu(menu)
self.menu_tabs.show_all()
@ -440,6 +465,10 @@ class TorrentDetails(component.Component):
self.set_tab_visible(name, widget.get_active())
def _on_tabs_pos_toggled(self, widget, position):
self.config['tabsbar_tab_pos'] = position
self.notebook.set_tab_pos(getattr(PositionType, position.upper()))
def save_state(self):
"""We save the state, which is basically the tab_index list"""
# Update the visiblity status of all tabs