From 973f6d43df2b90f7ca7bbbf966a407c0744d10c3 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 12 Apr 2008 05:05:19 -0700 Subject: [PATCH] qobserver: add_actions syntax sugar Signed-off-by: David Aguilar --- ugit/controllers/__init__.py | 19 ++++++++++++------- ugit/controllers/push.py | 2 +- ugit/controllers/repobrowser.py | 2 +- ugit/controllers/util.py | 12 ++++++------ ugit/models.py | 6 +++--- ugit/qobserver.py | 16 +++++++++++----- ugit/qtutils.py | 3 +-- 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/ugit/controllers/__init__.py b/ugit/controllers/__init__.py index df47994..5cc2ce8 100644 --- a/ugit/controllers/__init__.py +++ b/ugit/controllers/__init__.py @@ -14,14 +14,16 @@ from ugit import qtutils from ugit import defaults from ugit.qobserver import QObserver +from util import logger from push import push_branches from util import choose_branch from util import select_commits from util import search_revisions from util import update_options -from util import logger from repobrowser import browse_git_branch from createbranch import create_new_branch +from search import search_commits +import search class Controller(QObserver): """Controller manages the interaction between the model and views.""" @@ -53,10 +55,10 @@ class Controller(QObserver): self.add_observables('commitmsg', 'staged', 'unstaged') # When a model attribute changes, this runs a specific action - self.add_actions('staged', self.action_staged) - self.add_actions('unstaged', self.action_unstaged) - self.add_actions('global_ugit_fontdiff', self.update_diff_font) - self.add_actions('global_ugit_fontui', self.update_ui_font) + self.add_actions(staged = self.action_staged) + self.add_actions(unstaged = self.action_unstaged) + self.add_actions(global_ugit_fontdiff = self.update_diff_font) + self.add_actions(global_ugit_fontui = self.update_ui_font) self.add_callbacks( # Actions that delegate directly to the model @@ -98,7 +100,7 @@ class Controller(QObserver): # Seaarch Menu menu_search_revision = self.search_revision, - # menu_search_revision_range = self.search_revision_range, + menu_search_revision_range = self.search_revision_range, # menu_search_messages = self.search_messages, # menu_search_date = self.search_date, # menu_search_date_range = self.search_date_range, @@ -230,6 +232,9 @@ class Controller(QObserver): ##################################################################### # Qt callbacks + def search_revision_range(self): + search_commits(self.model, self.view, search.REVISION_RANGE) + def show_log(self, *rest): qtutils.toggle_log_window() @@ -717,7 +722,7 @@ class Controller(QObserver): # Recommend installing inotify if we're on Linux. self.inotify_thread = None try: - from inotify import GitNotifier + from ugit.inotify import GitNotifier qtutils.log(self.tr('inotify support: enabled')) except ImportError: import platform diff --git a/ugit/controllers/push.py b/ugit/controllers/push.py index 3d2f6d2..4010109 100644 --- a/ugit/controllers/push.py +++ b/ugit/controllers/push.py @@ -26,7 +26,7 @@ class PushController(QObserver): 'remote_branches', ) - self.add_actions('remotes', self.display_remotes) + self.add_actions(remotes = self.display_remotes) self.add_callbacks( remotes = self.update_remotes, local_branches = self.update_local_branches, diff --git a/ugit/controllers/repobrowser.py b/ugit/controllers/repobrowser.py index 26ae1a8..b73ca7e 100644 --- a/ugit/controllers/repobrowser.py +++ b/ugit/controllers/repobrowser.py @@ -25,7 +25,7 @@ class RepoBrowserController(QObserver): view.setWindowTitle('File Browser') self.add_signals('itemSelectionChanged()', view.commit_list,) - self.add_actions('directory', self.action_directory_changed) + self.add_actions(directory = self.action_directory_changed) self.add_callbacks(commit_list = self.item_changed) self.connect( view.commit_list, diff --git a/ugit/controllers/util.py b/ugit/controllers/util.py index d194e4c..092acf8 100644 --- a/ugit/controllers/util.py +++ b/ugit/controllers/util.py @@ -88,7 +88,7 @@ class SearchRevisionsController(QObserver): set_diff_font(model, self.view.commit_text) self.add_observables('revision') - self.add_actions('revision', self.search_revisions) + self.add_actions(revision = self.search_revisions) self.connect(view.commit_list, 'itemSelectionChanged()', self.select_summary) self.connect(view.commit_text, 'cursorPositionChanged()', @@ -204,10 +204,10 @@ class OptionsController(QObserver): 'global_ugit_savewindowsettings', 'global_ugit_saveatexit', ) - self.add_actions('global_ugit_fontdiff_size', self.update_size) - self.add_actions('global_ugit_fontui_size', self.update_size) - self.add_actions('global_ugit_fontdiff', self.tell_parent_model) - self.add_actions('global_ugit_fontui', self.tell_parent_model) + self.add_actions(global_ugit_fontdiff_size = self.update_size) + self.add_actions(global_ugit_fontui_size = self.update_size) + self.add_actions(global_ugit_fontdiff = self.tell_parent_model) + self.add_actions(global_ugit_fontui = self.tell_parent_model) self.add_callbacks(save_button = self.save_settings) self.connect(self.view, 'rejected()', self.restore_settings) @@ -296,7 +296,7 @@ class LogController(QObserver): QObserver.__init__(self, model, view) self.add_observables('search_text') - self.add_actions('search_text', self.insta_search) + self.add_actions(search_text = self.insta_search) self.add_callbacks( clear_button = self.clear, next_button = self.next, diff --git a/ugit/models.py b/ugit/models.py index bea8dea..2a46b6f 100644 --- a/ugit/models.py +++ b/ugit/models.py @@ -1,9 +1,9 @@ import os import re -import git -import utils -import model +from ugit import git +from ugit import utils +from ugit import model class Model(model.Model): """Provides a friendly wrapper for doing commit git operations.""" diff --git a/ugit/qobserver.py b/ugit/qobserver.py index 9e1ca54..c49c70a 100644 --- a/ugit/qobserver.py +++ b/ugit/qobserver.py @@ -12,7 +12,7 @@ from PyQt4.QtGui import QAbstractButton from PyQt4.QtGui import QSplitter from PyQt4.QtGui import QAction -from observer import Observer +from ugit.observer import Observer class QObserver(Observer, QObject): @@ -138,10 +138,14 @@ class QObserver(Observer, QObject): "%s => %s" %( type(widget), str(widget.objectName()) )) - def add_actions(self, model_param, callback): + def add_actions(self, **kwargs): '''Register view actions that are called in response to view changes.(view->model)''' - self.__actions[model_param] = callback + for model_param, callback in kwargs.iteritems(): + if type(callback) is list: + self.__actions[model_param] = callback + else: + self.__actions[model_param] = [callback] def subject_changed(self, param, value): '''Sends a model param to the view(model->view)''' @@ -172,13 +176,15 @@ class QObserver(Observer, QObject): widget_name, widget, value) self.model.set_notify(notify) - if param not in self.__actions: return + if param not in self.__actions: + return widgets = [] if param in self.__model_to_view: for widget in self.__model_to_view[param]: widgets.append(widget) # Call the model callback w/ the view's widgets as the args - self.__actions[param](*widgets) + for action in self.__actions[param]: + action(*widgets) def refresh_view(self, *params): if not params: diff --git a/ugit/qtutils.py b/ugit/qtutils.py index d9116d8..d623821 100644 --- a/ugit/qtutils.py +++ b/ugit/qtutils.py @@ -7,8 +7,7 @@ from PyQt4.QtGui import QIcon from PyQt4.QtGui import QListWidgetItem from PyQt4.QtGui import QMessageBox -import views -import utils +from ugit import utils LOGGER = None -- 2.11.4.GIT