/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: 2007-10-14 15:54:57 UTC
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: daniel.schierbeck@gmail.com-20071014155457-m3ek29p4ima8ev7d
Added the new Window base class.

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'
20
 
version_info = tuple(int(n) for n in __version__.split('.'))
 
36
version_info = (0, 92, 0, 'dev', 0)
21
37
 
 
38
if version_info[3] == 'final':
 
39
    version_string = '%d.%d.%d' % version_info[:3]
 
40
else:
 
41
    version_string = '%d.%d.%d%s%d' % version_info
 
42
__version__ = version_string
22
43
 
23
44
def check_bzrlib_version(desired):
24
45
    """Check that bzrlib is compatible.
30
51
    """
31
52
    desired_plus = (desired[0], desired[1]+1)
32
53
    bzrlib_version = bzrlib.version_info[:2]
33
 
    if bzrlib_version == desired:
 
54
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
 
55
                                     bzrlib.version_info[3] == 'dev'):
34
56
        return
35
57
    try:
36
58
        from bzrlib.trace import warning
38
60
        # get the message out any way we can
39
61
        from warnings import warn as warning
40
62
    if bzrlib_version < desired:
41
 
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
 
63
        from bzrlib.errors import BzrError
 
64
        warning('Installed Bazaar version %s is too old to be used with bzr-gtk'
42
65
                ' %s.' % (bzrlib.__version__, __version__))
43
 
        raise BzrError('Version mismatch: %r' % version_info)
 
66
        raise BzrError('Version mismatch: %r, %r' % (version_info, bzrlib.version_info) )
44
67
    else:
