/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Daniel Schierbeck
  • Date: 2008-01-23 16:36:21 UTC
  • mto: (423.1.8 trunk)
  • mto: This revision was merged to the branch mainline in revision 429.
  • Revision ID: daniel.schierbeck@gmail.com-20080123163621-x8kublc38ojipnly
Made the revision popup menu correctly add tags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
"""Graphical support for Bazaar using GTK.
16
16
 
17
17
This plugin includes:
 
18
commit-notify     Start the graphical notifier of commits.
18
19
gannotate         GTK+ annotate. 
19
20
gbranch           GTK+ branching. 
20
21
gcheckout         GTK+ checkout. 
22
23
gconflicts        GTK+ conflicts. 
23
24
gdiff             Show differences in working tree in a GTK+ Window. 
24
25
ginit             Initialise a new branch.
25
 
gmerge            GTK+ merge dialog
26
26
gmissing          GTK+ missing revisions dialog. 
27
27
gpreferences      GTK+ preferences dialog. 
28
28
gpush             GTK+ push.
36
36
 
37
37
import bzrlib
38
38
 
39
 
version_info = (0, 95, 0, 'dev', 1)
 
39
version_info = (0, 94, 0, 'dev', 0)
40
40
 
41
41
if version_info[3] == 'final':
42
42
    version_string = '%d.%d.%d' % version_info[:3]
44
44
    version_string = '%d.%d.%d%s%d' % version_info
45
45
__version__ = version_string
46
46
 
47
 
required_bzrlib = (1, 3)
 
47
required_bzrlib = (1, 0)
48
48
 
49
49
def check_bzrlib_version(desired):
50
50
    """Check that bzrlib is compatible.
77
77
    branch,
78
78
    builtins,
79
79
    errors,
80
 
    merge_directive,
81
80
    workingtree,
82
81
    )
83
82
""")
104
103
    bzrlib.ui.ui_factory = GtkUIFactory()
105
104
 
106
105
 
107
 
def data_basedirs():
108
 
    return [os.path.dirname(__file__),
109
 
             "/usr/share/bzr-gtk", 
110
 
             "/usr/local/share/bzr-gtk"]
111
 
 
112
 
 
113
 
def data_path(*args):
114
 
    for basedir in data_basedirs():
115
 
        path = os.path.join(basedir, *args)
116
 
        if os.path.exists(path):
117
 
            return path
118
 
    return None
119
 
 
120
 
 
121
 
def icon_path(*args):
122
 
    return data_path(os.path.join('icons', *args))
123
 
 
124
 
 
125
 
def open_display():
126
 
    pygtk = import_pygtk()
127
 
    try:
128
 
        import gtk
129
 
    except RuntimeError, e:
130
 
        if str(e) == "could not open display":
131
 
            raise NoDisplayError
132
 
    set_ui_factory()
133
 
    return gtk
134
 
 
 
106
def data_path():
 
107
    return os.path.dirname(__file__)
 
108
 
135
109
 
136
110
class GTKCommand(Command):
137
111
    """Abstract class providing GTK specific run commands."""
138
112
 
 
113
    def open_display(self):
 
114
        pygtk = import_pygtk()
 
115
        try:
 
116
            import gtk
 
117
        except RuntimeError, e:
 
118
            if str(e) == "could not open display":
 
119
                raise NoDisplayError
 
120
        set_ui_factory()
 
121
        return gtk
 
122
 
139
123
    def run(self):
140
 
        open_display()
 
124
        self.open_display()
141
125
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
142
126
        dialog.run()
143
127
 
171
155
 
172
156
    def run(self, location="."):
173
157
        (br, path) = branch.Branch.open_containing(location)
174
 
        open_display()
 
158
        self.open_display()
175
159
        from push import PushDialog
176
160
        dialog = PushDialog(br.repository, br.last_revision(), br)
177
161
        dialog.run()
196
180
            if revision is not None:
197
181
                if len(revision) == 1:
198
182
                    tree1 = wt
199
 
                    revision_id = revision[0].as_revision_id(tree1.branch)
 
183
                    revision_id = revision[0].in_history(branch).rev_id
200
184
                    tree2 = branch.repository.revision_tree(revision_id)
201
185
                elif len(revision) == 2:
202
 
                    revision_id_0 = revision[0].as_revision_id(branch)
 
186
                    revision_id_0 = revision[0].in_history(branch).rev_id
203
187
                    tree2 = branch.repository.revision_tree(revision_id_0)
204
 
                    revision_id_1 = revision[1].as_revision_id(branch)
 
188
                    revision_id_1 = revision[1].in_history(branch).rev_id
205
189
                    tree1 = branch.repository.revision_tree(revision_id_1)
206
190
            else:
207
191
                tree1 = wt
229
213
            wt.unlock()
230
214
 
231
215
 
232
 
def start_viz_window(branch, revisions, limit=None):
 
216
def start_viz_window(branch, revision, limit=None):
233
217
    """Start viz on branch with revision revision.
