/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: Szilveszter Farkas (Phanatic)
  • Date: 2007-08-16 07:17:26 UTC
  • mfrom: (257 trunk)
  • mto: This revision was merged to the branch mainline in revision 258.
  • Revision ID: szilveszter.farkas@gmail.com-20070816071726-3d3y82e7v7qo4ytt
Merge the changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# along with this program; if not, write to the Free Software
13
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
14
 
15
 
"""GTK+ frontends to Bazaar commands """
 
15
"""Graphical support for Bazaar using GTK.
 
16
 
 
17
This plugin includes:
 
18
commit-notify     Start the graphical notifier of commits.
 
19
gannotate         GTK+ annotate. 
 
20
gbranch           GTK+ branching. 
 
21
gcheckout         GTK+ checkout. 
 
22
gcommit           GTK+ commit dialog 
 
23
gconflicts        GTK+ conflicts. 
 
24
gdiff             Show differences in working tree in a GTK+ Window. 
 
25
ginit             Initialise a new branch.
 
26
gmissing          GTK+ missing revisions dialog. 
 
27
gpreferences      GTK+ preferences dialog. 
 
28
gpush             GTK+ push. 
 
29
gstatus           GTK+ status dialog 
 
30
gtags             Manage branch tags.
 
31
visualise         Graphically visualise this branch. 
 
32
"""
16
33
 
17
34
import bzrlib
18
35
 
19
 
__version__ = '0.17.0'
 
36
__version__ = '0.90.0'
20
37
version_info = tuple(int(n) for n in __version__.split('.'))
21
38
 
22
39
 
39
56
        # get the message out any way we can
40
57
        from warnings import warn as warning
41
58
    if bzrlib_version < desired:
 
59
        from bzrlib.errors import BzrError
42
60
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
43
61
                ' %s.' % (bzrlib.__version__, __version__))
44
62
        raise BzrError('Version mismatch: %r' % version_info)
