src/eric7/Plugins/VcsPlugins/vcsMercurial/HgArchiveDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2013 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the archive data.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
12
13 from EricWidgets.EricPathPicker import EricPathPickerModes
14
15 from .Ui_HgArchiveDialog import Ui_HgArchiveDialog
16
17 import Utilities
18
19
20 class HgArchiveDialog(QDialog, Ui_HgArchiveDialog):
21 """
22 Class implementing a dialog to enter the archive data.
23 """
24 def __init__(self, vcs, parent=None):
25 """
26 Constructor
27
28 @param vcs reference to the Mercurial object (Hg)
29 @param parent reference to the parent widget (QWidget)
30 """
31 super().__init__(parent)
32 self.setupUi(self)
33
34 self.archivePicker.setMode(
35 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE)
36
37 self.typeComboBox.addItem(
38 self.tr("Detect Automatically"), "")
39 self.typeComboBox.addItem(
40 self.tr("Directory of Files"), "files")
41 self.typeComboBox.addItem(
42 self.tr("Uncompressed TAR-Archive"), "tar")
43 self.typeComboBox.addItem(
44 self.tr("Bzip2 compressed TAR-Archive"), "tbz2")
45 self.typeComboBox.addItem(
46 self.tr("Gzip compressed TAR-Archive"), "tgz")
47 self.typeComboBox.addItem(
48 self.tr("Uncompressed ZIP-Archive"), "uzip")
49 self.typeComboBox.addItem(
50 self.tr("Compressed ZIP-Archive"), "zip")
51
52 self.__unixFileFilters = [
53 self.tr("Bzip2 compressed TAR-Archive (*.tar.bz2)"),
54 self.tr("Gzip compressed TAR-Archive (*.tar.gz)"),
55 self.tr("Uncompressed TAR-Archive (*.tar)"),
56 ]
57 self.__windowsFileFilters = [
58 self.tr("Compressed ZIP-Archive (*.zip)"),
59 self.tr("Uncompressed ZIP-Archive (*.uzip)")
60 ]
61 fileFilters = (
62 ";;".join(self.__windowsFileFilters + self.__unixFileFilters)
63 if Utilities.isWindowsPlatform() else
64 ";;".join(self.__unixFileFilters + self.__windowsFileFilters)
65 )
66 fileFilters += ";;" + self.tr("All Files (*)")
67
68 self.archivePicker.setFilters(fileFilters)
69
70 self.__typeFilters = {
71 "tar": ["*.tar"],
72 "tbz2": ["*.tar.bz2", "*.tbz2"],
73 "tgz": ["*.tar.gz", "*.tgz"],
74 "uzip": ["*.uzip", "*.zip"],
75 "zip": ["*.zip"],
76 }
77
78 self.subReposCheckBox.setEnabled(vcs.hasSubrepositories())
79
80 self.buttonBox.button(
81 QDialogButtonBox.StandardButton.Ok).setEnabled(False)
82
83 self.__projectPath = (
84 vcs.getPlugin().getProjectHelper().getProject().getProjectPath()
85 )
86
87 msh = self.minimumSizeHint()
88 self.resize(max(self.width(), msh.width()), msh.height())
89
90 @pyqtSlot(str)
91 def on_archivePicker_textChanged(self, archive):
92 """
93 Private slot to handle changes of the archive name.
94
95 @param archive name of the archive (string)
96 """
97 self.buttonBox.button(
98 QDialogButtonBox.StandardButton.Ok).setEnabled(archive != "")
99
100 @pyqtSlot(int)
101 def on_typeComboBox_activated(self, index):
102 """
103 Private slot to react on changes of the selected archive type.
104
105 @param index index of the selected type (integer)
106 """
107 type_ = self.typeComboBox.itemData(index)
108 if type_ == "files":
109 self.archivePicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
110 else:
111 self.archivePicker.setMode(
112 EricPathPickerModes.SAVE_FILE_ENSURE_EXTENSION_MODE)
113 if type_ in self.__typeFilters:
114 self.archivePicker.setNameFilters(
115 self.__typeFilters[type_])
116 else:
117 self.archivePicker.setNameFilters([])
118
119 def getData(self):
120 """
121 Public method to retrieve the data.
122
123 @return tuple giving the archive name (string), the archive type
124 (string), the directory prefix 8string) and a flag indicating
125 to recurse into subrepositories (boolean)
126 """
127 return (
128 self.archivePicker.text(),
129 self.typeComboBox.itemData(self.typeComboBox.currentIndex()),
130 self.prefixEdit.text(),
131 self.subReposCheckBox.isChecked(),
132 )

eric ide

mercurial