~ian-clatworthy/bzr-explorer/extensible-init-workspace

« back to all changes in this revision

Viewing changes to lib/tool_dialogs.py

  • Committer: Ian Clatworthy
  • Date: 2009-12-10 02:28:02 UTC
  • mfrom: (331.1.2 new-tool-dialog)
  • Revision ID: ian.clatworthy@canonical.com-20091210022802-nkjydulhc3m6vshx
Add Tool dialog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from PyQt4 import QtCore, QtGui
 
18
 
 
19
from bzrlib.plugins.explorer.lib import tools
 
20
from bzrlib.plugins.explorer.lib.i18n import gettext, N_
 
21
 
 
22
 
 
23
class AddToolDialog(QtGui.QDialog):
 
24
 
 
25
    def __init__(self, parent=None):
 
26
        super(AddToolDialog, self).__init__(parent)
 
27
        self.setWindowTitle(gettext("Add Tool"))
 
28
        self.setLayout(self._build_layout())
 
29
 
 
30
    def _build_layout(self):
 
31
        # Build the form
 
32
        self.title_field = QtGui.QLineEdit()
 
33
        self.type_field = self._build_combo([
 
34
            ('bzr', gettext("Bazaar Command")),
 
35
            ('link', gettext("Web Link")),
 
36
            ('application', gettext("Local Application")),
 
37
            ])
 
38
        self.action_field = QtGui.QLineEdit()
 
39
        form = QtGui.QFormLayout()
 
40
        form.addRow(gettext("Title"), self.title_field)
 
41
        form.addRow(gettext("Type"), self.type_field)
 
42
        form.addRow(gettext("Command"), self.action_field)
 
43
 
 
44
        # Add in the buttons
 
45
        buttons = QtGui.QDialogButtonBox(
 
46
            QtGui.QDialogButtonBox.Ok |
 
47
            QtGui.QDialogButtonBox.Cancel)
 
48
        self.connect(buttons, QtCore.SIGNAL("accepted()"), self,
 
49
            QtCore.SLOT("accept()"))
 
50
        self.connect(buttons, QtCore.SIGNAL("rejected()"), self,
 
51
            QtCore.SLOT("reject()"))
 
52
 
 
53
        # Put it all together
 
54
        layout = QtGui.QVBoxLayout()
 
55
        layout.addLayout(form)
 
56
        layout.addWidget(buttons)
 
57
        return layout
 
58
 
 
59
    def _build_combo(self, data_label_tuples):
 
60
        combo = QtGui.QComboBox()
 
61
        for data, label in data_label_tuples:
 
62
            combo.addItem(label, data)
 
63
        return combo
 
64
 
 
65
    def get_tool(self):
 
66
        """Get the added tool."""
 
67
        title = unicode(self.title_field.text()).strip()
 
68
        type_index = self.type_field.currentIndex()
 
69
        type = unicode(self.type_field.itemData(type_index).toString())
 
70
        action = unicode(self.action_field.text()).strip()
 
71
        return tools.Tool(title, type, action)