[kupfer] Store position for the main window



commit 9c627a093341bbe07f44a0e8abf4f7a806b967e9
Author: Ulrik Sverdrup <f04us lo-9 student lth se>
Date:   Thu May 6 11:24:25 2010 +0200

    Store position for the main window
    
    Keep track of the main window's position of all time. Window positions
    are tracked in regular config at this time.
    
    Since we restore the window position at all times, we don't need the
    dance of hiding the third pane on put_away and showing it again on
    focus.
    
    Touches bugs:
    
    Window manager moves window on hide/show cycle:
    https://bugs.launchpad.net/kupfer/+bug/417278
    
    Irregular window blanking:
    https://bugs.launchpad.net/kupfer/+bug/494237
    
    Wishlist: Store window position
    https://bugs.launchpad.net/kupfer/+bug/544908

 kupfer/core/settings.py |   18 ++++++++++++++++++
 kupfer/ui/browser.py    |   30 +++++++++++++++++++++++++-----
 2 files changed, 43 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/core/settings.py b/kupfer/core/settings.py
index 9165e23..6d8b24d 100644
--- a/kupfer/core/settings.py
+++ b/kupfer/core/settings.py
@@ -1,5 +1,6 @@
 from __future__ import with_statement
 
+import ast
 import os, sys
 import ConfigParser
 import copy
@@ -40,6 +41,9 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 		"Directories" : { "direct" : default_directories, "catalog" : (), },
 		"DeepDirectories" : { "direct" : (), "catalog" : (), "depth" : 1, },
 		'Keybindings': {},
+		"SessionPositions" : {
+			"main": "",
+		}
 	}
 	def __init__(self):
 		gobject.GObject.__init__(self)
@@ -295,6 +299,20 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
 	def set_directories(self, dirs):
 		return self._set_config("Directories", "direct", dirs)
 
+	def get_session_position(self, key, default=(-1, -1)):
+		"get ui object position for @key"
+		posstr = self.get_config("SessionPositions", key)
+		try:
+			x, y = ast.literal_eval(posstr)
+		except (SyntaxError, ValueError):
+			return default
+		return x, y
+
+	def set_session_position(self, key, value):
+		"set a ui object position key (x, y) pair"
+		x, y = value
+		self._set_config("SessionPositions", key, repr((x,y)))
+
 	def get_plugin_config(self, plugin, key, value_type=str, default=None):
 		"""Return setting @key for plugin names @plugin, try
 		to coerce to type @value_type.
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 42b4d2a..f3a6f63 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -1193,16 +1193,12 @@ class Interface (gobject.GObject):
 			self.switch_to_source()
 		# Check that items are still valid when "coming back"
 		self.data_controller.validate()
-		if self._pane_three_is_visible:
-			self._ui_transition_timer.set_ms(200, self._show_third_pane, True)
 
 	def put_away(self):
 		"""Called when the interface is hidden"""
 		self._relax_search_terms()
 		self._reset_to_toplevel = True
-		if self._pane_three_is_visible:
-			self._show_third_pane(False)
-		self._ui_transition_timer.invalidate()
+		# no hide / show pane three on put away -> focus anymore
 
 	def select_selected_file(self):
 		# Add optional lookup data to narrow the search
@@ -1408,6 +1404,7 @@ class WindowController (pretty.OutputMixin):
 		"""
 		"""
 		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+		self.window_position = -1, -1
 
 		data_controller = data.DataController()
 		data_controller.connect("launched-action", self.launch_callback)
@@ -1463,6 +1460,7 @@ class WindowController (pretty.OutputMixin):
 		"""
 
 		self.window.connect("delete-event", self._close_window)
+		self.window.connect("configure-event", self._window_frame_event)
 		widget = self.interface.get_widget()
 		widget.show()
 
@@ -1494,7 +1492,27 @@ class WindowController (pretty.OutputMixin):
 	def result_callback(self, sender, result_type):
 		self.activate()
 
+	def _load_window_position(self):
+		setctl = settings.GetSettingsController()
+		self.window_position = setctl.get_session_position("main")
+
+	def _window_frame_event(self, window, event):
+		# save most recent window position
+		window_pos = self.window.get_position()
+		if (self.window.get_property("visible") and
+		    window_pos != self.window_position):
+			self.window_position = self.window.get_position()
+			setctl = settings.GetSettingsController()
+			setctl.set_session_position("main", self.window_position)
+
+	def _move_window_to_position(self):
+		pos = self.window.get_position()
+		if self.window_position[0] > 0 and pos != self.window_position:
+			self.window.move(*self.window_position)
+			self.output_debug("Moving window to", self.window_position)
+
 	def activate(self, sender=None, time=0):
+		self._move_window_to_position()
 		if not time:
 			time = (gtk.get_current_event_time() or
 			        keybindings.get_current_event_time())
@@ -1502,6 +1520,7 @@ class WindowController (pretty.OutputMixin):
 		self.window.present_with_time(time)
 		self.window.window.focus(timestamp=time)
 		self.interface.focus()
+		self._move_window_to_position()
 
 	def put_away(self):
 		self.interface.put_away()
@@ -1646,6 +1665,7 @@ class WindowController (pretty.OutputMixin):
 		# Load data and present UI
 		sch = scheduler.GetScheduler()
 		sch.load()
+		self._load_window_position()
 
 		if not quiet:
 			self.activate()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]