mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
MainWindow state saving.
This commit is contained in:
parent
61216e06b0
commit
0ed8ac1cdc
3 changed files with 56 additions and 5 deletions
|
@ -115,17 +115,14 @@ class Config:
|
||||||
log.debug("Setting '%s' to %s", key, value)
|
log.debug("Setting '%s' to %s", key, value)
|
||||||
if self.config[key] != value:
|
if self.config[key] != value:
|
||||||
self.config[key] = value
|
self.config[key] = value
|
||||||
# Whenever something is set, we should save
|
|
||||||
self.save()
|
|
||||||
# Run the set_function for this key if any
|
# Run the set_function for this key if any
|
||||||
try:
|
try:
|
||||||
self.set_functions[key](key, value)
|
self.set_functions[key](key, value)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
log.debug("Not set as value is same.")
|
log.debug("Not set because value is same.")
|
||||||
|
|
||||||
|
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
"""Get the value of 'key'. If it is an invalid key then get() will
|
"""Get the value of 'key'. If it is an invalid key then get() will
|
||||||
return None."""
|
return None."""
|
||||||
|
|
|
@ -58,7 +58,12 @@ DEFAULT_PREFS = {
|
||||||
"open_folder_location": "",
|
"open_folder_location": "",
|
||||||
"check_new_releases": False,
|
"check_new_releases": False,
|
||||||
"send_info": False,
|
"send_info": False,
|
||||||
"default_load_path": None
|
"default_load_path": None,
|
||||||
|
"window_maximized": False,
|
||||||
|
"window_x_pos": -1,
|
||||||
|
"window_y_pos": -1,
|
||||||
|
"window_width": -1,
|
||||||
|
"window_height": -1
|
||||||
}
|
}
|
||||||
|
|
||||||
class GtkUI:
|
class GtkUI:
|
||||||
|
|
|
@ -37,6 +37,7 @@ import gtk, gtk.glade
|
||||||
import gobject
|
import gobject
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
|
from deluge.configmanager import ConfigManager
|
||||||
from menubar import MenuBar
|
from menubar import MenuBar
|
||||||
from toolbar import ToolBar
|
from toolbar import ToolBar
|
||||||
from torrentview import TorrentView
|
from torrentview import TorrentView
|
||||||
|
@ -48,6 +49,7 @@ from deluge.log import LOG as log
|
||||||
|
|
||||||
class MainWindow:
|
class MainWindow:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.config = ConfigManager("gtkui.conf")
|
||||||
# Get the glade file for the main window
|
# Get the glade file for the main window
|
||||||
self.main_glade = gtk.glade.XML(
|
self.main_glade = gtk.glade.XML(
|
||||||
pkg_resources.resource_filename("deluge.ui.gtkui",
|
pkg_resources.resource_filename("deluge.ui.gtkui",
|
||||||
|
@ -55,6 +57,16 @@ class MainWindow:
|
||||||
|
|
||||||
self.window = self.main_glade.get_widget("main_window")
|
self.window = self.main_glade.get_widget("main_window")
|
||||||
self.window.set_icon(deluge.common.get_logo(32))
|
self.window.set_icon(deluge.common.get_logo(32))
|
||||||
|
# Load the window state
|
||||||
|
self.load_window_geometry()
|
||||||
|
|
||||||
|
# Keep track of window's minimization state so that we don't update the
|
||||||
|
# UI when it is minimized.
|
||||||
|
self.is_minimized = False
|
||||||
|
|
||||||
|
# Connect events
|
||||||
|
self.window.connect("window-state-event", self.window_state_event)
|
||||||
|
self.window.connect("configure-event", self.window_configure_event)
|
||||||
|
|
||||||
# Initialize various components of the gtkui
|
# Initialize various components of the gtkui
|
||||||
self.menubar = MenuBar(self)
|
self.menubar = MenuBar(self)
|
||||||
|
@ -66,6 +78,9 @@ class MainWindow:
|
||||||
gobject.timeout_add(1000, self.update)
|
gobject.timeout_add(1000, self.update)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
# Don't update the UI if the the window is minimized.
|
||||||
|
if self.is_minimized == True:
|
||||||
|
return True
|
||||||
self.torrentview.update()
|
self.torrentview.update()
|
||||||
self.torrentdetails.update()
|
self.torrentdetails.update()
|
||||||
return True
|
return True
|
||||||
|
@ -79,3 +94,37 @@ class MainWindow:
|
||||||
def quit(self):
|
def quit(self):
|
||||||
self.hide()
|
self.hide()
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
|
||||||
|
def load_window_geometry(self):
|
||||||
|
x = self.config["window_x_pos"]
|
||||||
|
y = self.config["window_y_pos"]
|
||||||
|
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"] == True:
|
||||||
|
self.window.maximize()
|
||||||
|
|
||||||
|
def window_configure_event(self, widget, event):
|
||||||
|
if self.config["window_maximized"] == False:
|
||||||
|
self.config.set("window_x_pos", self.window.get_position()[0])
|
||||||
|
self.config.set("window_y_pos", self.window.get_position()[1])
|
||||||
|
self.config.set("window_width", event.width)
|
||||||
|
self.config.set("window_height", event.height)
|
||||||
|
|
||||||
|
def window_state_event(self, widget, event):
|
||||||
|
if event.changed_mask & gtk.gdk.WINDOW_STATE_MAXIMIZED:
|
||||||
|
if event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED:
|
||||||
|
self.config.set("window_maximized", True)
|
||||||
|
else:
|
||||||
|
self.config.set("window_maximized", False)
|
||||||
|
if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED:
|
||||||
|
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
|
||||||
|
log.debug("MainWindow is minimized..")
|
||||||
|
self.is_minimized = True
|
||||||
|
else:
|
||||||
|
log.debug("MainWindow is not minimized..")
|
||||||
|
self.is_minimized = False
|
||||||
|
# Force UI update as we don't update it while minimized
|
||||||
|
self.update()
|
||||||
|
return False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue