Rev 231: Add RevisionSelectionBox widget, use in TagDialog. in file:///data/jelmer/bzr-gtk/trunk/

Jelmer Vernooij jelmer at samba.org
Sun Jul 15 19:12:58 BST 2007


At file:///data/jelmer/bzr-gtk/trunk/

------------------------------------------------------------
revno: 231
revision-id: jelmer at samba.org-20070715181257-g264qus2zyi3v39z
parent: jelmer at samba.org-20070715163921-ydeemssii7wxy06i
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sun 2007-07-15 20:12:57 +0200
message:
  Add RevisionSelectionBox widget, use in TagDialog.
added:
  revidbox.py                    revidbox.py-20070715180408-gf400nn0ao0tkw6b-1
modified:
  tags.py                        tags.py-20070408210738-1c0lyfurp88v5c56-1
=== added file 'revidbox.py'
--- a/revidbox.py	1970-01-01 00:00:00 +0000
+++ b/revidbox.py	2007-07-15 18:12:57 +0000
@@ -0,0 +1,60 @@
+# Copyright (C) 2007 by Szilveszter Farkas (Phanatic) <szilveszter.farkas at gmail.com>
+# Copyright (C) 2007 by Jelmer Vernooij <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+try:
+    import pygtk
+    pygtk.require("2.0")
+except:
+    pass
+
+import gtk
+
+class RevisionSelectionBox(gtk.HBox):
+    def __init__(self, branch):
+        super(RevisionSelectionBox, self).__init__()
+        self._branch = branch
+        self._entry_revid = gtk.Entry()
+        self._button_revid = gtk.Button('')
+        self._button_revid.set_image(gtk.image_new_from_stock(
+            gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON))
+        self.pack_start(self._entry_revid, True, True)
+        self.pack_start(self._button_revid, False, False) 
+
+        self._button_revid.connect('clicked', self._on_revid_clicked)
+
+    def _on_revid_clicked(self, widget):
+        """ Browse for revision button clicked handler. """
+        from revbrowser import RevisionBrowser
+        
+        # FIXME: Should specific parent window here - how to get to it?
+        # JRV 20070715
+        revb = RevisionBrowser(self._branch)
+        response = revb.run()
+        if response != gtk.RESPONSE_NONE:
+            revb.hide()
+        
+            if response == gtk.RESPONSE_OK:
+                if revb.selected_revno is not None:
+                    self._entry_revid.set_text(revb.selected_revid)
+            
+            revb.destroy()
+
+    def get_revision_id(self):
+        if len(self._entry_revid.get_text()) == 0:
+            return None
+        else:
+            return self._entry_revid.get_text()

=== modified file 'tags.py'
--- a/tags.py	2007-04-16 22:14:51 +0000
+++ b/tags.py	2007-07-15 18:12:57 +0000
@@ -1,4 +1,5 @@
 # Copyright (C) 2007 by Szilveszter Farkas (Phanatic) <szilveszter.farkas at gmail.com>
+# Copyright (C) 2007 by Jelmer Vernooij <jelmer at samba.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -25,6 +26,7 @@
 from bzrlib.plugins.gtk.logview import LogView
 
 from dialog import error_dialog
+from revidbox import RevisionSelectionBox
 
 
 class TagsWindow(gtk.Window):
@@ -158,7 +160,8 @@
     
     def _on_add_clicked(self, widget):
         """ Add button event handler. """
-        dialog = AddTagDialog(self.branch, self)
+        dialog = AddTagDialog(self.branch.repository, None,
+                              self.branch, self)
         response = dialog.run()
         if response != gtk.RESPONSE_NONE:
             dialog.hide()
@@ -269,42 +272,38 @@
 
 class AddTagDialog(gtk.Dialog):
     """ Add tag dialog. """
-    def __init__(self, branch, parent):
+    def __init__(self, repository, revid=None, branch=None, parent=None):
         """ Initialize Add tag dialog. """
         gtk.Dialog.__init__(self, title="Add tag - Olive",
                                   parent=parent,
                                   flags=0,
-                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+                                  buttons=(gtk.STOCK_CANCEL, 
+                                           gtk.RESPONSE_CANCEL))
         
         # Get arguments
+        self._repository = repository
+        self._revid = revid
         self._branch = branch
         
         # Create the widgets
         self._button_add = gtk.Button(_("_Add tag"), use_underline=True)
-        self._button_revid = gtk.Button('')
         self._table = gtk.Table(2, 2)
         self._label_name = gtk.Label(_("Tag Name:"))
         self._label_revid = gtk.Label(_("Revision ID:"))
         self._entry_name = gtk.Entry()
-        self._entry_revid = gtk.Entry()
-        self._hbox_revid = gtk.HBox()
+        self._hbox_revid = RevisionSelectionBox(self._branch)
         
         # Set callbacks
         self._button_add.connect('clicked', self._on_add_clicked)
-        self._button_revid.connect('clicked', self._on_revid_clicked)
         
         # Set properties
         self._label_name.set_alignment(0, 0.5)
         self._label_revid.set_alignment(0, 0.5)
         self._button_add.set_image(gtk.image_new_from_stock(gtk.STOCK_ADD,
                                                             gtk.ICON_SIZE_BUTTON))
-        self._button_revid.set_image(gtk.image_new_from_stock(gtk.STOCK_OPEN,
-                                                               gtk.ICON_SIZE_BUTTON))
         self._button_add.set_flags(gtk.CAN_DEFAULT)
         
         # Construct the dialog
-        self._hbox_revid.pack_start(self._entry_revid, True, True)
-        self._hbox_revid.pack_start(self._button_revid, False, False) 
         self._table.attach(self._label_name, 0, 1, 0, 1)
         self._table.attach(self._label_revid, 0, 1, 1, 2)
         self._table.attach(self._entry_name, 1, 2, 0, 1)
@@ -315,21 +314,6 @@
         # Show the dialog
         self.vbox.show_all()
     
-    def _on_revid_clicked(self, widget):
-        """ Browse for revision button clicked handler. """
-        from revbrowser import RevisionBrowser
-        
-        revb = RevisionBrowser(self._branch, self)
-        response = revb.run()
-        if response != gtk.RESPONSE_NONE:
-            revb.hide()
-        
-            if response == gtk.RESPONSE_OK:
-                if revb.selected_revno is not None:
-                    self._entry_revid.set_text(revb.selected_revid)
-            
-            revb.destroy()
-    
     def _on_add_clicked(self, widget):
         """ Add button clicked handler. """
         if len(self._entry_name.get_text()) == 0:
@@ -337,10 +321,10 @@
                          _("You have to specify the tag's desired name."))
             return
         
-        if len(self._entry_revid.get_text()) == 0:
+        if self._hbox_revid.get_revision_id() is None:
             self.revid = self._branch.last_revision()
         else:
-            self.revid = self._entry_revid.get_text()
+            self.revid = self.hbox_revid.get_revision_id()
         
         self.tagname = self._entry_name.get_text()
         




More information about the bazaar-commits mailing list