[Pkg-bazaar-commits] ./bzr-gtk/unstable r147: Remove a bunch of duplicate functionality.
Jelmer Vernooij
jelmer at samba.org
Fri Apr 10 07:49:31 UTC 2009
------------------------------------------------------------
revno: 147
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sat 2007-02-03 13:35:55 +0100
message:
Remove a bunch of duplicate functionality.
There is now one LogView widget that shows revision information and is used
from both annotate and viz.
modified:
logview.py
olive/__init__.py
olive/dialog.py
viz/branchwin.py
-------------- next part --------------
=== modified file 'logview.py'
--- a/logview.py 2007-02-03 11:52:13 +0000
+++ b/logview.py 2007-02-03 12:35:55 +0000
@@ -31,59 +31,85 @@
def __init__(self, revision=None):
gtk.ScrolledWindow.__init__(self)
- self.parent_id_widgets = []
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.set_shadow_type(gtk.SHADOW_NONE)
self._create()
+ self._show_callback = None
+ self._clicked_callback = None
if revision is not None:
self.set_revision(revision)
+ def set_show_callback(self, callback):
+ self._show_callback = callback
+
+ def set_go_callback(self, callback):
+ self._go_callback = callback
+
def set_revision(self, revision):
+ self._revision = revision
self.revision_id.set_text(revision.revision_id)
self.committer.set_text(revision.committer)
self.timestamp.set_text(format_date(revision.timestamp,
revision.timezone))
self.message_buffer.set_text(revision.message)
+ try:
+ self.branchnick_label.set_text(revision.properties['branch-nick'])
+ except KeyError:
+ self.branchnick_label.set_text("")
+
self._add_parents(revision.parent_ids)
+ def _show_clicked_cb(self, widget, revid, parentid):
+ """Callback for when the show button for a parent is clicked."""
+ self._show_callback(revid, parentid)
+
+ def _go_clicked_cb(self, widget, revid):
+ """Callback for when the go button for a parent is clicked."""
+ self._go_callback(revid)
+
def _add_parents(self, parent_ids):
- for widget in self.parent_id_widgets:
- self.table.remove(widget)
+ for widget in self.parents_widgets:
+ self.parents_table.remove(widget)
- self.parent_id_widgets = []
-
- if len(parent_ids):
- self.table.resize(4 + len(parent_ids), 2)
-
- align = gtk.Alignment(1.0, 0.5)
+ self.parents_widgets = []
+ self.parents_table.resize(max(len(parent_ids), 1), 2)
+
+ for idx, parent_id in enumerate(parent_ids):
+ align = gtk.Alignment(0.0, 0.0)
+ self.parents_widgets.append(align)
+ self.parents_table.attach(align, 1, 2, idx, idx + 1,
+ gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
- self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
- self.parent_id_widgets.append(align)
-
- label = gtk.Label()
- if len(parent_ids) > 1:
- label.set_markup("<b>Parent Ids:</b>")
- else:
- label.set_markup("<b>Parent Id:</b>")
- label.show()
- align.add(label)
-
- for i, parent_id in enumerate(parent_ids):
- align = gtk.Alignment(0.0, 0.5)
- self.parent_id_widgets.append(align)
- self.table.attach(align, 1, 2, i + 3, i + 4,
- gtk.EXPAND | gtk.FILL, gtk.FILL)
- align.show()
- label = gtk.Label(parent_id)
- label.set_selectable(True)
- label.show()
- align.add(label)
+
+ hbox = gtk.HBox(False, spacing=6)
+ align.add(hbox)
+ hbox.show()
+
+ image = gtk.Image()
+ image.set_from_stock(
+ gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
+ image.show()
+
+ button = gtk.Button()
+ button.add(image)
+ button.set_sensitive(self._show_callback is not None)
+ button.connect("clicked", self._show_clicked_cb,
+ self._revision.revision_id, parent_id)
+ hbox.pack_start(button, expand=False, fill=True)
+ button.show()
+
+ button = gtk.Button(parent_id)
+ button.set_use_underline(False)
+ button.connect("clicked", self._go_clicked_cb, parent_id)
+ hbox.pack_start(button, expand=False, fill=True)
+ button.show()
def _create(self):
vbox = gtk.VBox(False, 6)
vbox.set_border_width(6)
vbox.pack_start(self._create_headers(), expand=False, fill=True)
+ vbox.pack_start(self._create_parents_table(), expand=False, fill=True)
vbox.pack_start(self._create_message_view())
self.add_with_viewport(vbox)
vbox.show()
@@ -93,12 +119,28 @@
self.table.set_row_spacings(6)
self.table.set_col_spacings(6)
self.table.show()
-
+
+ align = gtk.Alignment(1.0, 0.5)
+ label = gtk.Label()
+ label.set_markup("<b>Revision Id:</b>")
+ align.add(label)
+ self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
+ align.show()
+ label.show()
+
+ align = gtk.Alignment(0.0, 0.5)
+ self.revision_id = gtk.Label()
+ self.revision_id.set_selectable(True)
+ align.add(self.revision_id)
+ self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
+ align.show()
+ self.revision_id.show()
+
align = gtk.Alignment(1.0, 0.5)
label = gtk.Label()
label.set_markup("<b>Committer:</b>")
align.add(label)
- self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
+ self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
align.show()
label.show()
@@ -106,15 +148,31 @@
self.committer = gtk.Label()
self.committer.set_selectable(True)
align.add(self.committer)
- self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
+ self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
self.committer.show()
+ align = gtk.Alignment(0.0, 0.5)
+ label = gtk.Label()
+ label.set_markup("<b>Branch nick:</b>")
+ align.add(label)
+ self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
+ label.show()
+ align.show()
+
+ align = gtk.Alignment(0.0, 0.5)
+ self.branchnick_label = gtk.Label()
+ self.branchnick_label.set_selectable(True)
+ align.add(self.branchnick_label)
+ self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
+ self.branchnick_label.show()
+ align.show()
+
align = gtk.Alignment(1.0, 0.5)
label = gtk.Label()
label.set_markup("<b>Timestamp:</b>")
align.add(label)
- self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
+ self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
align.show()
label.show()
@@ -122,28 +180,29 @@
self.timestamp = gtk.Label()
self.timestamp.set_selectable(True)
align.add(self.timestamp)
- self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
+ self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
align.show()
self.timestamp.show()
- align = gtk.Alignment(1.0, 0.5)
- label = gtk.Label()
- label.set_markup("<b>Revision Id:</b>")
- align.add(label)
- self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
- align.show()
- label.show()
-
- align = gtk.Alignment(0.0, 0.5)
- self.revision_id = gtk.Label()
- self.revision_id.set_selectable(True)
- align.add(self.revision_id)
- self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
- align.show()
- self.revision_id.show()
-
return self.table
+ def _create_parents_table(self):
+ self.parents_table = gtk.Table(rows=1, columns=2)
+ self.parents_table.set_row_spacings(3)
+ self.parents_table.set_col_spacings(6)
+ self.parents_table.show()
+ self.parents_widgets = []
+
+ label = gtk.Label()
+ label.set_markup("<b>Parents:</b>")
+ align = gtk.Alignment(0.0, 0.5)
+ align.add(label)
+ self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
+ label.show()
+ align.show()
+
+ return self.parents_table
+
def _create_message_view(self):
self.message_buffer = gtk.TextBuffer()
tv = gtk.TextView(self.message_buffer)
=== modified file 'olive/__init__.py'
--- a/olive/__init__.py 2007-02-03 10:38:36 +0000
+++ b/olive/__init__.py 2007-02-03 12:35:55 +0000
@@ -248,6 +248,7 @@
checkout.destroy()
+ @show_bzr_error
def on_menuitem_branch_commit_activate(self, widget):
""" Branch/Commit... menu handler. """
commit = CommitDialog(self.wt, self.wtpath, self.notbranch, self.get_selected_right(), self.window)
=== modified file 'olive/dialog.py'
--- a/olive/dialog.py 2007-01-31 10:00:12 +0000
+++ b/olive/dialog.py 2007-02-03 12:35:55 +0000
@@ -46,55 +46,33 @@
# Destroy the dialog
dialog.destroy()
-def _message_dialog(type, primary, secondary):
+def _message_dialog(type, primary, secondary, buttons=gtk.BUTTONS_OK):
""" Display a given type of MessageDialog with the given message.
- :param type: error | warning | info
+ :param type: message dialog type
:param message: the message you want to display.
"""
- if type == 'error':
- dialog = gtk.MessageDialog(flags=gtk.DIALOG_MODAL,
- type=gtk.MESSAGE_ERROR,
- buttons=gtk.BUTTONS_OK)
- dialog.set_markup('<big><b>' + primary + '</b></big>')
- elif type == 'warning':
- dialog = gtk.MessageDialog(flags=gtk.DIALOG_MODAL,
- type=gtk.MESSAGE_WARNING,
- buttons=gtk.BUTTONS_OK)
- dialog.set_markup('<big><b>' + primary + '</b></big>')
- elif type == 'info':
- dialog = gtk.MessageDialog(flags=gtk.DIALOG_MODAL,
- type=gtk.MESSAGE_INFO,
- buttons=gtk.BUTTONS_OK)
- dialog.set_markup('<big><b>' + primary + '</b></big>')
- elif type == 'question':
- dialog = gtk.MessageDialog(flags=gtk.DIALOG_MODAL,
- type=gtk.MESSAGE_QUESTION,
- buttons=gtk.BUTTONS_YES_NO)
- dialog.set_markup('<big><b>' + primary + '</b></big>')
- else:
- return
-
+ dialog = gtk.MessageDialog(flags=gtk.DIALOG_MODAL, type=type,
+ buttons=buttons)
+ dialog.set_markup('<big><b>' + primary + '</b></big>')
dialog.format_secondary_markup(secondary)
-
response = dialog.run()
dialog.destroy()
-
return response
def error_dialog(primary, secondary):
""" Display an error dialog with the given message. """
- return _message_dialog('error', primary, secondary)
+ return _message_dialog(gtk.MESSAGE_ERROR, primary, secondary)
def info_dialog(primary, secondary):
""" Display an info dialog with the given message. """
- return _message_dialog('info', primary, secondary)
+ return _message_dialog(gtk.MESSAGE_INFO, primary, secondary)
def warning_dialog(primary, secondary):
""" Display a warning dialog with the given message. """
- return _message_dialog('warning', primary, secondary)
+ return _message_dialog(gtk.MESSAGE_WARNING, primary, secondary)
def question_dialog(primary, secondary):
""" Display a dialog with the given question. """
- return _message_dialog('question', primary, secondary)
+ return _message_dialog(gtk.MESSAGE_QUESTION, primary, secondary, gtk.BUTTONS_YES_NO)
=== modified file 'viz/branchwin.py'
--- a/viz/branchwin.py 2006-09-06 09:27:12 +0000
+++ b/viz/branchwin.py 2007-02-03 12:35:55 +0000
@@ -147,112 +147,16 @@
def construct_bottom(self):
"""Construct the bottom half of the window."""
- scrollwin = gtk.ScrolledWindow()
- scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
- scrollwin.set_shadow_type(gtk.SHADOW_NONE)
+ from bzrlib.plugins.gtk.logview import LogView
+ self.logview = LogView()
+ self.logview.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+ self.logview.set_shadow_type(gtk.SHADOW_NONE)
(width, height) = self.get_size()
- scrollwin.set_size_request(width, int(height / 2.5))
- scrollwin.show()
-
- vbox = gtk.VBox(False, spacing=6)
- vbox.set_border_width(6)
- scrollwin.add_with_viewport(vbox)
- vbox.show()
-
- table = gtk.Table(rows=4, columns=2)
- table.set_row_spacings(6)
- table.set_col_spacings(6)
- vbox.pack_start(table, expand=False, fill=True)
- table.show()
-
- align = gtk.Alignment(0.0, 0.5)
- label = gtk.Label()
- label.set_markup("<b>Revision:</b>")
- align.add(label)
- table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
- label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- self.revid_label = gtk.Label()
- self.revid_label.set_selectable(True)
- align.add(self.revid_label)
- table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
- self.revid_label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- label = gtk.Label()
- label.set_markup("<b>Committer:</b>")
- align.add(label)
- table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
- label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- self.committer_label = gtk.Label()
- self.committer_label.set_selectable(True)
- align.add(self.committer_label)
- table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
- self.committer_label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- label = gtk.Label()
- label.set_markup("<b>Branch nick:</b>")
- align.add(label)
- table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
- label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- self.branchnick_label = gtk.Label()
- self.branchnick_label.set_selectable(True)
- align.add(self.branchnick_label)
- table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
- self.branchnick_label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- label = gtk.Label()
- label.set_markup("<b>Timestamp:</b>")
- align.add(label)
- table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
- label.show()
- align.show()
-
- align = gtk.Alignment(0.0, 0.5)
- self.timestamp_label = gtk.Label()
- self.timestamp_label.set_selectable(True)
- align.add(self.timestamp_label)
- table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
- self.timestamp_label.show()
- align.show()
-
- self.parents_table = gtk.Table(rows=1, columns=2)
- self.parents_table.set_row_spacings(3)
- self.parents_table.set_col_spacings(6)
- self.parents_table.show()
- vbox.pack_start(self.parents_table, expand=False, fill=True)
- self.parents_widgets = []
-
- label = gtk.Label()
- label.set_markup("<b>Parents:</b>")
- align = gtk.Alignment(0.0, 0.5)
- align.add(label)
- self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
- label.show()
- align.show()
-
- self.message_buffer = gtk.TextBuffer()
- textview = gtk.TextView(self.message_buffer)
- textview.set_editable(False)
- textview.set_wrap_mode(gtk.WRAP_WORD)
- textview.modify_font(pango.FontDescription("Monospace"))
- vbox.pack_start(textview, expand=True, fill=True)
- textview.show()
-
- return scrollwin
+ self.logview.set_size_request(width, int(height / 2.5))
+ self.logview.show()
+ self.logview.set_show_callback(self._show_clicked_cb)
+ self.logview.set_go_callback(self._go_clicked_cb)
+ return self.logview
def set_branch(self, branch, start, maxnum):
"""Set the branch and start position for this window.
@@ -302,66 +206,7 @@
self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
-
- if revision.committer is not None:
- branchnick = ""
- committer = revision.committer
- timestamp = format_date(revision.timestamp, revision.timezone)
- message = revision.message
- try:
- branchnick = revision.properties['branch-nick']
- except KeyError:
- pass
-
- else:
- committer = ""
- timestamp = ""
- message = ""
- branchnick = ""
-
- self.revid_label.set_text(revision.revision_id)
- self.branchnick_label.set_text(branchnick)
-
- self.committer_label.set_text(committer)
- self.timestamp_label.set_text(timestamp)
- self.message_buffer.set_text(message)
-
- for widget in self.parents_widgets:
- self.parents_table.remove(widget)
-
- self.parents_widgets = []
- self.parents_table.resize(max(len(self.parent_ids[revision]), 1), 2)
-
- for idx, parent_id in enumerate(self.parent_ids[revision]):
- align = gtk.Alignment(0.0, 0.0)
- self.parents_widgets.append(align)
- self.parents_table.attach(align, 1, 2, idx, idx + 1,
- gtk.EXPAND | gtk.FILL, gtk.FILL)
- align.show()
-
- hbox = gtk.HBox(False, spacing=6)
- align.add(hbox)
- hbox.show()
-
- image = gtk.Image()
- image.set_from_stock(
- gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
- image.show()
-
- button = gtk.Button()
- button.add(image)
- button.set_sensitive(self.app is not None)
- button.connect("clicked", self._show_clicked_cb,
- revision.revision_id, parent_id)
- hbox.pack_start(button, expand=False, fill=True)
- button.show()
-
- button = gtk.Button(parent_id)
- button.set_use_underline(False)
- button.connect("clicked", self._go_clicked_cb, parent_id)
- hbox.pack_start(button, expand=False, fill=True)
- button.show()
-
+ self.logview.set_revision(revision)
def _back_clicked_cb(self, *args):
"""Callback for when the back button is clicked."""
@@ -396,12 +241,12 @@
self.treeview.set_cursor(self.index[prev])
self.treeview.grab_focus()
- def _go_clicked_cb(self, widget, revid):
+ def _go_clicked_cb(self, revid):
"""Callback for when the go button for a parent is clicked."""
self.treeview.set_cursor(self.index[self.revisions[revid]])
self.treeview.grab_focus()
- def _show_clicked_cb(self, widget, revid, parentid):
+ def _show_clicked_cb(self, revid, parentid):
"""Callback for when the show button for a parent is clicked."""
if self.app is not None:
self.app.show_diff(self.branch, revid, parentid)
More information about the Pkg-bazaar-commits
mailing list