Rev 175: Minor refactoring of __init__ to have less duplication. in file:///home/robertc/source/baz/plugins/gtk/fixen/
Robert Collins
robertc at robertcollins.net
Fri Mar 23 09:48:54 GMT 2007
At file:///home/robertc/source/baz/plugins/gtk/fixen/
------------------------------------------------------------
revno: 175
revision-id: robertc at robertcollins.net-20070323094853-zxab7td0348656te
parent: abentley at panoramicfeedback.com-20070319140443-nimeomjezt1nzf0h
committer: Robert Collins <robertc at robertcollins.net>
branch nick: fixen
timestamp: Fri 2007-03-23 20:48:53 +1100
message:
Minor refactoring of __init__ to have less duplication.
modified:
__init__.py __init__.py-20060519165329-a1fd52c8a829fcd5
=== modified file '__init__.py'
--- a/__init__.py 2007-03-17 23:58:03 +0000
+++ b/__init__.py 2007-03-23 09:48:53 +0000
@@ -89,49 +89,49 @@
bzrlib.ui.ui_factory = GtkUIFactory()
-class cmd_gbranch(Command):
+class GTKCommand(Command):
+ """Abstract class providing GTK specific run commands."""
+
+ def open_display(self):
+ pygtk = import_pygtk()
+ try:
+ import gtk
+ except RuntimeError, e:
+ if str(e) == "could not open display":
+ raise NoDisplayError
+ set_ui_factory()
+
+ def run(self):
+ self.open_display()
+ dialog = self.get_gtk_dialog(os.path.abspath('.'))
+ dialog.run()
+
+
+class cmd_gbranch(GTKCommand):
"""GTK+ branching.
"""
- def run(self):
- pygtk = import_pygtk()
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
+ def get_gtk_dialog(self, path):
from bzrlib.plugins.gtk.branch import BranchDialog
+ return BranchDialog(path)
- set_ui_factory()
- dialog = BranchDialog(os.path.abspath('.'))
- dialog.run()
register_command(cmd_gbranch)
-class cmd_gcheckout(Command):
+class cmd_gcheckout(GTKCommand):
""" GTK+ checkout.
"""
- def run(self):
- pygtk = import_pygtk()
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
+ def get_gtk_dialog(self, path):
from bzrlib.plugins.gtk.checkout import CheckoutDialog
-
- set_ui_factory()
- dialog = CheckoutDialog(os.path.abspath('.'))
- dialog.run()
+ return CheckoutDialog(path)
register_command(cmd_gcheckout)
-class cmd_gpush(Command):
+
+class cmd_gpush(GTKCommand):
""" GTK+ push.
"""
@@ -139,23 +139,15 @@
def run(self, location="."):
(br, path) = branch.Branch.open_containing(location)
-
- pygtk = import_pygtk()
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
+ self.open_display()
from push import PushDialog
-
- set_ui_factory()
dialog = PushDialog(br)
dialog.run()
register_command(cmd_gpush)
-class cmd_gdiff(Command):
+
+class cmd_gdiff(GTKCommand):
"""Show differences in working tree in a GTK+ Window.
Otherwise, all changes for the tree are listed.
@@ -251,7 +243,8 @@
register_command(cmd_visualise)
-class cmd_gannotate(Command):
+
+class cmd_gannotate(GTKCommand):
"""GTK+ annotate.
Browse changes to FILENAME line by line in a GTK+ window.
@@ -268,14 +261,7 @@
aliases = ["gblame", "gpraise"]
def run(self, filename, all=False, plain=False, line='1', revision=None):
- pygtk = import_pygtk()
-
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
- set_ui_factory()
+ self.open_display()
try:
line = int(line)
@@ -323,7 +309,8 @@
register_command(cmd_gannotate)
-class cmd_gcommit(Command):
+
+class cmd_gcommit(GTKCommand):
"""GTK+ commit dialog
Graphical user interface for committing revisions"""
@@ -334,15 +321,7 @@
def run(self, filename=None):
import os
- pygtk = import_pygtk()
-
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
- set_ui_factory()
+ self.open_display()
from commit import CommitDialog
from bzrlib.commit import Commit
from bzrlib.errors import (BzrCommandError,
@@ -372,7 +351,8 @@
register_command(cmd_gcommit)
-class cmd_gstatus(Command):
+
+class cmd_gstatus(GTKCommand):
"""GTK+ status dialog
Graphical user interface for showing status
@@ -384,15 +364,7 @@
def run(self, path='.'):
import os
- pygtk = import_pygtk()
-
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
- set_ui_factory()
+ self.open_display()
from status import StatusDialog
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
status = StatusDialog(wt, wt_path)
@@ -401,57 +373,45 @@
register_command(cmd_gstatus)
-class cmd_gconflicts(Command):
+
+class cmd_gconflicts(GTKCommand):
""" GTK+ push.
"""
def run(self):
(wt, path) = workingtree.WorkingTree.open_containing('.')
-
- pygtk = import_pygtk()
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
+ self.open_display()
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
-
- set_ui_factory()
dialog = ConflictsDialog(wt)
dialog.run()
register_command(cmd_gconflicts)
-class cmd_gpreferences(Command):
+
+class cmd_gpreferences(GTKCommand):
""" GTK+ preferences dialog.
"""
def run(self):
- pygtk = import_pygtk()
- try:
- import gtk
- except RuntimeError, e:
- if str(e) == "could not open display":
- raise NoDisplayError
-
+ self.open_display()
from bzrlib.plugins.gtk.preferences import PreferencesWindow
-
- set_ui_factory()
dialog = PreferencesWindow()
dialog.run()
register_command(cmd_gpreferences)
+
import gettext
gettext.install('olive-gtk')
+
class NoDisplayError(BzrCommandError):
"""gtk could not find a proper display"""
def __str__(self):
return "No DISPLAY. Unable to run GTK+ application."
+
def test_suite():
from unittest import TestSuite
import tests
More information about the bazaar-commits
mailing list