def setupTabs(self): """ Setup the various tabs in the AddressWidget. """ groups = ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VW", "XYZ"] for group in groups: proxyModel = QSortFilterProxyModel(self) proxyModel.setSourceModel(self.tableModel) proxyModel.setDynamicSortFilter(True) tableView = QTableView() tableView.setModel(proxyModel) tableView.setSortingEnabled(True) tableView.setSelectionBehavior(QAbstractItemView.SelectRows) tableView.horizontalHeader().setStretchLastSection(True) tableView.verticalHeader().hide() tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) tableView.setSelectionMode(QAbstractItemView.SingleSelection) # This here be the magic: we use the group name (e.g. "ABC") to # build the regex for the QSortFilterProxyModel for the group's # tab. The regex will end up looking like "^[ABC].*", only # allowing this tab to display items where the name starts with # "A", "B", or "C". Notice that we set it to be case-insensitive. reFilter = "^[%s].*" % group proxyModel.setFilterRegExp(QRegExp(reFilter, Qt.CaseInsensitive)) proxyModel.setFilterKeyColumn(0) # Filter on the "name" column proxyModel.sort(0, Qt.AscendingOrder) # This prevents an application crash (see: http://www.qtcentre.org/threads/58874-QListView-SelectionModel-selectionChanged-Crash) viewselectionmodel = tableView.selectionModel() tableView.selectionModel().selectionChanged.connect(self.selectionChanged) self.addTab(tableView, group)
def setupTabs(self): """ Setup the various tabs in the AddressWidget. """ groups = ["ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VW", "XYZ"] for group in groups: proxyModel = QSortFilterProxyModel(self) proxyModel.setSourceModel(self.tableModel) proxyModel.setDynamicSortFilter(True) tableView = QTableView() tableView.setModel(proxyModel) tableView.setSortingEnabled(True) tableView.setSelectionBehavior(QAbstractItemView.SelectRows) tableView.horizontalHeader().setStretchLastSection(True) tableView.verticalHeader().hide() tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) tableView.setSelectionMode(QAbstractItemView.SingleSelection) # This here be the magic: we use the group name (e.g. "ABC") to # build the regex for the QSortFilterProxyModel for the group's # tab. The regex will end up looking like "^[ABC].*", only # allowing this tab to display items where the name starts with # "A", "B", or "C". Notice that we set it to be case-insensitive. reFilter = "^[%s].*" % group proxyModel.setFilterRegExp(QRegExp(reFilter, Qt.CaseInsensitive)) proxyModel.setFilterKeyColumn(0) # Filter on the "name" column proxyModel.sort(0, Qt.AscendingOrder) # This prevents an application crash (see: http://www.qtcentre.org/threads/58874-QListView-SelectionModel-selectionChanged-Crash) viewselectionmodel = tableView.selectionModel() tableView.selectionModel().selectionChanged.connect( self.selectionChanged) self.addTab(tableView, group)
def setupTable(self): proxyModel = QSortFilterProxyModel(self) proxyModel.setSourceModel(self.tableModel) proxyModel.setDynamicSortFilter(True) self.tableView.setModel(proxyModel) self.tableView.setSortingEnabled(True) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.verticalHeader().hide() self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.tableView.setSelectionMode(QAbstractItemView.SingleSelection) proxyModel.setFilterKeyColumn(0) # Filter on the "name" column proxyModel.sort(0, Qt.AscendingOrder) viewselectionmodel = self.tableView.selectionModel() self.tableView.selectionModel().selectionChanged.connect(self.selectionChanged)
def setupTable(self): proxyModel = QSortFilterProxyModel(self) proxyModel.setSourceModel(self.tableModel) proxyModel.setDynamicSortFilter(True) self.tableView.setModel(proxyModel) self.tableView.setSortingEnabled(True) self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows) self.tableView.horizontalHeader().setStretchLastSection(True) self.tableView.verticalHeader().hide() self.tableView.setEditTriggers(QAbstractItemView.NoEditTriggers) self.tableView.setSelectionMode(QAbstractItemView.SingleSelection) proxyModel.setFilterKeyColumn(0) # Filter on the "name" column proxyModel.sort(0, Qt.AscendingOrder) viewselectionmodel = self.tableView.selectionModel() self.tableView.selectionModel().selectionChanged.connect( self.selectionChanged)
class Window(QWidget): def __init__(self): super(Window, self).__init__() self.proxyModel = QSortFilterProxyModel() self.proxyModel.setDynamicSortFilter(True) self.sourceGroupBox = QGroupBox("Original Model") self.proxyGroupBox = QGroupBox("Sorted/Filtered Model") self.sourceView = QTreeView() self.sourceView.setRootIsDecorated(False) self.sourceView.setAlternatingRowColors(True) self.proxyView = QTreeView() self.proxyView.setRootIsDecorated(False) self.proxyView.setAlternatingRowColors(True) self.proxyView.setModel(self.proxyModel) self.proxyView.setSortingEnabled(True) self.sortCaseSensitivityCheckBox = QCheckBox("Case sensitive sorting") self.filterCaseSensitivityCheckBox = QCheckBox("Case sensitive filter") self.filterPatternLineEdit = QLineEdit() self.filterPatternLineEdit.setClearButtonEnabled(True) self.filterPatternLabel = QLabel("&Filter pattern:") self.filterPatternLabel.setBuddy(self.filterPatternLineEdit) self.filterSyntaxComboBox = QComboBox() self.filterSyntaxComboBox.addItem("Regular expression", REGULAR_EXPRESSION) self.filterSyntaxComboBox.addItem("Wildcard", WILDCARD) self.filterSyntaxComboBox.addItem("Fixed string", FIXED_STRING) self.filterSyntaxLabel = QLabel("Filter &syntax:") self.filterSyntaxLabel.setBuddy(self.filterSyntaxComboBox) self.filterColumnComboBox = QComboBox() self.filterColumnComboBox.addItem("Subject") self.filterColumnComboBox.addItem("Sender") self.filterColumnComboBox.addItem("Date") self.filterColumnLabel = QLabel("Filter &column:") self.filterColumnLabel.setBuddy(self.filterColumnComboBox) self.filterPatternLineEdit.textChanged.connect(self.filterRegExpChanged) self.filterSyntaxComboBox.currentIndexChanged.connect(self.filterRegExpChanged) self.filterColumnComboBox.currentIndexChanged.connect(self.filterColumnChanged) self.filterCaseSensitivityCheckBox.toggled.connect(self.filterRegExpChanged) self.sortCaseSensitivityCheckBox.toggled.connect(self.sortChanged) sourceLayout = QHBoxLayout() sourceLayout.addWidget(self.sourceView) self.sourceGroupBox.setLayout(sourceLayout) proxyLayout = QGridLayout() proxyLayout.addWidget(self.proxyView, 0, 0, 1, 3) proxyLayout.addWidget(self.filterPatternLabel, 1, 0) proxyLayout.addWidget(self.filterPatternLineEdit, 1, 1, 1, 2) proxyLayout.addWidget(self.filterSyntaxLabel, 2, 0) proxyLayout.addWidget(self.filterSyntaxComboBox, 2, 1, 1, 2) proxyLayout.addWidget(self.filterColumnLabel, 3, 0) proxyLayout.addWidget(self.filterColumnComboBox, 3, 1, 1, 2) proxyLayout.addWidget(self.filterCaseSensitivityCheckBox, 4, 0, 1, 2) proxyLayout.addWidget(self.sortCaseSensitivityCheckBox, 4, 2) self.proxyGroupBox.setLayout(proxyLayout) mainLayout = QVBoxLayout() mainLayout.addWidget(self.sourceGroupBox) mainLayout.addWidget(self.proxyGroupBox) self.setLayout(mainLayout) self.setWindowTitle("Basic Sort/Filter Model") self.resize(500, 450) self.proxyView.sortByColumn(1, Qt.AscendingOrder) self.filterColumnComboBox.setCurrentIndex(1) self.filterPatternLineEdit.setText("Andy|Grace") self.filterCaseSensitivityCheckBox.setChecked(True) self.sortCaseSensitivityCheckBox.setChecked(True) def setSourceModel(self, model): self.proxyModel.setSourceModel(model) self.sourceView.setModel(model) def filterRegExpChanged(self): syntax_nr = self.filterSyntaxComboBox.currentData() pattern = self.filterPatternLineEdit.text() if syntax_nr == WILDCARD: pattern = QRegularExpression.wildcardToRegularExpression(pattern) elif syntax_nr == FIXED_STRING: pattern = QRegularExpression.escape(pattern) regExp = QRegularExpression(pattern) if not self.filterCaseSensitivityCheckBox.isChecked(): options = regExp.patternOptions() options |= QRegularExpression.CaseInsensitiveOption regExp.setPatternOptions(options) self.proxyModel.setFilterRegularExpression(regExp) def filterColumnChanged(self): self.proxyModel.setFilterKeyColumn(self.filterColumnComboBox.currentIndex()) def sortChanged(self): if self.sortCaseSensitivityCheckBox.isChecked(): caseSensitivity = Qt.CaseSensitive else: caseSensitivity = Qt.CaseInsensitive self.proxyModel.setSortCaseSensitivity(caseSensitivity)
class MainWindow(QMainWindow): createUpload = Signal(list, htauthcontroller.HTAuthorizationController, str, list) def __init__(self): super(MainWindow, self).__init__() self.hyperthoughtui = HyperthoughtDialogImpl() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.TabWidget.setCurrentWidget(self.ui.CreateTemplateTab) self.ui.actionHelp.triggered.connect(self.help) self.ui.actionOpenPackage.triggered.connect(self.openPackage) self.ui.actionSave_Package.triggered.connect(self.savePackageAs) self.ui.actionClose.triggered.connect(self.close) self.ui.actionSave_Template.triggered.connect(self.saveTemplate) self.ui.actionOpen_Template.triggered.connect(self.restoreTemplate) self.ui.dataFileSelect.clicked.connect(self.selectFile) self.ui.hyperthoughtTemplateSelect.clicked.connect(self.selectTemplate) self.ui.saveTemplateButton.clicked.connect(self.saveTemplate) self.ui.otherDataFileSelect.clicked.connect(self.extractFile) self.ui.hyperthoughtUploadButton.clicked.connect( self.uploadToHyperthought) self.setAcceptDrops(True) self.numCustoms = 0 self.customInputs = [] self.templateFilePath = "" aTree = {} self.createtablemodel = TableModelC(aTree, self) self.filterModel = FilterModel(self) self.filterModel.setSourceModel(self.createtablemodel) self.ui.metadataTableView.setModel(self.filterModel) self.ui.metadataTableView.horizontalHeader().setSectionResizeMode( self.createtablemodel.K_SOURCE_COL_INDEX, QHeaderView.ResizeToContents) self.ui.metadataTableView.horizontalHeader().setSectionResizeMode( self.createtablemodel.K_HTNAME_COL_INDEX, QHeaderView.ResizeToContents) self.ui.metadataTableView.horizontalHeader().setSectionResizeMode( self.createtablemodel.K_SOURCEVAL_COL_INDEX, QHeaderView.ResizeToContents) self.ui.metadataTableView.horizontalHeader().setSectionResizeMode( self.createtablemodel.K_HTVALUE_COL_INDEX, QHeaderView.ResizeToContents) self.ui.metadataTableView.setColumnWidth( self.createtablemodel.K_USESOURCE_COL_INDEX, self.width() * .1) self.checkboxDelegate = CheckBoxDelegate() self.createtrashDelegate = TrashDelegate() self.ui.metadataTableView.setItemDelegateForColumn( self.createtablemodel.K_USESOURCE_COL_INDEX, self.checkboxDelegate) self.ui.metadataTableView.setItemDelegateForColumn( self.createtablemodel.K_EDITABLE_COL_INDEX, self.checkboxDelegate) self.ui.metadataTableView.setItemDelegateForColumn( self.createtablemodel.K_REMOVE_COL_INDEX, self.createtrashDelegate) self.ui.metadataTableView.setColumnWidth( self.createtablemodel.K_REMOVE_COL_INDEX, self.width() * .05) self.treeModel = TreeModel(["Available File Metadata"], aTree, self.createtablemodel) self.ui.metadataTreeView.setModel(self.treeModel) self.treeModel.checkChanged.connect(self.filterModel.checkList) self.createtrashDelegate.pressed.connect(self.handleRemoveCreate) self.editableKeys = [] self.usetablemodel = TableModelU(self, [], self.editableKeys) self.usefilterModel = FilterModelU(self) self.usefilterModel.setSourceModel(self.usetablemodel) self.ui.useTemplateTableView.setModel(self.usefilterModel) self.ui.useTemplateTableView.setColumnWidth( self.usetablemodel.K_HTKEY_COL_INDEX, self.width() * .25) self.ui.useTemplateTableView.setColumnWidth( self.usetablemodel.K_HTVALUE_COL_INDEX, self.width() * .25) self.ui.useTemplateTableView.setColumnWidth( self.usetablemodel.K_SOURCE_COL_INDEX, self.width() * .25) self.ui.useTemplateTableView.setColumnWidth( self.usetablemodel.K_USESOURCE_COL_INDEX, self.width() * .1) self.ui.useTemplateTableView.setColumnWidth( self.usetablemodel.K_HTANNOTATION_COL_INDEX, self.width() * .1) self.usetrashDelegate = TrashDelegate() self.ui.useTemplateTableView.setItemDelegateForColumn( self.usetablemodel.K_USESOURCE_COL_INDEX, self.checkboxDelegate) self.ui.useTemplateTableView.setItemDelegateForColumn( self.usetablemodel.K_REMOVE_COL_INDEX, self.usetrashDelegate) self.ui.useTemplateTableView.setColumnWidth( self.usetablemodel.K_REMOVE_COL_INDEX, self.width() * .075) self.usetrashDelegate.pressed.connect(self.handleRemoveUse) self.uselistmodel = ListModel(self, self.usetablemodel, []) self.ui.useTemplateListView.setModel(self.uselistmodel) self.uselistmodel.rowRemoved.connect(self.toggleButtons) self.uselistmodel.rowAdded.connect(self.toggleButtons) self.useFileDelegate = UseFileDelegate(self) self.ui.useTemplateListView.setItemDelegate(self.useFileDelegate) self.ui.useTemplateListView.clicked.connect( self.removeRowfromUsefileType) self.addAppendButton() self.ui.TabWidget.currentChanged.connect(self.movethedamnbutton) self.appendSourceFilesButton.clicked.connect(self.addFile) self.ui.appendCreateTableRowButton.clicked.connect( self.addCreateTableRow) self.ui.appendUseTableRowButton.clicked.connect(self.addUseTableRow) self.ui.hyperthoughtLocationButton.clicked.connect( self.hyperthoughtui.exec) self.ui.usetableSearchBar.textChanged.connect(self.filterUseTable) self.ui.createTemplateListSearchBar.textChanged.connect( self.filterCreateTable) self.ui.createTemplateTreeSearchBar.textChanged.connect( self.filterCreateTree) self.ui.addMetadataFileCheckBox.stateChanged.connect( self.checkFileList) self.fileType = "" self.accessKey = "" self.folderuuid = "" self.mThread = QThread() self.uploader = Uploader() self.uploader.moveToThread(self.mThread) self.mThread.start() self.createUpload.connect(self.uploader.performUpload) self.hyperthoughtui.apiSubmitted.connect(self.acceptKey) self.hyperthoughtui.finished.connect(self.getLocation) self.ui.hyperthoughtTemplateLineEdit.installEventFilter(self) self.ui.otherDataFileLineEdit.installEventFilter(self) self.ui.dataFileLineEdit.installEventFilter(self) def acceptKey(self, apikey): self.accessKey = apikey def addCreateTableRow(self): self.createtablemodel.addEmptyRow(self.numCustoms) self.numCustoms += 1 def addFile(self): linetexts = QFileDialog.getOpenFileNames( self, self.tr("Select File"), QStandardPaths.displayName(QStandardPaths.HomeLocation), self.tr("Files (*.ctf *.xml *.ang)"))[0] for line in linetexts: self.uselistmodel.addRow(line) self.toggleButtons() def addAppendButton(self): self.appendSourceFilesButton = QToolButton(self.ui.useTemplateListView) icon = QApplication.style().standardIcon(QStyle.SP_FileIcon) def addUseTableRow(self): self.usetablemodel.addEmptyRow() def checkFileList(self, checked): if checked == Qt.Checked: if self.ui.otherDataFileLineEdit.text() != "": self.uselistmodel.addRow(self.ui.otherDataFileLineEdit.text()) elif checked == Qt.Unchecked: if self.ui.otherDataFileLineEdit.text( ) in self.uselistmodel.metadataList: rowIndex = self.uselistmodel.metadataList.index( self.ui.otherDataFileLineEdit.text()) self.uselistmodel.removeRow(rowIndex) def closeEvent(self, event): self.mThread.quit() self.mThread.wait(250) def extractFile(self, fileLink=False): if fileLink == False: linetext = QFileDialog.getOpenFileName( self, self.tr("Select File"), QStandardPaths.displayName(QStandardPaths.HomeLocation), self.tr("Files (*" + self.fileType + ")"))[0] else: linetext = fileLink if linetext != "": self.setWindowTitle(linetext) self.ui.dataTypeText.setText(linetext.split(".")[1].upper()) self.ui.otherDataFileLineEdit.setText(linetext) if self.ui.addMetadataFileCheckBox.checkState() == Qt.Checked: self.uselistmodel.removeAllRows() self.uselistmodel.addRow(linetext) self.toggleButtons() if self.ui.fileParserCombo.findText( linetext.split(".")[1].upper() + " Parser") != -1: headerDict = {} self.ui.fileParserCombo.setCurrentIndex( self.ui.fileParserCombo.findText( linetext.split(".")[1].upper() + " Parser")) if linetext.split(".")[1].upper() == "CTF": headerDict = ctf.parse_header_as_dict(linetext) elif linetext.split(".")[1].upper() == "ANG": headerDict = ang.parse_header_as_dict(linetext) elif linetext.split(".")[1].upper() == "XML": print("XML Parser used") if self.templatedata: self.usetablemodel.metadataList = [] self.usefilterModel = FilterModelU(self) self.usefilterModel.setSourceModel(self.usetablemodel) self.unusedTreeModel = TreeModelU(["Available File Metadata"], headerDict, self.usetablemodel, self.editableKeys) self.templatelist = [] self.templatesources = [] for i in range(len(self.templatedata)): self.templatelist.append(self.templatedata[i]) if "Custom Input" not in self.templatedata[i]["Source"]: self.templatesources.append("/".join( self.templatedata[i]['Source'].split("/")[1:])) else: self.usetablemodel.addExistingRow(self.templatedata[i]) self.usesearchFilterModel = QSortFilterProxyModel(self) self.usesearchFilterModel.setSourceModel(self.usefilterModel) self.usesearchFilterModel.setFilterKeyColumn(0) self.usesearchFilterModel.setDynamicSortFilter(True) self.ui.useTemplateTableView.setModel( self.usesearchFilterModel) self.toggleButtons() def eventFilter(self, object, event): if object == self.ui.hyperthoughtTemplateLineEdit: if event.type() == QEvent.DragEnter: if str(event.mimeData().urls()[0])[-5:-2] == ".ez": event.acceptProposedAction() if (event.type() == QEvent.Drop): if str(event.mimeData().urls()[0])[-5:-2] == ".ez": event.acceptProposedAction() self.loadTemplateFile( event.mimeData().urls()[0].toLocalFile()) if object == self.ui.otherDataFileLineEdit: if event.type() == QEvent.DragEnter: if str(event.mimeData().urls()[0])[-6:-2] == self.fileType: event.acceptProposedAction() if (event.type() == QEvent.Drop): if str(event.mimeData().urls()[0])[-6:-2] == self.fileType: event.acceptProposedAction() self.extractFile(event.mimeData().urls()[0].toLocalFile()) if object == self.ui.dataFileLineEdit: if event.type() == QEvent.DragEnter: if str(event.mimeData().urls()[0])[-6:-2] == ".ctf" or str( event.mimeData().urls()[0])[-6:-2] == ".ang": event.acceptProposedAction() if (event.type() == QEvent.Drop): if str(event.mimeData().urls()[0])[-6:-2] == ".ctf" or str( event.mimeData().urls()[0])[-6:-2] == ".ang": event.acceptProposedAction() self.selectFile(event.mimeData().urls()[0].toLocalFile()) return QMainWindow.eventFilter(self, object, event) def filterCreateTable(self): self.createTableSearchFilterModel.invalidate() self.createTableSearchFilterModel.setFilterCaseSensitivity( Qt.CaseInsensitive) self.createTableSearchFilterModel.setFilterWildcard( "*" + self.ui.createTemplateListSearchBar.text() + "*") def filterCreateTree(self): self.createTreeSearchFilterModel.invalidate() self.createTreeSearchFilterModel.setFilterCaseSensitivity( Qt.CaseInsensitive) self.createTreeSearchFilterModel.setFilterWildcard( "*" + self.ui.createTemplateTreeSearchBar.text() + "*") def filterUseTable(self): self.usesearchFilterModel.invalidate() self.usesearchFilterModel.setFilterCaseSensitivity(Qt.CaseInsensitive) self.usesearchFilterModel.setFilterWildcard( "*" + self.ui.usetableSearchBar.text() + "*") def getLocation(self): remoteDirPath = self.hyperthoughtui.getUploadDirectory() self.folderuuid = ht_requests.get_ht_id_path_from_ht_path( self.hyperthoughtui.authcontrol, ht_path=remoteDirPath) self.ui.hyperthoughtLocationLineEdit.setText(remoteDirPath) self.toggleButtons() def handleRemoveCreate(self, source, filterIndex, tableIndex): if "Custom Input" in source: for i in range(len(self.createtablemodel.metadataList)): if self.createtablemodel.metadataList[i]["Source"] == source: self.createtablemodel.beginRemoveRows(QModelIndex(), i, i) del self.createtablemodel.metadataList[i] self.createtablemodel.endRemoveRows() break else: self.treeModel.changeLeafCheck(source) def handleRemoveUse(self, source, listIndex, filterIndex): self.usetablemodel.beginRemoveRows(QModelIndex(), listIndex.row(), listIndex.row()) del self.usetablemodel.metadataList[listIndex.row()] self.usetablemodel.endRemoveRows() def help(self): QDesktopServices.openUrl("http://www.bluequartz.net/") def movethedamnbutton(self): self.appendSourceFilesButton.move( self.ui.useTemplateListView.width() - self.appendSourceFilesButton.width() - 15, self.ui.useTemplateListView.height() - self.appendSourceFilesButton.height()) def openPackage(self): linetext = QFileDialog.getOpenFileName( self, self.tr("Select File"), QStandardPaths.displayName(QStandardPaths.HomeLocation), self.tr("Files (*.ezpak)"))[0] if linetext != "": infile = open(linetext, "r") self.loadTemplateFile(infile.readline()[1:-2]) extractedFile = infile.readline()[1:-2] fileList = infile.readline() fileList = json.loads(fileList) self.fileList = fileList[:] self.uselistmodel = ListModel(self, self.usetablemodel, self.fileList) self.ui.useTemplateListView.setModel(self.uselistmodel) self.extractFile(extractedFile) self.uselistmodel.removeAllRows() for i in range(len(fileList)): self.uselistmodel.addRow(fileList[i]) self.toggleButtons() infile.close() self.ui.TabWidget.setCurrentIndex(1) def restoreTemplate(self): #Clear data on create side self.createtablemodel.metadataList = [] self.createtablemodel.hiddenList = [] self.filterModel.displayed = [] #open template linetext = QFileDialog.getOpenFileName( self, self.tr("Select File"), QStandardPaths.displayName(QStandardPaths.HomeLocation), self.tr("Files (*.ez)"))[0] if linetext != "": infile = open(linetext, "r") infile.readline() fileType = infile.readline() self.fileType = json.loads(fileType) infile.readline() newList = infile.readline() newList = json.loads(newList) newDict = infile.readline() newDict = json.loads(newDict) self.ui.dataTypeText.setText(self.fileType[0][-3:].upper()) self.ui.fileParserCombo.setCurrentIndex( self.ui.fileParserCombo.findText( self.fileType[0][-3:].upper() + " Parser")) self.ui.dataFileLineEdit.setText(self.fileType[0]) self.createtablemodel = TableModelC(newDict, self) self.filterModel.displayed = [] self.filterModel.setSourceModel(self.createtablemodel) self.filterModel.fileType = self.fileType self.createTableSearchFilterModel = QSortFilterProxyModel(self) self.createTableSearchFilterModel.setSourceModel(self.filterModel) self.createTableSearchFilterModel.setFilterKeyColumn(1) self.createTableSearchFilterModel.setDynamicSortFilter(True) self.ui.metadataTableView.setModel( self.createTableSearchFilterModel) self.treeModel = TreeModelR(["Available File Metadata"], newDict, self.createtablemodel, newList, self.filterModel) for i in range(len(newList)): if "Custom Input" in newList[i]["Source"]: self.numCustoms += 1 self.customInputs.append(newList[i]) self.createtablemodel.beginInsertRows( self.createtablemodel.index( len(self.createtablemodel.metadataList), 0), i, i) self.createtablemodel.metadataList.append(newList[i]) self.createtablemodel.endInsertRows() self.createTreeSearchFilterModel = QSortFilterProxyModel(self) self.createTreeSearchFilterModel.setSourceModel(self.treeModel) self.createTreeSearchFilterModel.setFilterKeyColumn(0) self.createTreeSearchFilterModel.setDynamicSortFilter(True) self.createTreeSearchFilterModel.setRecursiveFilteringEnabled(True) self.ui.metadataTreeView.setModel(self.createTreeSearchFilterModel) self.treeModel.checkChanged.connect(self.filterModel.checkList) self.createtrashDelegate.pressed.connect(self.handleRemoveCreate) self.ui.TabWidget.setCurrentIndex(0) def removeRowfromUsefileType(self, index): if self.ui.useTemplateListView.width( ) - 64 < self.ui.useTemplateListView.mapFromGlobal(QCursor.pos()).x(): #this is where to remove the row self.uselistmodel.removeRow(index.row()) def resizeEvent(self, event): super().resizeEvent(event) self.movethedamnbutton() def savePackageAs(self): fileName = QFileDialog.getSaveFileName(self, "Save File", "/Packages/", "Packages (*.ezpak)")[0] if fileName != "": myDir = QDir() myDir.mkpath(fileName) for file in self.uselistmodel.metadataList: QFile.copy(file, fileName + "/" + file.split("/")[-1]) oldtemplate = open(self.templateFilePath, 'r') oldtemplatelist = oldtemplate.readline() filetype = oldtemplate.readline() oldtemplate.readline() oldlist = oldtemplate.readline() oldtree = oldtemplate.readline() oldtemplate.close() with open(fileName + "/" + self.currentTemplate, 'w') as outfile: outfile.write(oldtemplatelist) outfile.write(filetype) json.dump(self.editableKeys, outfile) outfile.write("\n") outfile.write(oldlist) outfile.write(oldtree) with open(fileName + "/" + self.currentTemplate + "pak", 'w') as outfile: json.dump(fileName + "/" + self.currentTemplate, outfile) outfile.write("\n") json.dump(self.ui.otherDataFileLineEdit.text(), outfile) outfile.write("\n") json.dump(self.uselistmodel.metadataList, outfile) def saveTemplate(self): dialog = QFileDialog(self, "Save File", "", "Templates (*.ez)") dialog.setDefaultSuffix(".ez") dialog.setAcceptMode(QFileDialog.AcceptSave) fileName = "" if dialog.exec(): fileName = dialog.selectedFiles()[0] if fileName != "": with open(fileName, 'w') as outfile: json.dump(self.filterModel.displayed, outfile) outfile.write("\n") json.dump(self.filterModel.fileType, outfile) outfile.write("\n") self.createtablemodel.editableList = [] for i in range(len(self.createtablemodel.metadataList)): if self.createtablemodel.metadataList[i][ "Editable"] == 2 and ( self.createtablemodel.metadataList[i] ["Checked"] == 2 or self.createtablemodel. metadataList[i]["Checked"] == 1): self.createtablemodel.editableList.append( self.createtablemodel.metadataList[i]["Key"]) json.dump(self.createtablemodel.editableList, outfile) outfile.write("\n") json.dump(self.createtablemodel.metadataList, outfile) outfile.write("\n") json.dump(self.treeModel.treeDict, outfile) def selectFile(self, fileLink=None): if fileLink == False: linetext = QFileDialog.getOpenFileName( self, self.tr("Select File"), QStandardPaths.displayName(QStandardPaths.HomeLocation), self.tr("Files (*.*)"))[0] else: linetext = fileLink if linetext != "": self.setWindowTitle(linetext) self.ui.dataFileLineEdit.setText(linetext) self.ui.dataTypeText.setText(linetext.split(".")[1].upper()) if self.ui.fileParserCombo.findText( linetext.split(".")[1].upper() + " Parser") != -1: headerDict = {} self.ui.fileParserCombo.setCurrentIndex( self.ui.fileParserCombo.findText( linetext.split(".")[1].upper() + " Parser")) if linetext.split(".")[1].upper() == "CTF": headerDict = ctf.parse_header_as_dict(linetext) elif linetext.split(".")[1].upper() == "ANG": headerDict = ang.parse_header_as_dict(linetext) elif linetext.split(".")[1].upper() == "XML": print("XML Parser used") self.createtablemodel = TableModelC(headerDict, self) self.filterModel.displayed = [] self.filterModel.setSourceModel(self.createtablemodel) self.filterModel.fileType.append(linetext) self.createTableSearchFilterModel = QSortFilterProxyModel(self) self.createTableSearchFilterModel.setSourceModel(self.filterModel) self.createTableSearchFilterModel.setFilterKeyColumn(1) self.createTableSearchFilterModel.setDynamicSortFilter(True) self.ui.metadataTableView.setModel( self.createTableSearchFilterModel) self.treeModel = TreeModel(["Available File Metadata"], headerDict, self.createtablemodel) if len(self.customInputs) != 0: for i in range(len(self.customInputs)): self.createtablemodel.beginInsertRows( self.createtablemodel.index( len(self.createtablemodel.metadataList), 0), i, i) self.createtablemodel.metadataList.append( self.customInputs[i]) self.createtablemodel.endInsertRows() self.createTreeSearchFilterModel = QSortFilterProxyModel(self) self.createTreeSearchFilterModel.setSourceModel(self.treeModel) self.createTreeSearchFilterModel.setFilterKeyColumn(0) self.createTreeSearchFilterModel.setDynamicSortFilter(True) self.createTreeSearchFilterModel.setRecursiveFilteringEnabled(True) self.ui.metadataTreeView.setModel(self.createTreeSearchFilterModel) self.treeModel.checkChanged.connect(self.filterModel.checkList) self.createtrashDelegate.pressed.connect(self.handleRemoveCreate) self.toggleButtons() return True def selectTemplate(self): startLocation = self.ui.hyperthoughtTemplateLineEdit.text() if startLocation == "": startLocation = QStandardPaths.writableLocation( QStandardPaths.HomeLocation) templateFilePath = QFileDialog.getOpenFileName( self, self.tr("Select File"), startLocation, self.tr("Files (*.ez)"))[0] self.loadTemplateFile(templateFilePath) def loadTemplateFile(self, templateFilePath=None): if templateFilePath == "": return False self.templateFilePath = templateFilePath self.usetablemodel.metadataList = [] self.usefilterModel.displayed = [] self.currentTemplate = templateFilePath.split("/")[-1] self.ui.displayedFileLabel.setText(templateFilePath.split("/")[-1]) self.ui.hyperthoughtTemplateLineEdit.setText(templateFilePath) self.ui.otherDataFileLineEdit.setText("") infile = open(templateFilePath, "r") data = infile.readline() fileType = infile.readline() fileType = json.loads(fileType) self.fileType = fileType[0][-4:] editables = infile.readline() self.editableKeys = json.loads(editables) self.usetablemodel.editableKeys = self.editableKeys self.toggleButtons() self.templatedata = json.loads(data) self.usetablemodel.addTemplateList(self.templatedata) self.usefilterModel.setFilterRegExp(QRegExp()) infile.close() return True def showEvent(self, event): super().showEvent(event) self.movethedamnbutton() def toggleButtons(self): if (self.ui.hyperthoughtTemplateLineEdit.text() != "" and self.ui.otherDataFileLineEdit.text() != "" and self.ui.useTemplateListView.model().rowCount() > 0 and self.ui.hyperthoughtLocationLineEdit.text() != ""): self.ui.hyperthoughtUploadButton.setEnabled(True) def uploadToHyperthought(self): auth_control = htauthcontroller.HTAuthorizationController( self.accessKey) metadataJson = ht_utilities.dict_to_ht_metadata( self.usefilterModel.displayed) progress = QProgressDialog("Uploading files...", "Abort Upload", 0, len(self.uselistmodel.metadataList), self) progress.setWindowFlags(Qt.Window | Qt.CustomizeWindowHint | Qt.WindowTitleHint) progress.setAttribute(Qt.WA_DeleteOnClose) self.createUpload.emit(self.uselistmodel.metadataList, auth_control, self.folderuuid, metadataJson) self.uploader.currentUploadDone.connect(progress.setValue) self.uploader.currentlyUploading.connect(progress.setLabelText) self.uploader.allUploadsDone.connect(progress.accept) progress.canceled.connect(lambda: self.uploader.interruptUpload()) progress.setFixedSize(500, 100) progress.exec()