Permalink
Browse files

gui: fix the gui settings save/restore

The defaults module was removed in the process of refactoring the gui
settings save/restore functionality.

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
1 parent 72cdd4a commit 3d0c28af19ce1a2872af9bbcf2594582e99571c4 @davvid davvid committed Nov 18, 2008
Showing with 55 additions and 65 deletions.
  1. +2 −4 cola/controllers/repobrowser.py
  2. +0 −14 cola/defaults.py
  3. +29 −13 cola/inotify.py
  4. +22 −3 cola/models.py
  5. +2 −30 cola/utils.py
  6. +0 −1 test/test_moduleimport.py
@@ -7,7 +7,6 @@
from cola import utils
from cola import qtutils
-from cola import defaults
from cola.views import CommitView
from cola.qobserver import QObserver
@@ -135,12 +134,11 @@ def commit_list_doubleclick(self,*rest):
self.view.accept()
return
- nameguess = os.path.join(defaults.DIRECTORY, name)
-
+ nameguess = os.path.join(self.model.get_directory(), name)
filename = qtutils.save_dialog(self.view, 'Save', nameguess)
if not filename:
return
- defaults.DIRECTORY = os.path.dirname(filename)
+ self.model.set_directory(os.path.dirname(filename))
contents = self.model.git.cat_file(objtype, sha1,
with_raw_output=True)
utils.write(filename, contents)
View
@@ -1,14 +0,0 @@
-#!/usr/bin/env python
-# Copyright (c) 2008 David Aguilar
-
-import os
-from PyQt4.QtCore import QEvent
-
-INOTIFY_EVENT = QEvent.User + 0
-DIRECTORY = os.getcwd()
-
-WIDTH = 780
-HEIGHT = 600
-
-X = 262
-Y = 254
View
@@ -14,51 +14,67 @@
from pyinotify import ProcessEvent
from pyinotify import WatchManager, Notifier, EventsCodes
-import defaults
+INOTIFY_EVENT_TYPE = QEvent.User + 0
class FileSysEvent(ProcessEvent):
+ """FileSysEvents are generated by the GitNotifier thread
+ and represent the inotify events.
+ """
def __init__(self, parent):
+ """FileSysEvent keeps a reference to the Qt parent and remembers
+ the last event time to avoid event floods.
+ """
ProcessEvent.__init__(self)
self.parent = parent
self.last_event_time = time.time()
def process_default(self, event):
+ """Notifies the Qt parent when actions occur."""
# Prevent notificaiton floods
if time.time() - self.last_event_time > 1.0:
self.parent.notify()
self.last_event_time = time.time()
class GitNotifier(QThread):
+ """This polls inotify for changes and generates FileSysEvents
+ in response to updates.
+ """
def __init__(self, receiver, git):
QThread.__init__(self)
- self.receiver = receiver
- self.git = git
- self.path = git.get_work_tree()
- self.abort = False
- self.dirs_seen = {}
- self.mask = (EventsCodes.IN_CREATE |
- EventsCodes.IN_DELETE |
- EventsCodes.IN_MODIFY |
- EventsCodes.IN_MOVED_TO)
+ self.receiver = receiver #: The Qt receiver of the event
+ self.git = git # A: git command object
+ self.path = git.get_work_tree() #: Path to monitor
+ self.abort = False #: Whether to abort (using during destruction)
+ self.dirs_seen = {} #: Directories we're watching
+ #: Events we capture
+ self.mask = (EventsCodes.IN_CREATE | EventsCodes.IN_DELETE |
+ EventsCodes.IN_MODIFY | EventsCodes.IN_MOVED_TO)
def notify(self):
+ """Posts a Qt event in response to inotify updates.
+ """
if not self.abort:
- event_type = QEvent.Type(defaults.INOTIFY_EVENT)
+ event_type = QEvent.Type(INOTIFY_EVENT_TYPE)
event = QEvent(event_type)
QCoreApplication.postEvent(self.receiver, event)
def watch_directory(self, directory):
+ """Sets up a directory for monitoring by inotify.
+ """
directory = os.path.realpath(directory)
if directory not in self.dirs_seen:
self.wm.add_watch(directory, self.mask)
self.dirs_seen[directory] = True
-
+
def run(self):
+ """This creates the inotify WatchManager and generates
+ FileSysEvents."""
# Only capture those events that git cares about
self.wm = WatchManager()
notifier = Notifier(self.wm, FileSysEvent(self))
- self.notifier = notifier
dirs_seen = {}
added_flag = False
+ # self.abort signals app termination. The timeout is a tradeoff
+ # between fast notification response and waiting too long to exit.
while not self.abort:
if not added_flag:
self.watch_directory(self.path)
View
@@ -134,6 +134,7 @@ def init(self):
#####################################################
# Used in various places
currentbranch = '',
+ directory = '',
remotes = [],
remotename = '',
local_branch = '',
@@ -158,7 +159,6 @@ def init(self):
#####################################################
# Used by the commit/repo browser
- directory = '',
revisions = [],
summaries = [],
@@ -613,8 +613,27 @@ def stage_all(self):
self.update_status()
return output
- def save_gui_settings(self):
- self.config_set('cola.geometry', utils.get_geom(), local=False)
+ def get_window_geom(self):
+ return self.parse_geom_str(self.get_cola_config('geometry'))
+
+ def set_window_geom(self, w, h, x, y):
+ self._w = w
+ self._h = h
+ self._x = x
+ self._y = y
+ self.config_set('cola.geometry', '%dx%d+%d,%d' % self.window_geom(),
+ local=False)
+
+ def window_geom(self):
+ return (self._w, self._h, self._x, self._y)
+
+ def parse_geom_str(self, geomstr):
+ regex = re.compile('^(\d+)x(\d+)\+(\d+),(\d+).*?')
+ match = regex.match(geomstr)
+ if match:
+ self.set_window_geom(int(match.group(1)), int(match.group(2)),
+ int(match.group(3)), int(match.group(4)))
+ return self.window_geom()
def config_set(self, key=None, value=None, local=True):
if key and value is not None:
View
@@ -10,7 +10,6 @@
from glob import glob
from cStringIO import StringIO
-from cola import defaults
from cola import git
from cola.git import shell_quote
from cola.core import encode, decode
@@ -132,7 +131,8 @@ def grep(pattern, items, squash=True):
matchdict = {}
for item in items:
match = regex.match(item)
- if not match: continue
+ if not match:
+ continue
groups = match.groups()
if not groups:
subitems = match.group(0)
@@ -166,34 +166,6 @@ def basename(path):
else:
return pathstr
-HEADER_LENGTH = 80
-def header(msg):
- pad = HEADER_LENGTH - len(msg) - 4 # len(':+') + len('+:')
- extra = pad % 2
- pad /= 2
- return(':+'
- +(' ' * pad)
- + msg
- +(' ' * (pad + extra))
- + '+:'
- + '\n')
-
-def parse_geom(geomstr):
- regex = re.compile('^(\d+)x(\d+)\+(\d+),(\d+).*?')
- match = regex.match(geomstr)
- if match:
- defaults.WIDTH = int(match.group(1))
- defaults.HEIGHT = int(match.group(2))
- defaults.X = int(match.group(3))
- defaults.Y = int(match.group(4))
- return (defaults.WIDTH, defaults.HEIGHT, defaults.X, defaults.Y)
-
-def get_geom():
- return ('%dx%d+%d,%d'
- % (defaults.WIDTH, defaults.HEIGHT, defaults.X, defaults.Y))
-
-def project_name():
- return os.path.basename(defaults.DIRECTORY)
def slurp(path):
"""Slurps a filepath into a string."""
@@ -27,7 +27,6 @@ def __create_tests():
cola.model
cola.observer
cola.exception
- cola.defaults
cola.settings
""".split():
setattr(ImportTest,

0 comments on commit 3d0c28a

Please sign in to comment.