234
218
    
235
219
    :return: The viz window object.
236
220
    """
237
221
    from viz import BranchWindow
238
 
    return BranchWindow(branch, revisions, limit)
 
222
    return BranchWindow(branch, revision, limit)
239
223
 
240
224
 
241
225
class cmd_visualise(Command):
251
235
        "revision",
252
236
        Option('limit', "Maximum number of revisions to display.",
253
237
               int, 'count')]
254
 
    takes_args = [ "locations*" ]
 
238
    takes_args = [ "location?" ]
255
239
    aliases = [ "visualize", "vis", "viz" ]
256
240
 
257
 
    def run(self, locations_list, revision=None, limit=None):
 
241
    def run(self, location=".", revision=None, limit=None):
258
242
        set_ui_factory()
259
 
        if locations_list is None:
260
 
            locations_list = ["."]
261
 
        revids = []
262
 
        for location in locations_list:
263
 
            (br, path) = branch.Branch.open_containing(location)
264
 
            if revision is None:
265
 
                revids.append(br.last_revision())
266
 
            else:
267
 
                revids.append(revision[0].as_revision_id(br))
 
243
        (br, path) = branch.Branch.open_containing(location)
 
244
        if revision is None:
 
245
            revid = br.last_revision()
 
246
            if revid is None:
 
247
                return
 
248
        else:
 
249
            (revno, revid) = revision[0].in_history(br)
 
250
 
268
251
        import gtk
269
 
        pp = start_viz_window(br, revids, limit)
 
252
        pp = start_viz_window(br, revid, limit)
270
253
        pp.connect("destroy", lambda w: gtk.main_quit())
271
254
        pp.show()
272
255
        gtk.main()
289
272
    aliases = ["gblame", "gpraise"]
290
273
    
291
274
    def run(self, filename, all=False, plain=False, line='1', revision=None):
292
 
        gtk = open_display()
 
275
        gtk = self.open_display()
293
276
 
294
277
        try:
295
278
            line = int(line)
314
297
        if revision is not None:
315
298
            if len(revision) != 1:
316
299
                raise BzrCommandError("Only 1 revion may be specified.")
317
 
            revision_id = revision[0].as_revision_id(br)
 
300
            revision_id = revision[0].in_history(br).rev_id
318
301
            tree = br.repository.revision_tree(revision_id)
319
302
        else:
320
303
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
321
304
 
322
 
        window = GAnnotateWindow(all, plain, branch=br)
 
305
        window = GAnnotateWindow(all, plain)
323
306
        window.connect("destroy", lambda w: gtk.main_quit())
 
307
        window.set_title(path + " - gannotate")
324
308
        config = GAnnotateConfig(window)
325
309
        window.show()
326
310
        br.lock_read()
348
332
 
349
333
    def run(self, filename=None):
350
334
        import os
351
 
        open_display()
 
335
        self.open_display()
352
336
        from commit import CommitDialog
353
337
        from bzrlib.errors import (BzrCommandError,
354
338
                                   NotBranchError,
361
345
            br = wt.branch
362
346
        except NoWorkingTree, e:
363
347
            from dialog import error_dialog
364
 
            error_dialog(_i18n('Directory does not have a working tree'),
365
 
                         _i18n('Operation aborted.'))
 
348
            error_dialog(_('Directory does not have a working tree'),
 
349
                         _('Operation aborted.'))
366
350
            return 1 # should this be retval=3?
367
351
 
368
352
        # It is a good habit to keep things locked for the duration, but it
385
369
    
386
370
    aliases = [ "gst" ]
387
371
    takes_args = ['PATH?']
388
 
    takes_options = ['revision']
 
372
    takes_options = []
389
373
 
390
 
    def run(self, path='.', revision=None):
 
374
    def run(self, path='.'):
391
375
        import os
392
 
        gtk = open_display()
 
376
        gtk = self.open_display()
393
377
        from status import StatusDialog
394
378
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
395
 
        
396
 
        if revision is not None:
397
 
            try:
398
 
                revision_id = revision[0].as_revision_id(wt.branch)
399
 
            except:
400
 
                from bzrlib.errors import BzrError
401
 
                raise BzrError('Revision %r doesn\'t exist' % revision[0].user_spec )
402
 
        else:
403
 
            revision_id = None
404
 
 
405
 
        status = StatusDialog(wt, wt_path, revision_id)
 
379
        status = StatusDialog(wt, wt_path)
406
380
        status.connect("destroy", gtk.main_quit)
407
381
        status.run()
408
382
 
413
387
    """
