From 7a71feea5ae11c33eaced1a1e937874f2cb3411b Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 29 Dec 2007 02:57:42 -0800 Subject: [PATCH] Renamed classes to remove unnecessary prefix. Signed-off by: David Aguilar --- bin/ugit.py | 12 +++---- ugitlibs/cmds.py | 2 +- ugitlibs/controllers.py | 74 +++++++++++++++----------------------- ugitlibs/createbranchcontroller.py | 2 +- ugitlibs/model.py | 2 +- ugitlibs/models.py | 9 +++-- ugitlibs/pushcontroller.py | 2 +- ugitlibs/qtutils.py | 21 +++++++++-- ugitlibs/repobrowsercontroller.py | 5 ++- ugitlibs/syntax.py | 4 +-- ugitlibs/views.py | 26 ++++++++------ 11 files changed, 81 insertions(+), 78 deletions(-) diff --git a/bin/ugit.py b/bin/ugit.py index 2a1109e..50f243c 100755 --- a/bin/ugit.py +++ b/bin/ugit.py @@ -17,9 +17,9 @@ sys.path.insert(0, os.path.join( 'site-packages')) sys.path.insert(0, os.path.dirname(ugit)) -from ugitlibs.models import GitModel -from ugitlibs.views import GitView -from ugitlibs.controllers import GitController +from ugitlibs.models import Model +from ugitlibs.views import View +from ugitlibs.controllers import Controller from ugitlibs import utils if __name__ == "__main__": @@ -30,8 +30,8 @@ if __name__ == "__main__": translator = QtCore.QTranslator() translator.load(qmfile) app.installTranslator(translator) - model = GitModel() - view = GitView(app.activeWindow()) - ctl = GitController(model, view) + model = Model() + view = View(app.activeWindow()) + ctl = Controller(model, view) view.show() sys.exit(app.exec_()) diff --git a/ugitlibs/cmds.py b/ugitlibs/cmds.py index 2bab4dc..ff6bb2b 100644 --- a/ugitlibs/cmds.py +++ b/ugitlibs/cmds.py @@ -38,7 +38,7 @@ def run_cmd(cmd, *args, **kwargs): # Allow run_cmd(argv, raw=True) for when we # want the full, raw output(e.g. git cat-file) - if 'raw' in kwargs and kwargs['raw']: + if 'raw' in kwargs: return output else: if 'with_status' in kwargs: diff --git a/ugitlibs/controllers.py b/ugitlibs/controllers.py index bfdb7a0..572feed 100644 --- a/ugitlibs/controllers.py +++ b/ugitlibs/controllers.py @@ -11,15 +11,15 @@ import cmds import utils import qtutils import defaults -from views import GitPushDialog -from views import GitBranchDialog -from views import GitCreateBranchDialog -from views import GitCommitBrowser -from repobrowsercontroller import GitRepoBrowserController -from createbranchcontroller import GitCreateBranchController -from pushcontroller import GitPushController - -class GitController(QObserver): +from views import PushDialog +from views import BranchDialog +from views import CreateBranchDialog +from views import CommitBrowser +from repobrowsercontroller import RepoBrowserController +from createbranchcontroller import CreateBranchController +from pushcontroller import PushController + +class Controller(QObserver): '''The controller is a mediator between the model and view. It allows for a clean decoupling between view and model classes.''' @@ -180,16 +180,15 @@ class GitController(QObserver): # Qt callbacks def branch_create(self): - view = GitCreateBranchDialog(self.view) - controller = GitCreateBranchController(self.model, view) + view = CreateBranchDialog(self.view) + controller = CreateBranchController(self.model, view) view.show() result = view.exec_() - if result == QDialog.Accepted: - self.rescan() + if result == QDialog.Accepted: self.rescan() def branch_delete(self): - dlg = GitBranchDialog(self.view, branches=cmds.git_branch()) - branch = dlg.getSelectedBranch() + branch = BranchDialog.choose('Delete Branch', + self.view, self.model.get_local_branches()) if not branch: return qtutils.show_command(self.view, cmds.git_branch(name=branch, delete=True)) @@ -199,15 +198,15 @@ class GitController(QObserver): def browse_other(self): # Prompt for a branch to browse - branches = self.model.all_branches() - dialog = GitBranchDialog(self.view, branches=branches) - + branch = BranchDialog.choose('Browse Branch Files', + self.view, self.model.get_all_branches()) + if not branch: return # Launch the repobrowser - self.__browse_branch(dialog.getSelectedBranch()) + self.__browse_branch(branch) def checkout_branch(self): - dlg = GitBranchDialog(self.view, cmds.git_branch()) - branch = dlg.getSelectedBranch() + branch = BranchDialog.choose('Checkout Branch', + self.view, self.model.get_local_branches()) if not branch: return qtutils.show_command(self.view, cmds.git_checkout(branch)) self.rescan() @@ -384,8 +383,7 @@ class GitController(QObserver): def load_commitmsg(self): file = qtutils.open_dialog(self.view, - self.tr('Load Commit Message...'), - defaults.DIRECTORY) + 'Load Commit Message...', defaults.DIRECTORY) if file: defaults.DIRECTORY = os.path.dirname(file) @@ -393,9 +391,8 @@ class GitController(QObserver): self.model.set_commitmsg(slushy) def rebase(self): - dlg = GitBranchDialog(self.view, cmds.git_branch()) - dlg.setWindowTitle("Select the current branch's new root") - branch = dlg.getSelectedBranch() + branch = BranchDialog.choose('Rebase Branch', + self.view, self.model.get_local_branches()) if not branch: return qtutils.show_command(self.view, cmds.git_rebase(branch)) @@ -427,8 +424,8 @@ class GitController(QObserver): def push(self): model = self.model.clone() - view = GitPushDialog(self.view) - controller = GitPushController(model,view) + view = PushDialog(self.view) + controller = PushController(model,view) view.show() view.exec_() @@ -619,8 +616,8 @@ class GitController(QObserver): # with different sets of data model = self.model.clone() model.set_branch(branch) - view = GitCommitBrowser() - controller = GitRepoBrowserController(model, view) + view = CommitBrowser() + controller = RepoBrowserController(model, view) view.show() view.exec_() @@ -680,19 +677,6 @@ class GitController(QObserver): self.connect(self.__menu, 'aboutToShow()', self.__menu_about_to_show) - def __file_to_widget_item(self, filename, staged, untracked=False): - '''Given a filename, return a QListWidgetItem suitable - for adding to a QListWidget. "staged" controls whether - to use icons for the staged or unstaged list widget.''' - if staged: - icon_file = utils.get_staged_icon(filename) - elif untracked: - icon_file = utils.get_untracked_icon() - else: - icon_file = utils.get_icon(filename) - - return qtutils.create_listwidget_item(filename, icon_file) - def __read_config_settings(self): (w,h,x,y, st0,st1, @@ -708,7 +692,7 @@ class GitController(QObserver): def __select_commits(self, revs, summaries): '''Use the GitCommitBrowser to select commits from a list.''' if not summaries: - msg = self.tr('ERROR: No commits exist in this branch.') + msg = self.tr('No commits exist in this branch.') self.__show_command(msg) return([],[]) @@ -795,5 +779,5 @@ class GitController(QObserver): '''Populate a QListWidget with the custom icon items.''' if not append: widget.clear() qtutils.add_items( widget, - [ self.__file_to_widget_item(i, staged, untracked) + [ qtutils.create_item(i, staged, untracked) for i in items ]) diff --git a/ugitlibs/createbranchcontroller.py b/ugitlibs/createbranchcontroller.py index d19dcca..faab226 100644 --- a/ugitlibs/createbranchcontroller.py +++ b/ugitlibs/createbranchcontroller.py @@ -5,7 +5,7 @@ import utils import qtutils from qobserver import QObserver -class GitCreateBranchController(QObserver): +class CreateBranchController(QObserver): def __init__(self, model, view): QObserver.__init__(self, model, view) diff --git a/ugitlibs/model.py b/ugitlibs/model.py index 02ea929..99e13d6 100644 --- a/ugitlibs/model.py +++ b/ugitlibs/model.py @@ -49,7 +49,7 @@ class Model(Observable): self.__object_attrs = {} def create(self,**kwargs): - self.from_dict(kwargs) + return self.from_dict(kwargs) def clone(self): return self.__class__().from_dict(self.to_dict()) diff --git a/ugitlibs/models.py b/ugitlibs/models.py index 24bfa47..8d676dc 100644 --- a/ugitlibs/models.py +++ b/ugitlibs/models.py @@ -3,11 +3,11 @@ import re import commands import cmds import utils -from model import Model +import model -class GitModel(Model): +class Model(model.Model): def __init__(self): - Model.__init__(self) + model.Model.__init__(self) # chdir to the root of the git tree. This is critical # to being able to properly use the git porcelain. @@ -59,9 +59,8 @@ class GitModel(Model): subtree_sha1s = [], subtree_names = [], ) - - def all_branches(self): + def get_all_branches(self): return (self.get_local_branches() + self.get_remote_branches()) def init_branch_data(self): diff --git a/ugitlibs/pushcontroller.py b/ugitlibs/pushcontroller.py index 1c667f5..5c02821 100644 --- a/ugitlibs/pushcontroller.py +++ b/ugitlibs/pushcontroller.py @@ -5,7 +5,7 @@ import cmds import utils import qtutils -class GitPushController(QObserver): +class PushController(QObserver): def __init__(self, model, view): QObserver.__init__(self,model,view) diff --git a/ugitlibs/qtutils.py b/ugitlibs/qtutils.py index 6f01b05..4e31441 100644 --- a/ugitlibs/qtutils.py +++ b/ugitlibs/qtutils.py @@ -6,7 +6,9 @@ from PyQt4.QtGui import QIcon from PyQt4.QtGui import QListWidgetItem from PyQt4.QtGui import QMessageBox from PyQt4.QtGui import QPixmap + import views +import utils def create_listwidget_item(text, filename): icon = QIcon(QPixmap(filename)) @@ -44,12 +46,12 @@ def get_selected_item(list_widget, items): def open_dialog(parent, title, filename=None): qstr = QFileDialog.getOpenFileName( - parent, title, filename) + parent, parent.tr(title), filename) return unicode(qstr) def save_dialog(parent, title, filename=None): qstr = QFileDialog.getSaveFileName( - parent, title, filename) + parent, parent.tr(title), filename) return unicode(qstr) def dir_dialog(parent, title, directory): @@ -86,7 +88,7 @@ def set_items(widget, items): def show_command(parent, output): if not output: return - dialog = views.GitCommandDialog(parent, output=output) + dialog = views.CommandDialog(parent, output=output) dialog.show() dialog.exec_() @@ -97,3 +99,16 @@ def tr(txt): if trtext.endswith('@@noun'): trtext = trtext.replace('@@noun','') return trtext + +def create_item(filename, staged, untracked=False): + '''Given a filename, return a QListWidgetItem suitable + for adding to a QListWidget. "staged" controls whether + to use icons for the staged or unstaged list widget.''' + if staged: + icon_file = utils.get_staged_icon(filename) + elif untracked: + icon_file = utils.get_untracked_icon() + else: + icon_file = utils.get_icon(filename) + + return create_listwidget_item(filename, icon_file) diff --git a/ugitlibs/repobrowsercontroller.py b/ugitlibs/repobrowsercontroller.py index 642b3ae..2791f8b 100644 --- a/ugitlibs/repobrowsercontroller.py +++ b/ugitlibs/repobrowsercontroller.py @@ -6,7 +6,7 @@ import utils import qtutils import defaults -class GitRepoBrowserController(QObserver): +class RepoBrowserController(QObserver): def __init__(self, model, view): QObserver.__init__(self, model, view) @@ -108,8 +108,7 @@ class GitRepoBrowserController(QObserver): nameguess = os.path.join(defaults.DIRECTORY, name) - filename = qtutils.save_dialog(self.view, - self.tr('Save'), nameguess) + filename = qtutils.save_dialog(self.view, 'Save', nameguess) if not filename: return defaults.DIRECTORY = os.path.dirname(filename) diff --git a/ugitlibs/syntax.py b/ugitlibs/syntax.py index 311aaf8..4e4b502 100755 --- a/ugitlibs/syntax.py +++ b/ugitlibs/syntax.py @@ -5,7 +5,7 @@ from PyQt4.QtGui import QFont from PyQt4.QtGui import QSyntaxHighlighter from PyQt4.QtGui import QTextCharFormat -class GitSyntaxHighlighter(QSyntaxHighlighter): +class DiffSyntaxHighlighter(QSyntaxHighlighter): def __init__(self, doc): QSyntaxHighlighter.__init__(self, doc) @@ -80,7 +80,7 @@ if __name__ == '__main__': #self.commandText.setReadOnly(True) self.vboxlayout.addWidget(self.commandText) - GitSyntaxHighlighter(self.commandText.document()) + DiffSyntaxHighlighter(self.commandText.document()) app = QtGui.QApplication(sys.argv) diff --git a/ugitlibs/views.py b/ugitlibs/views.py index 313b874..a0c1a26 100644 --- a/ugitlibs/views.py +++ b/ugitlibs/views.py @@ -7,21 +7,21 @@ from CommitBrowser import Ui_CommitBrowser from BranchDialog import Ui_BranchDialog from CreateBranchDialog import Ui_CreateBranchDialog from PushDialog import Ui_PushDialog -from syntax import GitSyntaxHighlighter +from syntax import DiffSyntaxHighlighter import qtutils -class GitView(Ui_Window, QtGui.QMainWindow): +class View(Ui_Window, QtGui.QMainWindow): '''The main ugit interface.''' def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) Ui_Window.__init__(self) self.setupUi(self) - GitSyntaxHighlighter(self.displayText.document()) + DiffSyntaxHighlighter(self.displayText.document()) # Qt does not handle noun/verb support self.commitButton.setText(qtutils.tr('Commit@@verb')) self.menuCommit.setTitle(qtutils.tr('Commit@@verb')) -class GitCommandDialog(Ui_CommandDialog, QtGui.QDialog): +class CommandDialog(Ui_CommandDialog, QtGui.QDialog): '''A simple dialog to display command output.''' def __init__(self, parent=None, output=None): QtGui.QDialog.__init__(self, parent) @@ -32,9 +32,9 @@ class GitCommandDialog(Ui_CommandDialog, QtGui.QDialog): def set_command(self, output): self.commandText.setText(output) -class GitBranchDialog(Ui_BranchDialog, QtGui.QDialog): +class BranchDialog(Ui_BranchDialog, QtGui.QDialog): '''A dialog to display available branches.''' - def __init__(self, parent=None, branches=None): + def __init__(self, parent, branches): QtGui.QDialog.__init__(self, parent) Ui_BranchDialog.__init__(self) self.setupUi(self) @@ -57,7 +57,13 @@ class GitBranchDialog(Ui_BranchDialog, QtGui.QDialog): else: return None -class GitCommitBrowser(Ui_CommitBrowser, QtGui.QDialog): + @staticmethod + def choose(title, parent, branches): + dlg = BranchDialog(parent,branches) + dlg.setWindowTitle(dlg.tr(title)) + return dlg.getSelectedBranch() + +class CommitBrowser(Ui_CommitBrowser, QtGui.QDialog): '''A dialog to display commits in for selection.''' def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) @@ -65,16 +71,16 @@ class GitCommitBrowser(Ui_CommitBrowser, QtGui.QDialog): self.setupUi(self) # Make the list widget slighty larger self.splitter.setSizes([ 50, 200 ]) - GitSyntaxHighlighter(self.commitText.document()) + DiffSyntaxHighlighter(self.commitText.document()) -class GitCreateBranchDialog(Ui_CreateBranchDialog, QtGui.QDialog): +class CreateBranchDialog(Ui_CreateBranchDialog, QtGui.QDialog): '''A dialog for creating or updating branches.''' def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) Ui_CreateBranchDialog.__init__(self) self.setupUi(self) -class GitPushDialog(Ui_PushDialog, QtGui.QDialog): +class PushDialog(Ui_PushDialog, QtGui.QDialog): '''A dialog for pushing branches.''' def __init__(self, parent=None): QtGui.QDialog.__init__(self, parent) -- 2.11.4.GIT