Plugins/VcsPlugins/vcsMercurial/HgCopyDialog.py

Mon, 25 Mar 2013 03:11:06 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 25 Mar 2013 03:11:06 +0100
branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2357
f6a2cbf3f514
child 3057
10516539f238
permissions
-rw-r--r--

Script changes: Future import added, super calls modified and unicode behavior for str.

178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1885
diff changeset
3 # Copyright (c) 2010 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to enter the data for a copy or rename operation.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2357
diff changeset
10 from __future__ import unicode_literals # __IGNORE_WARNING__
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2357
diff changeset
11
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os.path
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from PyQt4.QtCore import pyqtSlot
1885
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
15 from PyQt4.QtGui import QDialog, QDialogButtonBox
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui.E5Completers import E5FileCompleter, E5DirCompleter
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
18 from E5Gui import E5FileDialog
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from .Ui_HgCopyDialog import Ui_HgCopyDialog
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
2357
f6a2cbf3f514 Fixed a bug in the VCS copy dialogs causing a failure on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
22 import Utilities
f6a2cbf3f514 Fixed a bug in the VCS copy dialogs causing a failure on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
23
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
24
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 class HgCopyDialog(QDialog, Ui_HgCopyDialog):
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Class implementing a dialog to enter the data for a copy or rename operation.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
29 def __init__(self, source, parent=None, move=False, force=False):
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Constructor
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param source name of the source file/directory (string)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param parent parent widget (QWidget)
1885
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
35 @param move flag indicating a move operation (boolean)
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param force flag indicating a forced operation (boolean)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2357
diff changeset
38 super(HgCopyDialog, self).__init__(parent)
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.setupUi(self)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.source = source
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 if os.path.isdir(self.source):
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.targetCompleter = E5DirCompleter(self.targetEdit)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 else:
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.targetCompleter = E5FileCompleter(self.targetEdit)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if move:
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.setWindowTitle(self.trUtf8('Mercurial Move'))
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 else:
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.forceCheckBox.setEnabled(False)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.forceCheckBox.setChecked(force)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.sourceEdit.setText(source)
1885
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
54
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
55 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 def getData(self):
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 Public method to retrieve the copy data.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @return the target name (string) and a flag indicating
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 the operation should be enforced (boolean)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 """
1885
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
64 target = self.targetEdit.text()
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
65 if not os.path.isabs(target):
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
66 sourceDir = os.path.dirname(self.sourceEdit.text())
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
67 target = os.path.join(sourceDir, target)
2357
f6a2cbf3f514 Fixed a bug in the VCS copy dialogs causing a failure on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
68 return Utilities.toNativeSeparators(target), self.forceCheckBox.isChecked()
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @pyqtSlot()
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 def on_dirButton_clicked(self):
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
73 Private slot to handle the button press for selecting the target via a
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 selection dialog.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 if os.path.isdir(self.source):
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
77 target = E5FileDialog.getExistingDirectory(
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self,
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.trUtf8("Select target"),
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.targetEdit.text(),
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
81 E5FileDialog.Options(E5FileDialog.ShowDirsOnly))
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 else:
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
83 target = E5FileDialog.getSaveFileName(
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self,
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.trUtf8("Select target"),
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.targetEdit.text(),
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 "",
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
88 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if target:
2357
f6a2cbf3f514 Fixed a bug in the VCS copy dialogs causing a failure on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
91 self.targetEdit.setText(Utilities.toNativeSeparators(target))
1885
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
92
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
93 @pyqtSlot(str)
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
94 def on_targetEdit_textChanged(self, txt):
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
95 """
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
96 Private slot to handle changes of the target.
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
97
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
98 @param txt contents of the target edit (string)
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
99 """
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
100 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
e51a12f1f404 Improved the VCS copy/move operations a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1884
diff changeset
101 os.path.isabs(txt) or os.path.dirname(txt) == "")

eric ide

mercurial