414
388
    def run(self):
415
389
        (br, path) = branch.Branch.open_containing(".")
416
 
        gtk = open_display()
 
390
        gtk = self.open_display()
417
391
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
418
392
        from StringIO import StringIO
419
393
        dialog = SendMergeDirectiveDialog(br)
435
409
    """
436
410
    def run(self):
437
411
        (wt, path) = workingtree.WorkingTree.open_containing('.')
438
 
        open_display()
 
412
        self.open_display()
439
413
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
440
414
        dialog = ConflictsDialog(wt)
441
415
        dialog.run()
446
420
 
447
421
    """
448
422
    def run(self):
449
 
        open_display()
 
423
        self.open_display()
450
424
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
451
425
        dialog = PreferencesWindow()
452
426
        dialog.run()
453
427
 
454
428
 
455
 
class cmd_gmerge(Command):
456
 
    """ GTK+ merge dialog
457
 
    
458
 
    """
459
 
    takes_args = ["merge_from_path?"]
460
 
    def run(self, merge_from_path=None):
461
 
        from bzrlib import workingtree
462
 
        from bzrlib.plugins.gtk.dialog import error_dialog
463
 
        from bzrlib.plugins.gtk.merge import MergeDialog
464
 
        
465
 
        (wt, path) = workingtree.WorkingTree.open_containing('.')
466
 
        old_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
467
 
        delta = wt.changes_from(old_tree)
468
 
        if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
469
 
            error_dialog(_i18n('There are local changes in the branch'),
470
 
                         _i18n('Please commit or revert the changes before merging.'))
471
 
        else:
472
 
            parent_branch_path = wt.branch.get_parent()
473
 
            merge = MergeDialog(wt, path, parent_branch_path)
474
 
            response = merge.run()
475
 
            merge.destroy()
476
 
 
477
 
 
478
429
class cmd_gmissing(Command):
479
430
    """ GTK+ missing revisions dialog.
480
431
 
513
464
 
514
465
class cmd_ginit(GTKCommand):
515
466
    def run(self):
516
 
        open_display()
 
467
        self.open_display()
517
468
        from initialize import InitDialog
518
469
        dialog = InitDialog(os.path.abspath(os.path.curdir))
519
470
        dialog.run()
523
474
    def run(self):
524
475
        br = branch.Branch.open_containing('.')[0]
525
476
        
526
 
        gtk = open_display()
 
477
        gtk = self.open_display()
527
478
        from tags import TagsWindow
528
479
        window = TagsWindow(br)
529
480
        window.show()
538
489
    cmd_gconflicts, 
539
490
    cmd_gdiff,
540
491
    cmd_ginit,
541
 
    cmd_gmerge,
542
492
    cmd_gmissing, 
543
493
    cmd_gpreferences, 
544
494
    cmd_gpush, 
552
502
    register_command(cmd)
553
503
 
554
504
 
 
505
class cmd_commit_notify(GTKCommand):
 
506
    """Run the bzr commit notifier.
 
