Read about our upcoming Code of Conduct on this issue

quickbar.py 1.93 KB
Newer Older
Adrian Buehlmann's avatar
Adrian Buehlmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
"""
Qt4 QToolBar-based class for quick bars XXX
"""

20
21
from PyQt4.QtCore import *
from PyQt4.QtGui import *
22

23
from tortoisehg.hgqt.i18n import _
Yuki KODAMA's avatar
Yuki KODAMA committed
24
from tortoisehg.hgqt.qtlib import geticon
Adrian Buehlmann's avatar
Adrian Buehlmann committed
25

26
27
28
29
30
class GotoQuickBar(QToolBar):
    gotoSignal = pyqtSignal(QString)

    def __init__(self, parent):
        QToolBar.__init__(self, _('Goto'), parent)
31
        self.setIconSize(QSize(16,16))
Adrian Buehlmann's avatar
Adrian Buehlmann committed
32
33
34
35
        self.setFloatable(False)
        self.setMovable(False)
        self.setAllowedAreas(Qt.BottomToolBarArea)
        self.setVisible(False)
36
37
        self.goAction = QAction(geticon('go-jump'), _('Go'), self)
        self.goAction.triggered.connect(self.goto)
38
        self.entry = QLineEdit(self)
39
        self.entry.returnPressed.connect(self.goAction.trigger)
40
        self.addWidget(self.entry)
41
42
43
44
        self.addAction(self.goAction)

    def goto(self):
        self.gotoSignal.emit(self.entry.text())
45
46

    def setVisible(self, visible=True):
47
        super(GotoQuickBar, self).setVisible(visible)
48
49
50
51
52
        if visible:
            self.entry.setFocus()
            self.entry.selectAll()

    def setCompletionKeys(self, keys):
53
        self.entry.setCompleter(QCompleter(keys, self))