class Main(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) # Populate default values self.ui.portNumber.setText("2002") self.ui.relationship.addItems('Wife Husband Boyfriend Girlfriend'.split()) self.ui.senderGender.addItems('Male Female'.split()) self.ui.receiverGender.addItems('Female Male'.split()) self.ui.letterTone.addItems('Romantic Casual Comedy Apologetic'.split()) self.ui.fileName.setText("lovelLetter.odt") #Connect Buttons QtCore.QObject.connect (self.ui.startLibreOfficeButton,QtCore.SIGNAL ("clicked()"),self.startLibreOffice) QtCore.QObject.connect (self.ui.writeLoveLetterButton,QtCore.SIGNAL ("clicked()"),self.writeLoveLetter) def startLibreOffice(self): portNumber = str(self.ui.portNumber.text()) #commands.getoutput('soffice "--accept=socket,port='+portNumber+';urp;"') os.system('soffice "--accept=socket,port='+portNumber+';urp;" &') def writeLoveLetter(self): #Get current values senderName = str(self.ui.senderName.text()) receiverName = str(self.ui.receiverName.text()) senderGender = str(self.ui.senderGender.currentText()) receiverGender = str(self.ui.receiverGender.currentText()) relationship = str(self.ui.relationship.currentText()) fileName = str(self.ui.fileName.text()) loveLetterWriter.write(self,senderName,receiverName,senderGender,receiverGender,relationship,fileName)
class window(QWidget): def __init__(self): super(QWidget, self).__init__() self.Ui=Ui_Form() self.setWindowTitle('Eagles packet sniffer') self.Ui.setupUi(self) self.setWindowIcon(QIcon('images.png')) self.combo() self.result=self.Ui.pushButton.clicked.connect(self.get_data) self.show() def combo(self): d = sniff.findInterfaces() for i in d: if "Loopback" not in i: self.Ui.comboBox.addItem(i[0]) def get_data(self): if(sniff.run): self.Ui.pushButton.setText("Start Sniffing") sniff.run =False else : d = sniff.findInterfaces() i=self.Ui.comboBox.currentIndex() interface = d[i][1] sniff.selectInterface(interface) filter_pkt=self.Ui.lineEdit.text() sniff.setFilter(filter_pkt) self.Ui.pushButton.setText("Stop Sniffing") sniff.run = True sniff.start(self) return 0
class MainWindow(QWidget): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self._ui = Ui_Form() self._ui.setupUi(self) @property def parameters(self): u = self._ui return { 'client_m': float(u.le_client_m.text()), 'client_d': float(u.le_client_d.text()), 'op0_m': float(u.le_op0_m.text()), 'op0_d': float(u.le_op0_d.text()), 'op1_m': float(u.le_op1_m.text()), 'op1_d': float(u.le_op1_d.text()), 'op2_m': float(u.le_op2_m.text()), 'op2_d': float(u.le_op2_d.text()), 'comp0_m': float(u.le_comp0_m.text()), 'comp1_m': float(u.le_comp1_m.text()), 'c_count': float(u.le_client_count.text()) } def on_pushButton_model_clicked(self): miss, prob = modeller.event_based_modelling(**self.parameters) self._ui.le_lost_clients.setText('{:.4f}'.format(prob))
class ClaptonWidget(QtWidgets.QWidget): struc = "" # JSON Structure of Document Types quellOrdnerSelectedFilename="" pixmap_realsize={"width":0,"height":0} def nextDocument(self): self.ui.listWidgetQuellordner.setCurrentRow(self.ui.listWidgetQuellordner.currentRow()+1) def previousDocument(self): self.ui.listWidgetQuellordner.setCurrentRow(self.ui.listWidgetQuellordner.currentRow()-1) def openElement(self): elements = self.ui.treeWidget.selectedItems() if elements is not None: if len(elements)>0: element = elements[0] element.setExpanded(True) def removeElement(self): print("REMOVE") _filepath = self.quellOrdnerSelectedFilename+".json" try: print("REMOVE"+_filepath) os.remove(_filepath) print("OK") except: pass self.setDokumenttyp(self.ui.lineEditDokumenttyp.text()) def __init__(self): super(ClaptonWidget, self).__init__() self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle('CLAPTON - CLassification, Anonymization, Pseudonymization and Tagging with OCR and NLP') self.setBaseSize(1250, 700) self.ui.toolButtonQuellordner.clicked.connect(self.clickSetDirectory) self.ui.listWidgetQuellordner.currentTextChanged.connect(self.listWidgetQuellordner_currentTextChanged) self.ui.labelBild.setScaledContents(True) self.setDirectory(default_image_dir) self.ui.toolButtonDokumenttyp.clicked.connect(self.clickSetDokumenttyp) self.setDokumenttyp(default_json) self.ui.treeWidget.doubleClicked.connect(self.treeWidget_itemSelectionChanged) returnFilter = returnKeyFilter(self.ui.treeWidget) self.ui.treeWidget.installEventFilter(returnFilter) returnFilter.returnKeyPressed.connect(self.treeWidget_itemSelectionChanged) #self.ui.treeWidget.itemSelectionChanged.connect(self.treeWidget_itemSelectionChanged) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Down"), self, self.nextDocument) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+Up"), self, self.previousDocument) QtWidgets.QShortcut(QtGui.QKeySequence("Ctrl+W"), self, self.close) QtWidgets.QShortcut(QtGui.QKeySequence("Space"), self, self.nextDocument) QtWidgets.QShortcut(QtGui.QKeySequence("Esc"), self, self.removeElement) self.ui.treeWidget.setFocus() def clickSetDirectory(self): directory = QtWidgets.QFileDialog.getExistingDirectory(self, "Pick a folder") self.setDirectory(directory) def setDirectory(self, directory): self.ui.listWidgetQuellordner.clear() # In case there are any existing elements in the list if directory: # if user didn't pick a directory don't continue self.ui.lineEditQuellordner.setText(directory) for file_name in os.listdir(directory): # for all files, if any, in the directory if file_name.endswith(".TIFF"): self.ui.listWidgetQuellordner.addItem(file_name) # add file to the listWidget def listWidgetQuellordner_currentTextChanged(self, newPixmapFilename): # load different image self.quellOrdnerSelectedFilename = self.ui.lineEditQuellordner.text() + "/" + newPixmapFilename if (len(self.ui.lineEditDokumenttyp.text())>0): print("CTC") self.setDokumenttyp(self.ui.lineEditDokumenttyp.text()) cur_pixmap = QtGui.QPixmap(self.quellOrdnerSelectedFilename) self.pixmap_realsize = {"width":cur_pixmap.width(), "height":cur_pixmap.height()} pixmap = cur_pixmap.scaled(self.ui.widgetBild.width(), self.ui.widgetBild.height(), QtCore.Qt.KeepAspectRatio) self.ui.labelBild.setPixmap(pixmap) elements = self.ui.treeWidget.setCurrentItem(self.ui.treeWidget.topLevelItem(0)) def clickSetDokumenttyp(self): filename = QtWidgets.QFileDialog.getExistingDirectory(self, "Pick a JSON") if filename: # if user didn't pick a directory don't continue print("FILE") self.setDokumenttyp(filename) else: print("NO_FILE") def recurse_json_to_treeWidget(self, struc): l=[] for title in struc: if isinstance(struc[title], str): #print(struc[title]) #print(title) w = QtWidgets.QTreeWidgetItem([struc[title], title]) l.append(w) if title == "area_px": w.setBackground(0, QtGui.QColor(255,255,128)) if isinstance(struc[title], list): #print(struc[title]) w = QtWidgets.QTreeWidgetItem([struc[title][0], title]) if len(struc[title])>1: w.addChildren(self.recurse_json_to_treeWidget(struc[title][1])) w.setBackground(0, w.child(0).background(0)) #print(title) #print(struc[title]) #w.addChildren(self.recurse_json_to_treeWidget(struc)) l.append(w) if title == "area_px": w.setBackground(0, QtGui.QColor(255,255,128)) areas_vector = json.loads("["+struc[title][0]+"]") print("###") print(areas_vector) # w = QtWidgets.QTreeWidgetItem([struc[title][0], title]) #r = self.recurse_json_to_treeWidget(struc[title][1]) #w.addChild(r) return l def setDokumenttyp(self, filename): if filename: # if user didn't pick a directory don't continue self.ui.lineEditDokumenttyp.setText(filename) jsonQuelldatei = self.quellOrdnerSelectedFilename + ".json" if os.path.isfile(jsonQuelldatei): print("LOAD JSON") print(jsonQuelldatei) #self.struc = self.loadCommentedJSON(jsonQuelldatei) self.struc = self.loadCommentedJSON(filename) addstruc = self.loadCommentedJSON(jsonQuelldatei) self.struc.update(addstruc) else: print("LOAD GENERIC JSON") print(jsonQuelldatei) self.struc = self.loadCommentedJSON(filename) self.populateTreeWidgetFromStruc() def populateTreeWidgetFromStruc(self): #store_current = self.ui.treeWidget.selectedItems() #NEW TODO :: Get top level item, restore it self.ui.treeWidget.clear() # In case there are any existing elements in the list l = [] # list of QTreeWidgetItem to add for title in self.struc: w = QtWidgets.QTreeWidgetItem([self.struc[title][0], title]) w.addChildren(self.recurse_json_to_treeWidget(self.struc[title][1])) w.setBackground(0, w.child(0).background(0)) l.append(w) tree = self.ui.treeWidget tree.addTopLevelItems(l) ##exit(0) ##### ##for title in self.struc: ## w=QtWidgets.QTreeWidgetItem([self.struc[title][0], title]) # create QTreeWidgetItem's and append them ## for child in self.struc[title][1]: ## _child = self.struc[title][1][child] ## print(type(_child), _child) #if isinstance(_child, str): # w.addChild(QtWidgets.QTreeWidgetItem([child, child])) #print(self.struc[title][1][child][1]) ## l.append(w) #l.append(QtWidgets.QTreeWidgetItem([self.struc[title][0]])) # create QTreeWidgetItem's and append them #rowPosition = self.ui.treeWidget.rowCount() #self.ui.treeWidget.insertRow(rowPosition) #self.ui.treeWidget.setItem(rowPosition-1, 0, QtWidgets.QTableWidgetItem(title)) #self.ui.treeWidget.setItem(rowPosition-1, 1, QtWidgets.QTableWidgetItem(self.struc[title][0])) # populate tree ########### def treeWidget_itemSelectionChanged(self): getSelected = self.ui.treeWidget.selectedItems() if getSelected: baseNode = getSelected[0] while baseNode.child(0) is not None: # Travel to a leaf baseNode = baseNode.child(0) list=[] self.treeWidget_recurse(list, baseNode) # list contains path to current element from self.struc # WHILE LAST LIST ELEMENT IS NOT LEAF ADD FIRST LEAF TODO::: print (list) self.setArea(list) #QtGui.QKeyEvent event(KeyPress, Qt::NoModifier, QString("") #QMouseEvent event(QEvent.MouseButtonPress, pos, 0, 0, 0); modifier=QtCore.Qt.NoModifier text=None event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, QtCore.Qt.Key_Down, modifier) QtCore.QCoreApplication.postEvent(self.ui.treeWidget, event) #QtCore.QCoreApplication.postEvent(self, event) #self.ui.treeWidget.collapseAll() def treeWidget_recurse(self, list, selectedItem): if selectedItem is not None: if selectedItem.parent() is not None: self.treeWidget_recurse(list, selectedItem.parent()) list.append(selectedItem.text(1)) def loadCommentedJSON(self, filename): with open(filename, encoding="utf-8") as data_file: string = data_file.read() jsonStructure = json.loads(removeComments(string)) return jsonStructure def saveJSON(self, struc): jsonQuelldatei = self.quellOrdnerSelectedFilename + ".json" with open(jsonQuelldatei, 'w', encoding="utf-8") as data_file: json.dump(struc, data_file) def setArea(self, list): cstruc = self.struc for name in list: print ("BEFORE_1") print (cstruc) # if not isinstance(cstruc[name][1], str) : if not isinstance(cstruc[name], str) : cstruc = cstruc[name][1] if "area_px" in cstruc: break print("AFTER_1") print(cstruc) # if cstruc.keys() contains 'area_px': width = self.ui.labelBild.size().width() height = self.ui.labelBild.size().height() realwidth = self.pixmap_realsize["width"] realheight = self.pixmap_realsize["height"] print(width,height,realwidth,realheight) height = self.ui.labelBild.size().height() if self.ui.labelBild.selection.isVisible(): posstr = "" if self.ui.labelBild.upper_left.x() < self.ui.labelBild.lower_right.x(): posstr += str(round(self.ui.labelBild.upper_left.x()*realwidth/width)) posstr += "," posstr += str(round(self.ui.labelBild.upper_left.y()*realheight/height)) posstr += "," posstr += str(round(self.ui.labelBild.lower_right.x()*realwidth/width)) posstr += "," posstr += str(round(self.ui.labelBild.lower_right.y()*realheight/height)) else: posstr += str(round(self.ui.labelBild.lower_right.x()*realwidth/width)) posstr += "," posstr += str(round(self.ui.labelBild.lower_right.y()*realheight/height)) posstr += "," posstr += str(round(self.ui.labelBild.upper_left.x()*realwidth/width)) posstr += "," posstr += str(round(self.ui.labelBild.upper_left.y()*realheight/height)) else: posstr = "0,0," posstr += str(width) posstr += "," posstr += str(height) if "area_px" in cstruc: if self.ui.labelBild.selection.isVisible(): print("BEFORE_2") print(cstruc["area_px"]) print("AFTER_2") cstruc["area_px"][0] += "," + posstr print(cstruc["area_px"]) else: print("BEFORE_3") print(cstruc["area_px"]) print("AFTER_3") cstruc["area_px"][0] += "," + posstr print(cstruc["area_px"]) if (DIRTY_QUICK_DAVID): selectedTreeItems = self.ui.treeWidget.selectedItems() if selectedTreeItems is not None: if len(selectedTreeItems) > 0: selectedTreeItem = selectedTreeItems[0] selectedTreeItem.setBackground(0, QtGui.QColor(128,255,128)) else: self.populateTreeWidgetFromStruc() # DIRTY TODO:: self.saveJSON(self.struc) print ("R") print (cstruc) else: cstruc[name] = [cstruc[name],{"area_px" : [posstr]}] if (DIRTY_QUICK_DAVID): selectedTreeItems = self.ui.treeWidget.selectedItems() if selectedTreeItems is not None: if len(selectedTreeItems) > 0: selectedTreeItem = selectedTreeItems[0] selectedTreeItem.setBackground(0, QtGui.QColor(128,255,128)) else: self.populateTreeWidgetFromStruc() # DIRTY TODO:: self.saveJSON(self.struc) print ("A") print (cstruc)