|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to get the data to rename a bookmark. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt4.QtCore import pyqtSlot |
|
13 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
14 |
|
15 from .Ui_HgBookmarkRenameDialog import Ui_HgBookmarkRenameDialog |
|
16 |
|
17 |
|
18 class HgBookmarkRenameDialog(QDialog, Ui_HgBookmarkRenameDialog): |
|
19 """ |
|
20 Class implementing a dialog to get the data to rename a bookmark. |
|
21 """ |
|
22 def __init__(self, bookmarksList, parent=None): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param bookmarksList list of bookmarks (list of strings) |
|
27 @param parent reference to the parent widget (QWidget) |
|
28 """ |
|
29 super(HgBookmarkRenameDialog, self).__init__(parent) |
|
30 self.setupUi(self) |
|
31 |
|
32 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
33 |
|
34 self.bookmarkCombo.addItems(sorted(bookmarksList)) |
|
35 |
|
36 msh = self.minimumSizeHint() |
|
37 self.resize(max(self.width(), msh.width()), msh.height()) |
|
38 |
|
39 def __updateUI(self): |
|
40 """ |
|
41 Private slot to update the UI. |
|
42 """ |
|
43 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
44 self.nameEdit.text() != "" and |
|
45 self.bookmarkCombo.currentText() != "" |
|
46 ) |
|
47 |
|
48 @pyqtSlot(str) |
|
49 def on_nameEdit_textChanged(self, txt): |
|
50 """ |
|
51 Private slot to handle changes of the bookmark name. |
|
52 |
|
53 @param txt text of the edit (string) |
|
54 """ |
|
55 self.__updateUI() |
|
56 |
|
57 @pyqtSlot(str) |
|
58 def on_bookmarkCombo_editTextChanged(self, txt): |
|
59 """ |
|
60 Private slot to handle changes of the selected bookmark. |
|
61 |
|
62 @param txt name of the selected bookmark (string) |
|
63 """ |
|
64 self.__updateUI() |
|
65 |
|
66 def getData(self): |
|
67 """ |
|
68 Public method to retrieve the entered data. |
|
69 |
|
70 @return tuple naming the new and old bookmark names |
|
71 (string, string) |
|
72 """ |
|
73 return ( |
|
74 self.nameEdit.text().replace(" ", "_"), |
|
75 self.bookmarkCombo.currentText().replace(" ", "_") |
|
76 ) |