PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/tortoisehg/hgtk/gorev.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 65 lines | 45 code | 13 blank | 7 comment | 1 complexity | eef824162852da89c4feb2dc94d6a696 MD5 | raw file
 1# gorev.py - TortoiseHg's dialog for selecting a revision
 2#
 3# Copyright 2007 TK Soh <teekaysoh@gmail.com>
 4# Copyright 2007 Steve Borho <steve@borho.org>
 5#
 6# This software may be used and distributed according to the terms of the
 7# GNU General Public License version 2, incorporated herein by reference.
 8
 9import os
10import gtk
11import gobject
12
13from mercurial import error
14
15from tortoisehg.util.i18n import _
16from tortoisehg.hgtk import gtklib, gdialog
17
18
19class GotoRevDialog(gtk.Dialog):
20    'Dialog for selecting a revision'
21    def __init__(self, gotofunc):
22        super(GotoRevDialog, self).__init__(flags=gtk.DIALOG_MODAL)
23        gtklib.set_tortoise_icon(self, 'menulog.ico')
24        gtklib.set_tortoise_keys(self)
25        self.set_has_separator(False)
26
27        self._btn_goto = gtk.Button(_('Select'))
28        self._btn_goto.connect('clicked', self._btn_goto_clicked)
29        self.action_area.pack_end(self._btn_goto)
30
31        self.set_title(_('Select Revision'))
32
33        self.gotofunc = gotofunc
34
35        self.tips = gtklib.Tooltips()
36
37        hbox = gtk.HBox()
38        self.revEntry = gtk.Entry()
39        self.revEntry.connect('activate', self._btn_goto_clicked)
40        hbox.pack_start(self.revEntry, True, True, 4)
41        eventbox = gtk.EventBox()
42        eventbox.add(hbox)
43        self.tips.set_tip(
44            eventbox, _('revision number, changeset ID, branch or tag'))
45        self.vbox.pack_start(eventbox, False, False, 4)
46
47        self.revEntry.grab_focus()
48
49        self.show_all()
50
51    def _btn_goto_clicked(self, button, data=None):
52        try:
53            revision = self.revEntry.get_text()
54            if self.gotofunc:
55                self.gotofunc(revision)
56            self.revEntry.set_text('')
57            self.hide()
58        except error.LookupError, e:
59            gdialog.Prompt(_('Ambiguous Revision'), str(e), self).run()
60            self.revEntry.grab_focus()
61            return
62        except error.RepoError, e:
63            gdialog.Prompt(_('Invalid Revision'), str(e), self).run()
64            self.revEntry.grab_focus()
65            return