mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-06 16:38:43 +00:00
[GTKUI] Cleaup/refactor mainwindow
This commit is contained in:
parent
1637da84e4
commit
722ca41584
1 changed files with 34 additions and 62 deletions
|
@ -62,13 +62,13 @@ class MainWindow(component.Component):
|
||||||
self.screen = wnck.screen_get_default()
|
self.screen = wnck.screen_get_default()
|
||||||
component.Component.__init__(self, 'MainWindow', interval=2)
|
component.Component.__init__(self, 'MainWindow', interval=2)
|
||||||
self.config = ConfigManager('gtkui.conf')
|
self.config = ConfigManager('gtkui.conf')
|
||||||
self.gtk_builder_signals_holder = _GtkBuilderSignalsHolder()
|
|
||||||
self.main_builder = gtk.Builder()
|
self.main_builder = gtk.Builder()
|
||||||
|
|
||||||
# Patch this GtkBuilder to avoid connecting signals from elsewhere
|
# Patch this GtkBuilder to avoid connecting signals from elsewhere
|
||||||
#
|
#
|
||||||
# Think about splitting up the main window gtkbuilder file into the necessary parts
|
# Think about splitting up mainwindow gtkbuilder file into the necessary parts
|
||||||
# in order not to have to monkey patch GtkBuilder. Those parts would then need to
|
# to avoid GtkBuilder monkey patch. Those parts would then need adding to mainwindow 'by hand'.
|
||||||
# be added to the main window "by hand".
|
self.gtk_builder_signals_holder = _GtkBuilderSignalsHolder()
|
||||||
self.main_builder.prev_connect_signals = copy.deepcopy(self.main_builder.connect_signals)
|
self.main_builder.prev_connect_signals = copy.deepcopy(self.main_builder.connect_signals)
|
||||||
|
|
||||||
def patched_connect_signals(*a, **k):
|
def patched_connect_signals(*a, **k):
|
||||||
|
@ -77,27 +77,23 @@ class MainWindow(component.Component):
|
||||||
self.main_builder.connect_signals = patched_connect_signals
|
self.main_builder.connect_signals = patched_connect_signals
|
||||||
|
|
||||||
# Get Gtk Builder files Main Window, New release dialog, and Tabs.
|
# Get Gtk Builder files Main Window, New release dialog, and Tabs.
|
||||||
self.main_builder.add_from_file(resource_filename('deluge.ui.gtkui', os.path.join(
|
for filename in ('main_window.ui', 'main_window.new_release.ui', 'main_window.tabs.ui',
|
||||||
'glade', 'main_window.ui')))
|
'main_window.tabs.menu_file.ui', 'main_window.tabs.menu_peer.ui'):
|
||||||
self.main_builder.add_from_file(resource_filename('deluge.ui.gtkui', os.path.join(
|
self.main_builder.add_from_file(
|
||||||
'glade', 'main_window.new_release.ui')))
|
resource_filename('deluge.ui.gtkui', os.path.join('glade', filename)))
|
||||||
self.main_builder.add_from_file(resource_filename('deluge.ui.gtkui', os.path.join(
|
|
||||||
'glade', 'main_window.tabs.ui')))
|
|
||||||
self.main_builder.add_from_file(resource_filename('deluge.ui.gtkui', os.path.join(
|
|
||||||
'glade', 'main_window.tabs.menu_file.ui')))
|
|
||||||
self.main_builder.add_from_file(resource_filename('deluge.ui.gtkui', os.path.join(
|
|
||||||
'glade', 'main_window.tabs.menu_peer.ui')))
|
|
||||||
|
|
||||||
self.window = self.main_builder.get_object('main_window')
|
self.window = self.main_builder.get_object('main_window')
|
||||||
self.window.set_icon(deluge.ui.gtkui.common.get_deluge_icon())
|
self.window.set_icon(deluge.ui.gtkui.common.get_deluge_icon())
|
||||||
self.vpaned = self.main_builder.get_object('vpaned')
|
self.vpaned = self.main_builder.get_object('vpaned')
|
||||||
self.initial_vpaned_position = self.config['window_pane_position']
|
self.initial_vpaned_position = self.config['window_pane_position']
|
||||||
|
|
||||||
|
# Keep a list of components to pause and resume when changing window state.
|
||||||
|
self.child_components = ['TorrentView', 'StatusBar', 'TorrentDetails']
|
||||||
|
|
||||||
# Load the window state
|
# Load the window state
|
||||||
self.load_window_state()
|
self.load_window_state()
|
||||||
|
|
||||||
# Keep track of window's minimization state so that we don't update the
|
# Keep track of window minimization state so we don't update UI when it is minimized.
|
||||||
# UI when it is minimized.
|
|
||||||
self.is_minimized = False
|
self.is_minimized = False
|
||||||
self.restart = False
|
self.restart = False
|
||||||
|
|
||||||
|
@ -119,9 +115,8 @@ class MainWindow(component.Component):
|
||||||
self.gtk_builder_signals_holder.connect_signals(mapping_or_class)
|
self.gtk_builder_signals_holder.connect_signals(mapping_or_class)
|
||||||
|
|
||||||
def first_show(self):
|
def first_show(self):
|
||||||
if not(self.config['start_in_tray'] and
|
if not(self.config['start_in_tray'] and self.config['enable_system_tray']
|
||||||
self.config['enable_system_tray']) and not \
|
) and not self.window.get_property('visible'):
|
||||||
self.window.get_property('visible'):
|
|
||||||
log.debug('Showing window')
|
log.debug('Showing window')
|
||||||
self.main_builder.prev_connect_signals(self.gtk_builder_signals_holder)
|
self.main_builder.prev_connect_signals(self.gtk_builder_signals_holder)
|
||||||
self.vpaned.set_position(self.initial_vpaned_position)
|
self.vpaned.set_position(self.initial_vpaned_position)
|
||||||
|
@ -130,42 +125,27 @@ class MainWindow(component.Component):
|
||||||
gtk.main_iteration()
|
gtk.main_iteration()
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
try:
|
component.resume(self.child_components)
|
||||||
component.resume('TorrentView')
|
|
||||||
component.resume('StatusBar')
|
|
||||||
component.resume('TorrentDetails')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
def hide(self):
|
def hide(self):
|
||||||
component.pause('TorrentView')
|
|
||||||
component.get('TorrentView').save_state()
|
component.get('TorrentView').save_state()
|
||||||
component.pause('StatusBar')
|
component.pause(self.child_components)
|
||||||
component.pause('TorrentDetails')
|
|
||||||
# Store the x, y positions for when we restore the window
|
# Store the x, y positions for when we restore the window
|
||||||
self.window_x_pos = self.window.get_position()[0]
|
self.window_x_pos, self.window_y_pos = self.window.get_position()
|
||||||
self.window_y_pos = self.window.get_position()[1]
|
|
||||||
self.window.hide()
|
self.window.hide()
|
||||||
|
|
||||||
def present(self):
|
def present(self):
|
||||||
def restore():
|
def restore():
|
||||||
# Restore the proper x,y coords for the window prior to showing it
|
# Restore the proper x,y coords for the window prior to showing it
|
||||||
try:
|
|
||||||
if self.window_x_pos == -32000 or self.window_y_pos == -32000:
|
if self.window_x_pos == -32000 or self.window_y_pos == -32000:
|
||||||
self.config['window_x_pos'] = 0
|
self.config['window_x_pos'] = self.config['window_y_pos'] = 0
|
||||||
self.config['window_y_pos'] = 0
|
|
||||||
else:
|
else:
|
||||||
self.config['window_x_pos'] = self.window_x_pos
|
self.config['window_x_pos'] = self.window_x_pos
|
||||||
self.config['window_y_pos'] = self.window_y_pos
|
self.config['window_y_pos'] = self.window_y_pos
|
||||||
except Exception:
|
|
||||||
pass
|
component.resume(self.child_components)
|
||||||
try:
|
|
||||||
component.resume('TorrentView')
|
|
||||||
component.resume('StatusBar')
|
|
||||||
component.resume('TorrentDetails')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.window.present()
|
self.window.present()
|
||||||
self.load_window_state()
|
self.load_window_state()
|
||||||
|
@ -229,19 +209,14 @@ class MainWindow(component.Component):
|
||||||
quit_gtkui()
|
quit_gtkui()
|
||||||
|
|
||||||
def load_window_state(self):
|
def load_window_state(self):
|
||||||
x = self.config['window_x_pos']
|
self.window.move(self.config['window_x_pos'], self.config['window_y_pos'])
|
||||||
y = self.config['window_y_pos']
|
self.window.resize(self.config['window_width'], self.config['window_height'])
|
||||||
w = self.config['window_width']
|
|
||||||
h = self.config['window_height']
|
|
||||||
self.window.move(x, y)
|
|
||||||
self.window.resize(w, h)
|
|
||||||
if self.config['window_maximized']:
|
if self.config['window_maximized']:
|
||||||
self.window.maximize()
|
self.window.maximize()
|
||||||
|
|
||||||
def on_window_configure_event(self, widget, event):
|
def on_window_configure_event(self, widget, event):
|
||||||
if not self.config['window_maximized'] and self.visible:
|
if not self.config['window_maximized'] and self.visible:
|
||||||
self.config['window_x_pos'] = self.window.get_position()[0]
|
self.config['window_x_pos'], self.config['window_y_pos'] = self.window.get_position()
|
||||||
self.config['window_y_pos'] = self.window.get_position()[1]
|
|
||||||
self.config['window_width'] = event.width
|
self.config['window_width'] = event.width
|
||||||
self.config['window_height'] = event.height
|
self.config['window_height'] = event.height
|
||||||
|
|
||||||
|
@ -255,16 +230,12 @@ class MainWindow(component.Component):
|
||||||
if event.changed_mask & WINDOW_STATE_ICONIFIED:
|
if event.changed_mask & WINDOW_STATE_ICONIFIED:
|
||||||
if event.new_window_state & WINDOW_STATE_ICONIFIED:
|
if event.new_window_state & WINDOW_STATE_ICONIFIED:
|
||||||
log.debug('MainWindow is minimized..')
|
log.debug('MainWindow is minimized..')
|
||||||
component.pause('TorrentView')
|
component.get('TorrentView').save_state()
|
||||||
component.pause('StatusBar')
|
component.pause(self.child_components)
|
||||||
self.is_minimized = True
|
self.is_minimized = True
|
||||||
else:
|
else:
|
||||||
log.debug('MainWindow is not minimized..')
|
log.debug('MainWindow is not minimized..')
|
||||||
try:
|
component.resume(self.child_components)
|
||||||
component.resume('TorrentView')
|
|
||||||
component.resume('StatusBar')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
self.is_minimized = False
|
self.is_minimized = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -300,8 +271,9 @@ class MainWindow(component.Component):
|
||||||
upload_rate = fspeed(status['payload_upload_rate'], precision=0, shortform=True)
|
upload_rate = fspeed(status['payload_upload_rate'], precision=0, shortform=True)
|
||||||
self.window.set_title(_('D: %s U: %s - Deluge' % (download_rate, upload_rate)))
|
self.window.set_title(_('D: %s U: %s - Deluge' % (download_rate, upload_rate)))
|
||||||
if self.config['show_rate_in_title']:
|
if self.config['show_rate_in_title']:
|
||||||
client.core.get_session_status(['payload_download_rate',
|
client.core.get_session_status(
|
||||||
'payload_upload_rate']).addCallback(_on_get_session_status)
|
['payload_download_rate', 'payload_upload_rate']
|
||||||
|
).addCallback(_on_get_session_status)
|
||||||
|
|
||||||
def _on_set_show_rate_in_title(self, key, value):
|
def _on_set_show_rate_in_title(self, key, value):
|
||||||
if value:
|
if value:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue