class SimulationViewer(QWidget):
    def __init__(self, parent, size=256):
        super(SimulationViewer, self).__init__(parent)        
        self.size = size        

        self.pixmap = QLabel()        
        self.pixmap.setFixedSize(self.size, self.size)
        self.pixmap.setFrameStyle(QFrame.Panel | QFrame.Sunken)
        self.status_line = QLabel('no simulation running')

        box = QVBoxLayout()
        box.addWidget(self.pixmap, alignment=QtCore.Qt.AlignHCenter)
        box.addWidget(self.status_line, alignment=QtCore.Qt.AlignHCenter)
        self.setLayout(box)
        
        self.colortable = colortable.BlueWhiteRed 
        
    def resize(self, size):
        self.size = size
        self.pixmap.setFixedSize(self.size, self.size)   

    @QtCore.Slot(str)
    def update_status(self, status):
        self.status_line.setText(status)
        self.status_line.adjustSize()
    
    @QtCore.Slot(QImage)
    def update_image(self, image):
        image.setColorTable(self.colortable)        
        pixmap = QPixmap.fromImage(image)
        self.pixmap.setPixmap(pixmap.scaled(self.size, self.size))
        
Esempio n. 2
0
    def build(self):
        for name in self.headerlist:
            label = QLabel('<b><font align="center">%s</font></b>' % name)
            self.labellist.append(label)
            label.setMargin(2)
            label.setFrameStyle(QFrame.Box | QFrame.Plain)
            label.setLineWidth(1)
            self.addWidget(label, self.r, self.c)
            self.c += 1

        self.c = 0
        self.r += 1

        for row in self.resultslist:
            for name in row:
                label = QLabel('<font align="center">%s</font>' % name)
                self.labellist.append(label)
                label.setMargin(2)
                label.setFrameStyle(QFrame.Box | QFrame.Plain)
                label.setLineWidth(1)
                self.addWidget(label, self.r, self.c)
                if self.c == self.maxcols - 1:
                    self.c = 0
                    self.r += 1
                else:
                    self.c += 1
Esempio n. 3
0
class MyApp(QMainWindow):
    """
    This class presents main application window
    """
    def __init__(self, parent=None):
        super(MyApp, self).__init__(parent)

        # main window size, title and icon
        self.setMinimumSize(800, 150)
        self.setWindowTitle("Calculate a password hash in Linux")
        self.setWindowIcon(QIcon("shacalc.ico"))

        # lines for entering data
        self.saltLabel = QLabel("Salt:")
        self.saltLine = QLineEdit()
        self.saltLine.setPlaceholderText("e.g. $6$xxxxxxxx")
        self.passwordLabel = QLabel("Password:"******"Hash")
        self.hashSunkenLabel = QLabel()
        self.hashSunkenLabel.setFrameStyle(QFrame.Box | QFrame.Sunken)
        self.resultButton = QPushButton("&Calculate", self)
        self.resultButton.setMaximumSize(100, 50)

        # set layout
        grid = QGridLayout()
        grid.addWidget(self.passwordLabel, 0, 0)
        grid.addWidget(self.passwordLine, 0, 1)
        grid.addWidget(self.saltLabel, 1, 0)
        grid.addWidget(self.saltLine, 1, 1)
        grid.addWidget(self.hashLabel, 3, 0)
        grid.addWidget(self.hashSunkenLabel, 3, 1)
        grid.addWidget(self.resultButton, 2, 1)

        #  set central widget in QMainWindow
        widget = QWidget()
        widget.setLayout(grid)
        self.setCentralWidget(widget)

        #  This happens when button is clicked
        self.resultButton.clicked.connect(self.logic)

        #  Shows a widget
        self.show()

    def logic(self):
        """
        Calculates hash from salt and password
        """
        salt = self.saltLine.text()
        password = self.passwordLine.text()
        resulting_hash = crypt.crypt(password, salt)
        self.hashSunkenLabel.setText(resulting_hash)
    def organizeContent(self, widget):
        # get style metrics
        leftMargin = self.app.style().pixelMetric(QStyle.PM_LayoutLeftMargin)
        topMargin = self.app.style().pixelMetric(QStyle.PM_LayoutTopMargin)
        standHeight = self.app.style().pixelMetric(QStyle.PM_ButtonMargin) +\
                      self.app.fontMetrics().height()
        doubleStandHeight = standHeight * 2
        hsepara = self.app.style().pixelMetric(QStyle.PM_LayoutHorizontalSpacing)
        vsepara = self.app.style().pixelMetric(QStyle.PM_LayoutVerticalSpacing)
        # calculate grids
        col0Left = leftMargin
        col1Left = leftMargin + doubleStandHeight + vsepara
        col2Left = leftMargin + doubleStandHeight + standHeight + 2*vsepara
        col3Left = leftMargin + 2*doubleStandHeight + standHeight + 4*vsepara
        row0Top = topMargin
        row1Top = topMargin + standHeight + hsepara
        row2Top = topMargin + 3*standHeight + 2*hsepara
        row3Top = topMargin + 4*standHeight + 3*hsepara

        btnUp = QPushButton('Up', widget)
        btnUp.setGeometry(col1Left, row1Top, standHeight, doubleStandHeight)
        btnLeft = QPushButton('Left', widget)
        btnLeft.setGeometry(col0Left, row2Top, doubleStandHeight, standHeight)
        txtQuant = QLineEdit(widget)
        txtQuant.setGeometry(col1Left, row2Top, standHeight, standHeight)
        txtQuant.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        btnRight = QPushButton('Right', widget)
        btnRight.setGeometry(col2Left, row2Top, doubleStandHeight, standHeight)
        btnDown = QPushButton('Dn', widget)
        btnDown.setGeometry(col1Left, row3Top, standHeight, doubleStandHeight)
        lb3 = QLabel('Elevation:', widget)
        lb3.setGeometry(col3Left, row2Top, lb3.sizeHint().width(), standHeight)
        wi = self.app.fontMetrics().width('Horizontal:') + 2
        lb4 = QLabel('Horizontal:', widget)
        lb4.setGeometry(col3Left, row3Top, wi, standHeight)
        col4Left = leftMargin + 2*doubleStandHeight + standHeight + 5*vsepara + wi
        txtElev = QLineEdit(widget)
        txtElev.setGeometry(col4Left, row2Top, doubleStandHeight, standHeight)
        txtElev.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        txtHoriz = QLineEdit(widget)
        txtHoriz.setGeometry(col4Left, row3Top, doubleStandHeight, standHeight)
        txtHoriz.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        lb2 = QLabel('Angles in degrees', widget)
        lb2.setGeometry(col3Left, row2Top - standHeight - hsepara, wi + hsepara + doubleStandHeight, standHeight)
        lb2.setAlignment(Qt.AlignVCenter | Qt.AlignCenter) #Qt.AlignVCenter
        totalWi = col4Left + doubleStandHeight - col0Left
        totalHi = row3Top + doubleStandHeight - row0Top
        lb1 = QLabel('Camera position control panel', widget)
        lb1.setGeometry(col0Left, row0Top, totalWi, standHeight)
        lb1.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        lb1.setFrameStyle(QFrame.Box)
Esempio n. 5
0
class SymbolWort(QWidget):
	def __init__(self):
		QWidget.__init__(self)
		self.setWindowTitle("Symbol-Worte")
		
		self.thread=MyWorker(self)
		self.thread.start()
		self.thread.calculator.calculationDone.connect(self.calculationDone)
		
		self.initUI()
	
	def about(self):
		QMessageBox.information(self,u"Über Symbol-Worte",u"Symbol-Worte ist ein kleines, zum Spaß entwickeltes, Programm. Es nutzt die Open-Source Entwicklungsumgebung Python (www.python.org) und PySide (Qt-Schnittstelle). Es ist unter GPL v.3 veröffentlicht. Entwickelt von Peter Waldert.")
	
	def update(self):
		text=self.lineEdit.text()
		if text.lower() != self.responseLabel.text().lower():
			self.thread.startCalculation(text)
	
	def calculationDone(self,ok):
		if ok:
			self.responseLabel.setText(self.thread.calculator.result)
		else:
			self.responseLabel.setText(u"Keine Treffer")
		self.updateTable(self.thread.calculator.resultElements)
	
	def updateAuto(self,checked):
		if checked:
			self.lineEdit.textEdited.connect(self.update)
		else:
			self.lineEdit.textEdited.disconnect(self.update)
	
	def updateMaxLength(self,checked):
		if checked:
			self.lineEdit.setMaxLength(10)
		else:
			self.lineEdit.setMaxLength(100)
	
	def setupTable(self):
		self.tableWidget.setColumnCount(3)
		self.tableWidget.setHorizontalHeaderLabels(["OZ","Sym","Name"])
		self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
		self.tableWidget.setSelectionMode(QTableWidget.SingleSelection)
		self.tableWidget.setEditTriggers(QTableWidget.NoEditTriggers)
		self.tableWidget.setAlternatingRowColors(True)
	
	def updateTable(self,elements):
		self.tableWidget.clearContents()
		self.tableWidget.setRowCount(len(elements))
		row=0
		for element in elements:
			self.tableWidget.setItem(row,0,QTableWidgetItem(str(element.atomicNumber)))
			self.tableWidget.setItem(row,1,QTableWidgetItem(elements[row].symbol))
			self.tableWidget.setItem(row,2,QTableWidgetItem(elements[row].name))
			row+=1
		self.tableWidget.resizeColumnsToContents()
	
	def initUI(self):
		wordLabel=QLabel("&Wort:")
		responseLabel=QLabel("Symbol-Wort:")
		progressLabel=QLabel("Rechen-Fortschritt:")
		
		self.lineEdit=QLineEdit()
		self.updateButton=QPushButton("&Berechnen")
		self.autoUpdate=QCheckBox("&Auto-Berechnung")
		self.responseLabel=QLabel()
		wordLabel.setBuddy(self.lineEdit)
		self.tableWidget=QTableWidget()
		self.progressView=ProgressView()
		
		self.disableMaxLengthAction=QAction("Zeichenmaximum (Achtung!)",self)
		self.disableMaxLengthAction.setCheckable(True)
		self.disableMaxLengthAction.toggled.connect(self.updateMaxLength)
		self.disableMaxLengthAction.setChecked(True)
		
		self.setupTable()
		self.progressView.setProgress(self.thread.calculator.progress)
		self.progressView.abortButton.setIcon(QIcon.fromTheme("process-stopp",QIcon("Abort.png")))
		self.progressView.abortButton.setToolTip("Stoppe die Berechnung")
		self.lineEdit.setValidator(QRegExpValidator(QRegExp("[A-Za-z]+")))
		self.lineEdit.setToolTip("Nur Zeichen von A-Z")
		self.lineEdit.setContextMenuPolicy(Qt.ActionsContextMenu)
		self.lineEdit.addAction(self.disableMaxLengthAction)
		self.responseLabel.setSizePolicy(QSizePolicy.Preferred,QSizePolicy.Fixed)
		self.responseLabel.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)
		self.aboutButton=QPushButton(u"Über")
		f=self.responseLabel.font()
		f.setPointSize(24)
		self.responseLabel.setFont(f)
		
		self.lineEdit.returnPressed.connect(self.update)
		self.updateButton.clicked.connect(self.update)
		self.autoUpdate.stateChanged.connect(self.updateAuto)
		self.aboutButton.clicked.connect(self.about)
		
		layout=QGridLayout()
		layout.addWidget(wordLabel,0,0)
		layout.addWidget(self.lineEdit,0,1)
		layout.addWidget(self.updateButton,0,2)
		layout.addWidget(self.autoUpdate,1,1,1,2)
		layout.addWidget(responseLabel,2,0)
		layout.addWidget(self.responseLabel,2,1,1,2)
		layout.addWidget(self.tableWidget,3,0,1,3)
		layout.addWidget(progressLabel,4,0)
		layout.addWidget(self.progressView,5,0,1,3)
		layout.addWidget(self.aboutButton,6,2)
		self.setLayout(layout)
	
	def closeEvent(self,event):
		self.thread.quit()
		self.thread.wait()
		event.accept()
	
	def keyPressEvent(self,event):
		if event.key() == Qt.Key_Escape:
			self.thread.calculator.progress.abort()
			event.accept()
		else:
			event.ignore()
