[Pkg-bazaar-commits] ./bzr-gtk/unstable r182: Merge trunk

Jelmer Vernooij jelmer at samba.org
Fri Apr 10 07:49:41 UTC 2009


------------------------------------------------------------
revno: 182
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Fri 2007-03-23 14:43:29 +0100
message:
  Merge trunk
modified:
  __init__.py
  annotate/gannotate.py
  tests/__init__.py
    ------------------------------------------------------------
    revno: 173.1.1
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: gtk
    timestamp: Mon 2007-03-19 10:04:43 -0400
    message:
      Better behavior when unable to go back
    modified:
      annotate/gannotate.py
    ------------------------------------------------------------
    revno: 173.1.2
    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
    ------------------------------------------------------------
    revno: 173.1.3
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: trunk
    timestamp: Fri 2007-03-23 23:46:47 +1100
    message:
      Add new command 'commit-notify' to listen for commits on dbus and show them via pynotify.
    modified:
      __init__.py
      tests/__init__.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-03-20 21:08:58 +0000
+++ b/__init__.py	2007-03-23 13:43:29 +0000
@@ -87,46 +87,47 @@
     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()
+        return gtk
+
+    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
-
-        set_ui_factory()
-        dialog = BranchDialog(os.path.abspath('.'))
-        dialog.run()
-
-class cmd_gcheckout(Command):
+        return BranchDialog(path)
+
+
+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()
-
-
-class cmd_gpush(Command):
+        return CheckoutDialog(path)
+
+
+
+class cmd_gpush(GTKCommand):
     """ GTK+ push.
     
     """
@@ -134,22 +135,14 @@
 
     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()
 
 
-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.
@@ -242,7 +235,7 @@
             br.unlock()
 
 
-class cmd_gannotate(Command):
+class cmd_gannotate(GTKCommand):
     """GTK+ annotate.
     
     Browse changes to FILENAME line by line in a GTK+ window.
@@ -259,14 +252,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)
@@ -314,7 +300,8 @@
                 wt.unlock()
 
 
-class cmd_gcommit(Command):
+
+class cmd_gcommit(GTKCommand):
     """GTK+ commit dialog
 
     Graphical user interface for committing revisions"""
@@ -325,15 +312,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.errors import (BzrCommandError,
                                    NotBranchError,
@@ -357,7 +336,8 @@
         commit.run()
 
 
-class cmd_gstatus(Command):
+
+class cmd_gstatus(GTKCommand):
     """GTK+ status dialog
 
     Graphical user interface for showing status 
@@ -369,15 +349,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)
@@ -385,42 +357,27 @@
         status.run()
 
 
-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()
 
 
-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()
 
@@ -479,15 +436,80 @@
 for cmd in commands:
     register_command(cmd)
 
+
+class cmd_commit_notify(GTKCommand):
+    """Run the bzr commit notifier.
+
+    This is a background program which will pop up a notification on the users
+    screen when a commit occurs.
+    """
+
+    def run(self):
+        gtk = self.open_display()
+        import cgi
+        import dbus
+        import dbus.service
+        import pynotify
+        from bzrlib.bzrdir import BzrDir
+        from bzrlib import errors
+        from bzrlib.osutils import format_date
+        from bzrlib.transport import get_transport
+        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
+            import dbus.glib
+        from bzrlib.plugins.dbus import activity
+        bus = dbus.SessionBus()
+        # get the object so we can subscribe to callbacks from it.
+        broadcast_service = bus.get_object(
+            activity.Broadcast.DBUS_NAME,
+            activity.Broadcast.DBUS_PATH)
+        def catch_branch(revision_id, url):
+            try:
+                if isinstance(revision_id, unicode):
+                    revision_id = revision_id.encode('utf8')
+                transport = get_transport(url)
+                try:
+                    transport.local_abspath('.')
+                except errors.TransportNotPossible:
+                    # dont show remote urls for now.
+                    return
+                # here we should:
+                a_dir = BzrDir.open_from_transport(transport)
+                branch = a_dir.open_branch()
+                revno = branch.revision_id_to_revno(revision_id)
+                revision = branch.repository.get_revision(revision_id)
+                summary = 'New revision %d in %s' % (revno, url)
+                body  = 'Committer: %s\n' % revision.committer
+                body += 'Date: %s\n' % format_date(revision.timestamp,
+                    revision.timezone)
+                body += '\n'
+                body += revision.message
+                body = cgi.escape(body)
+                #print repr(body)
+                nw = pynotify.Notification(summary, body)
+                nw.set_timeout(5000)
+                nw.show()
+            except Exception, e:
+                print e
+                raise
+        broadcast_service.connect_to_signal("Revision", catch_branch,
+            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
+        pynotify.init("bzr commit-notify")
+        gtk.main()
+
+register_command(cmd_commit_notify)
+
+
 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

=== modified file 'annotate/gannotate.py'
--- a/annotate/gannotate.py	2007-03-18 00:22:11 +0000
+++ b/annotate/gannotate.py	2007-03-19 14:04:43 +0000
@@ -56,6 +56,7 @@
         self._create()
         self.revisions = {}
         self.history = []
+        self._no_back = set()
 
     def annotate(self, tree, branch, file_id):
         self.annotations = []
@@ -184,7 +185,12 @@
             return
         selected = self.revisions[rev_id]
         self.logview.set_revision(selected)
-        self.back_button.set_sensitive(len(selected.parent_ids) != 0)
+        if (len(selected.parent_ids) != 0 and selected.parent_ids[0] not in
+            self._no_back):
+            enable_back = True
+        else:
+            enable_back = False
+        self.back_button.set_sensitive(enable_back)
 
     def _create(self):
         self.logview = self._create_log_view()
@@ -342,12 +348,16 @@
         return button
 
     def go_back(self):
-        self.history.append(self.tree)
-        self.forward_button.set_sensitive(True)
+        last_tree = self.tree
         rev_id = self._selected_revision()
         parent_id = self.revisions[rev_id].parent_ids[0]
         target_tree = self.branch.repository.revision_tree(parent_id)
-        self._go(target_tree)
+        if self._go(target_tree):
+            self.history.append(last_tree)
+            self.forward_button.set_sensitive(True)
+        else:
+            self._no_back.add(parent_id)
+            self.back_button.set_sensitive(False)
 
     def go_forward(self):
         if len(self.history) == 0:
@@ -367,6 +377,9 @@
             if new_row < 0:
                 new_row = 0
             self.annoview.set_cursor(new_row)
+            return True
+        else:
+            return False
 
     def get_scroll_offset(self, tree):
         old = self.tree.get_file(self.file_id)

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-03-09 19:05:06 +0000
+++ b/tests/__init__.py	2007-03-23 12:46:47 +0000
@@ -24,7 +24,10 @@
 
     loader = TestUtil.TestLoader()
 
-    testmod_names = ['test_preferences', 'test_history']
+    testmod_names = [
+        'test_preferences',
+        'test_history',
+        ]
 
     if os.name == 'nt':
         testmod_names.append("test_tortoise_bzr")



More information about the Pkg-bazaar-commits mailing list