45
68
        warning('bzr-gtk is not up to date with installed bzr version %s.'
46
69
                ' \nThere should be a newer version available, e.g. %i.%i.' 
47
70
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
48
 
        if bzrlib_version != desired_plus:
49
 
            raise Exception, 'Version mismatch'
50
 
 
51
 
 
52
 
check_bzrlib_version(version_info[:2])
 
71
 
 
72
 
 
73
if version_info[2] == "final":
 
74
    check_bzrlib_version(version_info[:2])
53
75
 
54
76
from bzrlib.trace import warning
55
77
if __name__ != 'bzrlib.plugins.gtk':
59
81
lazy_import(globals(), """
60
82
from bzrlib import (
61
83
    branch,
 
84
    builtins,
62
85
    errors,
63
86
    workingtree,
64
87
    )
86
109
    bzrlib.ui.ui_factory = GtkUIFactory()
87
110
 
88
111
 
 
112
def data_path():
 
113
    return os.path.dirname(__file__)
 
114
 
 
115
 
89
116
class GTKCommand(Command):
90
117
    """Abstract class providing GTK specific run commands."""
91
118
 
136
163
        (br, path) = branch.Branch.open_containing(location)
137
164
        self.open_display()
138
165
        from push import PushDialog
139
 
        dialog = PushDialog(br)
 
166
        dialog = PushDialog(br.repository, br.last_revision(), br)
140
167
        dialog.run()
141
168
 
142
169
 
192
219
            wt.unlock()
193
220
 
194
221
 
 
222
def start_viz_window(branch, revision, limit=None):
 
223
    """Start viz on branch with revision revision.
 
224
    
 
225
    :return: The viz window object.
 
226
    """
 
227
    from viz.branchwin import BranchWindow
 
228
    branch.lock_read()
 
229
    pp = BranchWindow()
 
230
    pp.set_branch(branch, revision, limit)
 
231
    # cleanup locks when the window is closed
 
232
    pp.connect("destroy", lambda w: branch.unlock())
 
233
    return pp
 
234
 
 
235
 
195
236
class cmd_visualise(Command):
196
237
    """Graphically visualise this branch.
197
238
 
203
244
    """
204
245
    takes_options = [
205
246
        "revision",
206
 
        Option('limit', "maximum number of revisions to display",
 
247
        Option('limit', "Maximum number of revisions to display.",
207
248
               int, 'count')]
208
249
    takes_args = [ "location?" ]
209
250
    aliases = [ "visualize", "vis", "viz" ]
212
253
        set_ui_factory()
213
254
        (br, path) = branch.Branch.open_containing(location)
214
255
        br.lock_read()
215
 
        br.repository.lock_read()
216
256
        try:
217
257
            if revision is None:
218
258
                revid = br.last_revision()
221
261
            else:
222
262
                (revno, revid) = revision[0].in_history(br)
223
263
 
224
 
            from viz.branchwin import BranchWindow
225
264
            import gtk
226
 
                
227
 
            pp = BranchWindow()
228
 
            pp.set_branch(br, revid, limit)
 
265
            pp = start_viz_window(br, revid, limit)
229
266
            pp.connect("destroy", lambda w: gtk.main_quit())
230
267
            pp.show()
231
268
            gtk.main()
232
269
        finally:
233
 
            br.repository.unlock()
234
270
            br.unlock()
235
271
 
236
272
 
242
278
 
243
279
    takes_args = ["filename", "line?"]
244
280
    takes_options = [
245
 
        Option("all", help="show annotations on all lines"),
246
 
        Option("plain", help="don't highlight annotation lines"),
 
281
        Option("all", help="Show annotations on all lines."),
 
282
        Option("plain", help="Don't highlight annotation lines."),
247
283
        Option("line", type=int, argname="lineno",
248
 
               help="jump to specified line number"),
 
284
               help="Jump to specified line number."),
249
285
        "revision",
250
286
    ]
251
287
    aliases = ["gblame", "gpraise"]
353
389
 
354
390
 
355
391
class cmd_gconflicts(GTKCommand):
356
 
    """ GTK+ push.
 
392
    """ GTK+ conflicts.
357
393
    
 
394
    Select files from the list of conflicts and run an external utility to
 
395
    resolve them.
358
396
    """
359
397
    def run(self):
360
398
        (wt, path) = workingtree.WorkingTree.open_containing('.')
460
498
    """
461
499
 
462
500
    def run(self):
 
501
        from notify import NotifyPopupMenu
463
502
        gtk = self.open_display()
 
503
        menu = NotifyPopupMenu()
 
504
        icon = gtk.status_icon_new_from_file(os.path.join(data_path(), "bzr-icon-64.png"))
 
505
        icon.connect('popup-menu', menu.display)
 
506
 
464
507
        import cgi
465
508
        import dbus
466
509
        import dbus.service
477
520
        broadcast_service = bus.get_object(
478
521
            activity.Broadcast.DBUS_NAME,
479
522
            activity.Broadcast.DBUS_PATH)
 
523
 
480
524
        def catch_branch(revision_id, urls):
481
525
            # TODO: show all the urls, or perhaps choose the 'best'.
482
526
            url = urls[0]
496
540
                body += revision.message
497
541
                body = cgi.escape(body)
498
542
                nw = pynotify.Notification(summary, body)
 
543
                def start_viz(notification=None, action=None, data=None):
 
544
                    """Start the viz program."""
 
545
                    pp = start_viz_window(branch, revision_id)
 
546
                    pp.show()
 
547
                def start_branch(notification=None, action=None, data=None):
 
548
                    """Start a Branch dialog"""
 
549
                    from bzrlib.plugins.gtk.branch import BranchDialog
 
550
                    bd = BranchDialog(remote_path=url)
 
551
                    bd.run()
 
552
                nw.add_action("inspect", "Inspect", start_viz, None)
 
553
                nw.add_action("branch", "Branch", start_branch, None)
499
554
                nw.set_timeout(5000)
500
555
                nw.show()
501
556
            except Exception, e:
509
564
register_command(cmd_commit_notify)
510
565
 
511
566
 
 
567
class cmd_gselftest(GTKCommand):
 
568
    """Version of selftest that displays a notification at the end"""
 
569
 
 
570
    takes_args = builtins.cmd_selftest.takes_args
 
571
    takes_options = builtins.cmd_selftest.takes_options
 
572
    _see_also = ['selftest']
 
573
 
 
574
    def run(self, *args, **kwargs):
 
575
        import cgi
 
576
        import sys
 
577
        default_encoding = sys.getdefaultencoding()
 
578
        # prevent gtk from blowing up later
 
579
        gtk = import_pygtk()
 
580
        # prevent gtk from messing with default encoding
 
581
        import pynotify
 
582
        if sys.getdefaultencoding() != default_encoding:
 
583
            reload(sys)
 
584
            sys.setdefaultencoding(default_encoding)
 
585
        result = builtins.cmd_selftest().run(*args, **kwargs)
 
586
        if result == 0:
 
587
            summary = 'Success'
 
588
            body = 'Selftest succeeded in "%s"' % os.getcwd()
 
589
        if result == 1:
 
590
            summary = 'Failure'
 
591
            body = 'Selftest failed in "%s"' % os.getcwd()
 
592
        pynotify.init("bzr gselftest")
 
593
        note = pynotify.Notification(cgi.escape(summary), cgi.escape(body))
 
594
        note.set_timeout(pynotify.EXPIRES_NEVER)
 
595
        note.show()
 
596
 
 
597
 
 
598
register_command(cmd_gselftest)
 
599
 
 
600
 
512
601
import gettext
513
602
gettext.install('olive-gtk')
514
603