Esempio n. 6
0
class Form(QDialog):
    def __init__(self, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        self.setWindowTitle("New Empty Copy — {}".format(
            QApplication.applicationName()))
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.updateUi()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        self.filenameLabelLabel = QLabel("New Filename")
        self.filenameLabel = QLabel()
        self.filenameLabel.setFrameStyle(QFrame.StyledPanel | QFrame.Sunken)
        self.filenameButton = QPushButton("C&hoose...")
        self.tooltips.append((self.filenameButton, """\
<p><b>Choose</b></p>
<p>Choose the {} <tt>.xix</tt> file to copy the current index's options,
spelling words, etc., to.</p>""".format(QApplication.applicationName())))
        self.copyGroupBox = QGroupBox("Copy")
        self.configCheckBox = QCheckBox("&Options")
        self.tooltips.append((self.configCheckBox, """\
<p><b>Options</b></p>
<p>If checked, copy all the current index's option and output option
settings (language, sort as and page range rules, display preferences,
fonts, output style, etc.) to the new empty copy.</p>"""))
        self.spellWordsCheckBox = QCheckBox("&Spelling Words")
        self.tooltips.append((self.spellWordsCheckBox, """\
<p><b>Spelling Words</b></p>
<p>If checked, copy all the current index's spelling words to the new
empty copy.</p>"""))
        self.ignoredFirstWordsCheckBox = QCheckBox(
            "&Ignored Subentry Function Words")
        self.tooltips.append((self.ignoredFirstWordsCheckBox, """\
<p><b>Ignored Subentry Function Words</b></p>
<p>If checked, copy all the current index's ignored subentry function
words words to the new empty copy.</p>"""))
        self.customMarkupCheckBox = QCheckBox("Custom &Markup")
        self.tooltips.append((self.customMarkupCheckBox, """\
<p><b>Custom Markup</b></p>
<p>If checked, copy all the current index's custom markup to the new
empty copy.</p>"""))
        self.groupsCheckBox = QCheckBox("&Groups")
        self.tooltips.append((self.groupsCheckBox, """\
<p><b>Groups</b></p>
<p>If checked, copy all the current index's groups to the new empty
copy.</p>"""))
        self.autoReplaceCheckBox = QCheckBox("&Auto Replacements")
        self.tooltips.append((self.autoReplaceCheckBox, """\
<p><b>Auto Replacements</b></p>
<p>If checked, copy all the current index's auto replacements to the new
empty copy.</p>"""))
        for checkbox in (self.configCheckBox, self.spellWordsCheckBox,
                         self.ignoredFirstWordsCheckBox,
                         self.customMarkupCheckBox, self.groupsCheckBox,
                         self.autoReplaceCheckBox):
            checkbox.setChecked(True)
        self.helpButton = QPushButton(QIcon(":/help.svg"), "Help")
        self.tooltips.append(
            (self.helpButton, "Help on the New Empty Copy dialog"))
        self.newCopyButton = QPushButton(QIcon(":/document-new.svg"),
                                         "&New Empty Copy")
        self.tooltips.append((self.newCopyButton, """\
<p><b>New Empty Copy</b></p>
<p>Create a new empty index and copy the options, spelling words,
etc.&mdash;providing they have been checked&mdash;into the new
index.</p>"""))
        self.cancelButton = QPushButton(QIcon(":/dialog-close.svg"), "&Cancel")
        self.tooltips.append((self.cancelButton, """<p><b>Cancel</b></p>
<p>Close the dialog without making a new empty copy.</p>"""))

    def layoutWidgets(self):
        layout = QVBoxLayout()
        hbox = QHBoxLayout()
        hbox.addWidget(self.filenameLabelLabel)
        hbox.addWidget(self.filenameLabel, 1)
        hbox.addWidget(self.filenameButton)
        layout.addLayout(hbox)
        grid = QGridLayout()
        grid.addWidget(self.configCheckBox, 0, 0)
        grid.addWidget(self.autoReplaceCheckBox, 0, 1)
        grid.addWidget(self.spellWordsCheckBox, 1, 0)
        grid.addWidget(self.ignoredFirstWordsCheckBox, 1, 1)
        grid.addWidget(self.groupsCheckBox, 2, 0)
        grid.addWidget(self.customMarkupCheckBox, 2, 1)
        hbox = QHBoxLayout()
        hbox.addLayout(grid)
        hbox.addStretch()
        self.copyGroupBox.setLayout(hbox)
        layout.addWidget(self.copyGroupBox)
        layout.addStretch()
        buttonBox = QDialogButtonBox()
        buttonBox.addButton(self.newCopyButton, QDialogButtonBox.AcceptRole)
        buttonBox.addButton(self.cancelButton, QDialogButtonBox.RejectRole)
        buttonBox.addButton(self.helpButton, QDialogButtonBox.HelpRole)
        layout.addWidget(buttonBox)
        self.setLayout(layout)

    def createConnections(self):
        self.newCopyButton.clicked.connect(self.accept)
        self.cancelButton.clicked.connect(self.reject)
        self.helpButton.clicked.connect(self.help)
        self.filenameButton.clicked.connect(self.setFilename)

    def updateUi(self):
        filename = self.filenameLabel.text()
        self.newCopyButton.setEnabled(
            bool(filename)
            and filename != os.path.normpath(self.state.model.filename))

    def setFilename(self):  # No need to restore focus widget
        with Lib.Qt.DisableUI(self, forModalDialog=True):
            filename, _ = QFileDialog.getSaveFileName(
                self,
                "New Empty Index — {}".format(QApplication.applicationName()),
                self.state.indexPath,
                "{} index (*{})".format(QApplication.applicationName(),
                                        EXTENSION))
        if filename and not filename.casefold().endswith(EXTENSION):
            filename += EXTENSION
        if filename:
            self.state.indexPath = os.path.dirname(filename)
            self.filenameLabel.setText(os.path.normpath(filename))
            self.updateUi()

    def help(self):
        self.state.help("xix_ref_dlg_newcopy.html")

    def accept(self):
        settings = QSettings()
        language = LanguageKind(
            settings.value(Gopt.Key.Language, Gopt.Default.Language))
        if self.configCheckBox.isChecked():
            sortasrules = Gopt.Default.SortAsRules
            pagerangerules = Gopt.Default.PageRangeRules
        else:
            sortasrules = self.state.model.sortAsRules()
            pagerangerules = self.state.model.pageRangeRules()
        copyInfo = CopyInfo(self.state.model.filename,
                            self.filenameLabel.text(),
                            self.configCheckBox.isChecked(),
                            self.customMarkupCheckBox.isChecked(),
                            self.spellWordsCheckBox.isChecked(),
                            self.ignoredFirstWordsCheckBox.isChecked(),
                            self.autoReplaceCheckBox.isChecked(),
                            self.groupsCheckBox.isChecked(),
                            self.state.model.username, language, sortasrules,
                            pagerangerules)
        self.state.window.closeXix()
        self.state.model.copyEmpty(copyInfo)
        self.state.window.openXix(copyInfo.newname)
        self.state.entryPanel.clearForm()
        self.state.setMode(ModeKind.VIEW)
        super().accept()