79
101
def set_ui_factory():
80
pygtk = import_pygtk()
81
103
from ui import GtkUIFactory
83
105
bzrlib.ui.ui_factory = GtkUIFactory()
86
class cmd_gbranch(Command):
108
class GTKCommand(Command):
109
"""Abstract class providing GTK specific run commands."""
111
def open_display(self):
112
pygtk = import_pygtk()
115
except RuntimeError, e:
116
if str(e) == "could not open display":
123
dialog = self.get_gtk_dialog(os.path.abspath('.'))
127
class cmd_gbranch(GTKCommand):
87
128
"""GTK+ branching.
92
pygtk = import_pygtk()
95
except RuntimeError, e:
96
if str(e) == "could not open display":
132
def get_gtk_dialog(self, path):
99
133
from bzrlib.plugins.gtk.branch import BranchDialog
102
dialog = BranchDialog(os.path.abspath('.'))
105
register_command(cmd_gbranch)
107
class cmd_gcheckout(Command):
134
return BranchDialog(path)
137
class cmd_gcheckout(GTKCommand):
108
138
""" GTK+ checkout.
113
pygtk = import_pygtk()
116
except RuntimeError, e:
117
if str(e) == "could not open display":
142
def get_gtk_dialog(self, path):
120
143
from bzrlib.plugins.gtk.checkout import CheckoutDialog
123
dialog = CheckoutDialog(os.path.abspath('.'))
126
register_command(cmd_gcheckout)
128
class cmd_gpush(Command):
144
return CheckoutDialog(path)
148
class cmd_gpush(GTKCommand):
132
152
takes_args = [ "location?" ]
134
154
def run(self, location="."):
135
(branch, path) = Branch.open_containing(location)
137
pygtk = import_pygtk()
140
except RuntimeError, e:
141
if str(e) == "could not open display":
155
(br, path) = branch.Branch.open_containing(location)
144
157
from push import PushDialog
147
dialog = PushDialog(branch)
158
dialog = PushDialog(br)
150
register_command(cmd_gpush)
152
class cmd_gdiff(Command):
163
class cmd_gdiff(GTKCommand):
153
164
"""Show differences in working tree in a GTK+ Window.
155
166
Otherwise, all changes for the tree are listed.
161
172
def run(self, revision=None, filename=None):
163
wt = WorkingTree.open_containing(".")[0]
165
if revision is not None:
166
if len(revision) == 1:
174
wt = workingtree.WorkingTree.open_containing(".")[0]
178
if revision is not None:
179
if len(revision) == 1:
181
revision_id = revision[0].in_history(branch).rev_id
182
tree2 = branch.repository.revision_tree(revision_id)
183
elif len(revision) == 2:
184
revision_id_0 = revision[0].in_history(branch).rev_id
185
tree2 = branch.repository.revision_tree(revision_id_0)
186
revision_id_1 = revision[1].in_history(branch).rev_id
187
tree1 = branch.repository.revision_tree(revision_id_1)
168
revision_id = revision[0].in_history(branch).rev_id
169
tree2 = branch.repository.revision_tree(revision_id)
170
elif len(revision) == 2:
171
revision_id_0 = revision[0].in_history(branch).rev_id
172
tree2 = branch.repository.revision_tree(revision_id_0)
173
revision_id_1 = revision[1].in_history(branch).rev_id
174
tree1 = branch.repository.revision_tree(revision_id_1)
177
tree2 = tree1.basis_tree()
179
from viz.diff import DiffWindow
181
window = DiffWindow()
182
window.connect("destroy", lambda w: gtk.main_quit())
183
window.set_diff("Working Tree", tree1, tree2)
184
if filename is not None:
185
tree_filename = wt.relpath(filename)
187
window.set_file(tree_filename)
189
if (tree1.inventory.path2id(tree_filename) is None and
190
tree2.inventory.path2id(tree_filename) is None):
191
raise NotVersionedError(filename)
192
raise BzrCommandError('No changes found for file "%s"' %
198
register_command(cmd_gdiff)
190
tree2 = tree1.basis_tree()
192
from diff import DiffWindow
194
window = DiffWindow()
195
window.connect("destroy", gtk.main_quit)
196
window.set_diff("Working Tree", tree1, tree2)
197
if filename is not None:
198
tree_filename = wt.relpath(filename)
200
window.set_file(tree_filename)
202
if (tree1.path2id(tree_filename) is None and
203
tree2.path2id(tree_filename) is None):
204
raise NotVersionedError(filename)
205
raise BzrCommandError('No changes found for file "%s"' %
214
def start_viz_window(branch, revision, limit=None):
215
"""Start viz on branch with revision revision.
217
:return: The viz window object.
219
from viz.branchwin import BranchWindow
222
pp.set_branch(branch, revision, limit)
223
# cleanup locks when the window is closed
224
pp.connect("destroy", lambda w: branch.unlock())
200
228
class cmd_visualise(Command):
201
229
"""Graphically visualise this branch.
209
237
takes_options = [
211
Option('limit', "maximum number of revisions to display",
239
Option('limit', "Maximum number of revisions to display.",
213
241
takes_args = [ "location?" ]
214
242
aliases = [ "visualize", "vis", "viz" ]
216
244
def run(self, location=".", revision=None, limit=None):
218
(branch, path) = Branch.open_containing(location)
220
branch.repository.lock_read()
246
(br, path) = branch.Branch.open_containing(location)
222
249
if revision is None:
223
revid = branch.last_revision()
250
revid = br.last_revision()
224
251
if revid is None:
227
(revno, revid) = revision[0].in_history(branch)
254
(revno, revid) = revision[0].in_history(br)
229
from viz.bzrkapp import BzrkApp
232
app.show(branch, revid, limit)
257
pp = start_viz_window(br, revid, limit)
258
pp.connect("destroy", lambda w: gtk.main_quit())
234
branch.repository.unlock()
239
register_command(cmd_visualise)
241
class cmd_gannotate(Command):
265
class cmd_gannotate(GTKCommand):
242
266
"""GTK+ annotate.
244
268
Browse changes to FILENAME line by line in a GTK+ window.
247
271
takes_args = ["filename", "line?"]
248
272
takes_options = [
249
Option("all", help="show annotations on all lines"),
250
Option("plain", help="don't highlight annotation lines"),
273
Option("all", help="Show annotations on all lines."),
274
Option("plain", help="Don't highlight annotation lines."),
251
275
Option("line", type=int, argname="lineno",
252
help="jump to specified line number"),
276
help="Jump to specified line number."),
255
279
aliases = ["gblame", "gpraise"]
257
281
def run(self, filename, all=False, plain=False, line='1', revision=None):
258
pygtk = import_pygtk()
262
except RuntimeError, e:
263
if str(e) == "could not open display":
282
gtk = self.open_display()
320
340
def run(self, filename=None):
322
pygtk = import_pygtk()
326
except RuntimeError, e:
327
if str(e) == "could not open display":
331
343
from commit import CommitDialog
332
from bzrlib.commit import Commit
333
344
from bzrlib.errors import (BzrCommandError,
343
(wt, path) = WorkingTree.open_containing(filename)
345
except NotBranchError, e:
351
(wt, path) = workingtree.WorkingTree.open_containing(filename)
347
353
except NoWorkingTree, e:
350
(branch, path) = Branch.open_containing(path)
351
except NotBranchError, e:
355
commit = CommitDialog(wt, path, not branch)
355
(br, path) = branch.Branch.open_containing(path)
357
commit = CommitDialog(wt, path, not br)
358
register_command(cmd_gcommit)
362
class cmd_gstatus(GTKCommand):
363
"""GTK+ status dialog
365
Graphical user interface for showing status
369
takes_args = ['PATH?']
372
def run(self, path='.'):
374
gtk = self.open_display()
375
from status import StatusDialog
376
(wt, wt_path) = workingtree.WorkingTree.open_containing(path)
377
status = StatusDialog(wt, wt_path)
378
status.connect("destroy", gtk.main_quit)
383
class cmd_gconflicts(GTKCommand):
388
(wt, path) = workingtree.WorkingTree.open_containing('.')
390
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
391
dialog = ConflictsDialog(wt)
396
class cmd_gpreferences(GTKCommand):
397
""" GTK+ preferences dialog.
402
from bzrlib.plugins.gtk.preferences import PreferencesWindow
403
dialog = PreferencesWindow()
408
class cmd_gmissing(Command):
409
""" GTK+ missing revisions dialog.
412
takes_args = ["other_branch?"]
413
def run(self, other_branch=None):
414
pygtk = import_pygtk()
417
except RuntimeError, e:
418
if str(e) == "could not open display":
421
from bzrlib.plugins.gtk.missing import MissingWindow
422
from bzrlib.branch import Branch
424
local_branch = Branch.open_containing(".")[0]
425
if other_branch is None:
426
other_branch = local_branch.get_parent()
428
if other_branch is None:
429
raise errors.BzrCommandError("No peer location known or specified.")
430
remote_branch = Branch.open_containing(other_branch)[0]
432
local_branch.lock_read()
434
remote_branch.lock_read()
436
dialog = MissingWindow(local_branch, remote_branch)
439
remote_branch.unlock()
441
local_branch.unlock()
444
class cmd_ginit(GTKCommand):
447
from initialize import InitDialog
448
dialog = InitDialog(os.path.abspath(os.path.curdir))
452
class cmd_gtags(GTKCommand):
454
br = branch.Branch.open_containing('.')[0]
456
gtk = self.open_display()
457
from tags import TagsWindow
458
window = TagsWindow(br)
480
register_command(cmd)
483
class cmd_commit_notify(GTKCommand):
484
"""Run the bzr commit notifier.
486
This is a background program which will pop up a notification on the users
487
screen when a commit occurs.
491
from notify import NotifyPopupMenu
492
gtk = self.open_display()
493
menu = NotifyPopupMenu()
494
icon = gtk.status_icon_new_from_file("bzr-icon-64.png")
495
icon.connect('popup-menu', menu.display)
501
from bzrlib.bzrdir import BzrDir
502
from bzrlib import errors
503
from bzrlib.osutils import format_date
504
from bzrlib.transport import get_transport
505
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
507
from bzrlib.plugins.dbus import activity
508
bus = dbus.SessionBus()
509
# get the object so we can subscribe to callbacks from it.
510
broadcast_service = bus.get_object(
511
activity.Broadcast.DBUS_NAME,
512
activity.Broadcast.DBUS_PATH)
514
def catch_branch(revision_id, urls):
515
# TODO: show all the urls, or perhaps choose the 'best'.
518
if isinstance(revision_id, unicode):
519
revision_id = revision_id.encode('utf8')
520
transport = get_transport(url)
521
a_dir = BzrDir.open_from_transport(transport)
522
branch = a_dir.open_branch()
523
revno = branch.revision_id_to_revno(revision_id)
524
revision = branch.repository.get_revision(revision_id)
525
summary = 'New revision %d in %s' % (revno, url)
526
body = 'Committer: %s\n' % revision.committer
527
body += 'Date: %s\n' % format_date(revision.timestamp,
530
body += revision.message
531
body = cgi.escape(body)
532
nw = pynotify.Notification(summary, body)
533
def start_viz(notification=None, action=None, data=None):
534
"""Start the viz program."""
535
pp = start_viz_window(branch, revision_id)
537
def start_branch(notification=None, action=None, data=None):
538
"""Start a Branch dialog"""
539
from bzrlib.plugins.gtk.branch import BranchDialog
540
bd = BranchDialog(remote_path=url)
542
nw.add_action("inspect", "Inspect", start_viz, None)
543
nw.add_action("branch", "Branch", start_branch, None)
549
broadcast_service.connect_to_signal("Revision", catch_branch,
550
dbus_interface=activity.Broadcast.DBUS_INTERFACE)
551
pynotify.init("bzr commit-notify")
554
register_command(cmd_commit_notify)
558
gettext.install('olive-gtk')
360
561
class NoDisplayError(BzrCommandError):
361
562
"""gtk could not find a proper display"""