46
64
        warning('bzr-gtk is not up to date with installed bzr version %s.'
47
65
                ' \nThere should be a newer version available, e.g. %i.%i.' 
48
66
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
 
        if bzrlib_version != desired_plus:
50
 
            raise Exception, 'Version mismatch'
51
67
 
52
68
 
53
69
check_bzrlib_version(version_info[:2])
60
76
lazy_import(globals(), """
61
77
from bzrlib import (
62
78
    branch,
 
79
    builtins,
63
80
    errors,
64
81
    workingtree,
65
82
    )
87
104
    bzrlib.ui.ui_factory = GtkUIFactory()
88
105
 
89
106
 
 
107
def data_path():
 
108
    return os.path.dirname(__file__)
 
109
 
 
110
 
90
111
class GTKCommand(Command):
91
112
    """Abstract class providing GTK specific run commands."""
92
113
 
137
158
        (br, path) = branch.Branch.open_containing(location)
138
159
        self.open_display()
139
160
        from push import PushDialog
140
 
        dialog = PushDialog(br)
 
161
        dialog = PushDialog(br.repository, br.last_revision(), br)
141
162
        dialog.run()
142
163
 
143
164
 
193
214
            wt.unlock()
194
215
 
195
216
 
 
217
def start_viz_window(branch, revision, limit=None):
 
218
    """Start viz on branch with revision revision.
 
219
    
 
220
    :return: The viz window object.
 
221
    """
 
222
    from viz.branchwin import BranchWindow
 
223
    branch.lock_read()
 
224
    pp = BranchWindow()
 
225
    pp.set_branch(branch, revision, limit)
 
226
    # cleanup locks when the window is closed
 
227
    pp.connect("destroy", lambda w: branch.unlock())
 
228
    return pp
 
229
 
 
230
 
196
231
class cmd_visualise(Command):
197
232
    """Graphically visualise this branch.
198
233
 
204
239
    """
205
240
    takes_options = [
206
241
        "revision",
207
 
        Option('limit', "maximum number of revisions to display",
 
242
        Option('limit', "Maximum number of revisions to display.",
208
243
               int, 'count')]
209
244
    takes_args = [ "location?" ]
210
245
    aliases = [ "visualize", "vis", "viz" ]
213
248
        set_ui_factory()
214
249
        (br, path) = branch.Branch.open_containing(location)
215
250
        br.lock_read()
216
 
        br.repository.lock_read()
217
251
        try:
218
252
            if revision is None:
219
253
                revid = br.last_revision()
222
256
            else:
223
257
                (revno, revid) = revision[0].in_history(br)
224
258
 
225
 
            from viz.branchwin import BranchWindow
226
259
            import gtk
227
 
                
228
 
            pp = BranchWindow()
229
 
            pp.set_branch(br, revid, limit)
 
260
            pp = start_viz_window(br, revid, limit)
230
261
            pp.connect("destroy", lambda w: gtk.main_quit())
231
262
            pp.show()
232
263
            gtk.main()
233
264
        finally:
234
 
            br.repository.unlock()
235
265
            br.unlock()
236
266
 
237
267
 
243
273
 
244
274
    takes_args = ["filename", "line?"]
245
275
    takes_options = [
246
 
        Option("all", help="show annotations on all lines"),
247
 
        Option("plain", help="don't highlight annotation lines"),
 
276
        Option("all", help="Show annotations on all lines."),
 
277
        Option("plain", help="Don't highlight annotation lines."),
248
278
        Option("line", type=int, argname="lineno",
249
 
               help="jump to specified line number"),
 
279
               help="Jump to specified line number."),
250
280
        "revision",
251
281
    ]
252
282
    aliases = ["gblame", "gpraise"]
354
384
 
355
385
 
356
386
class cmd_gconflicts(GTKCommand):
357
 
    """ GTK+ push.
 
387
    """ GTK+ conflicts.
358
388
    
 
389
    Select files from the list of conflicts and run an external utility to
 
390
    resolve them.
359
391
    """
360
392
    def run(self):
361
393
        (wt, path) = workingtree.WorkingTree.open_containing('.')
461
493
    """
462
494
 
463
495
    def run(self):
 
496
        from notify import NotifyPopupMenu
464
497
        gtk = self.open_display()
 
498
        menu = NotifyPopupMenu()
 
499
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
500
        icon.connect('popup-menu', menu.display)
 
501
 
465
502
        import cgi
466
503
        import dbus
467
504
        import dbus.service
478
515
        broadcast_service = bus.get_object(
479
516
            activity.Broadcast.DBUS_NAME,
480
517
            activity.Broadcast.DBUS_PATH)
 
518
 
481
519
        def catch_branch(revision_id, urls):
482
520
            # TODO: show all the urls, or perhaps choose the 'best'.
483
521
            url = urls[0]
497
535
                body += revision.message
498
536
                body = cgi.escape(body)
499
537
                nw = pynotify.Notification(summary, body)
 
538
                def start_viz(notification=None, action=None, data=None):
 
539
                    """Start the viz program."""
 
540
                    pp = start_viz_window(branch, revision_id)
 
541
                    pp.show()
 
542
                def start_branch(notification=None, action=None, data=None):
 
543
                    """Start a Branch dialog"""
 
544
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
545
                    bd = BranchDialog(remote_path=url)
 
546
                    bd.run()
 
547
                nw.add_action("inspect", "Inspect", start_viz, None)
 
548
                nw.add_action("branch", "Branch", start_branch, None)
500
549
                nw.set_timeout(5000)
501
550
                nw.show()
502
551
            except Exception, e:
510
559
register_command(cmd_commit_notify)
511
560
 
512
561
 
 
562
class cmd_gselftest(GTKCommand):
 
563
    """Version of selftest that displays a notification at the end"""
 
564
 
 
565
    takes_args = builtins.cmd_selftest.takes_args
 
566
    takes_options = builtins.cmd_selftest.takes_options
 
567
    _see_also = ['selftest']
 
568
 
 
569
    def run(self, *args, **kwargs):
 
570
        import cgi
 
571
        import sys
 
572
        default_encoding = sys.getdefaultencoding()
 
573
        # prevent gtk from blowing up later
 
574
        gtk = import_pygtk()
 
575
        # prevent gtk from messing with default encoding
 
576
        import pynotify
 
577
        if sys.getdefaultencoding() != default_encoding:
 
578
            reload(sys)
 
579
            sys.setdefaultencoding(default_encoding)
 
580
        result = builtins.cmd_selftest().run(*args, **kwargs)
 
581
        if result == 0:
 
582
            summary = 'Success'
 
583
            body = 'Selftest succeeded in "%s"' % os.getcwd()
 
584
        if result == 1:
 
585
            summary = 'Failure'
 
586
            body = 'Selftest failed in "%s"' % os.getcwd()
 
587
        pynotify.init("bzr gselftest")
 
588
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
 
589
        note.set_timeout(pynotify.EXPIRES_NEVER)
 
590
        note.show()
 
591
 
 
592
 
 
593
register_command(cmd_gselftest)
 
594
 
 
595
 
513
596
import gettext
514
597
gettext.install('olive-gtk')
515
598