507
 
 
508
    This is a background program which will pop up a notification on the users
 
509
    screen when a commit occurs.
 
510
    """
 
511
 
 
512
    def run(self):
 
513
        from notify import NotifyPopupMenu
 
514
        gtk = self.open_display()
 
515
        menu = NotifyPopupMenu()
 
516
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
517
        icon.connect('popup-menu', menu.display)
 
518
 
 
519
        import cgi
 
520
        import dbus
 
521
        import dbus.service
 
522
        import pynotify
 
523
        from bzrlib.bzrdir import BzrDir
 
524
        from bzrlib import errors
 
525
        from bzrlib.osutils import format_date
 
526
        from bzrlib.transport import get_transport
 
527
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
528
            import dbus.glib
 
529
        from bzrlib.plugins.dbus import activity
 
530
        bus = dbus.SessionBus()
 
531
        # get the object so we can subscribe to callbacks from it.
 
532
        broadcast_service = bus.get_object(
 
533
            activity.Broadcast.DBUS_NAME,
 
534
            activity.Broadcast.DBUS_PATH)
 
535
 
 
536
        def catch_branch(revision_id, urls):
 
537
            # TODO: show all the urls, or perhaps choose the 'best'.
 
538
            url = urls[0]
 
539
            try:
 
540
                if isinstance(revision_id, unicode):
 
541
                    revision_id = revision_id.encode('utf8')
 
542
                transport = get_transport(url)
 
543
                a_dir = BzrDir.open_from_transport(transport)
 
544
                branch = a_dir.open_branch()
 
545
                revno = branch.revision_id_to_revno(revision_id)
 
546
                revision = branch.repository.get_revision(revision_id)
 
547
                summary = 'New revision %d in %s' % (revno, url)
 
548
                body  = 'Committer: %s\n' % revision.committer
 
549
                body += 'Date: %s\n' % format_date(revision.timestamp,
 
550
                    revision.timezone)
 
551
                body += '\n'
 
552
                body += revision.message
 
553
                body = cgi.escape(body)
 
554
                nw = pynotify.Notification(summary, body)
 
555
                def start_viz(notification=None, action=None, data=None):
 
556
                    """Start the viz program."""
 
557
                    pp = start_viz_window(branch, revision_id)
 
558
                    pp.show()
 
559
                def start_branch(notification=None, action=None, data=None):
 
560
                    """Start a Branch dialog"""
 
561
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
562
                    bd = BranchDialog(remote_path=url)
 
563
                    bd.run()
 
564
                nw.add_action("inspect", "Inspect", start_viz, None)
 
565
                nw.add_action("branch", "Branch", start_branch, None)
 
566
                nw.set_timeout(5000)
 
567
                nw.show()
 
568
            except Exception, e:
 
569
                print e
 
570
                raise
 
571
        broadcast_service.connect_to_signal("Revision", catch_branch,
 
572
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
573
        pynotify.init("bzr commit-notify")
 
574
        gtk.main()
 
575
 
 
576
register_command(cmd_commit_notify)
 
577
 
 
578
 
555
579
class cmd_gselftest(GTKCommand):
556
580
    """Version of selftest that displays a notification at the end"""
557
581
 
648
672
register_command(cmd_test_gtk)
649
673
 
650
674
 
651
 
 
652
675
import gettext
653
676
gettext.install('olive-gtk')
654
677
 
655
 
# Let's create a specialized alias to protect '_' from being erased by other
656
 
# uses of '_' as an anonymous variable (think pdb for one).
657
 
_i18n = gettext.gettext
658
678
 
659
679
class NoDisplayError(BzrCommandError):
660
680
    """gtk could not find a proper display"""