class MainWindow(QMainWindow): # Sets up the main window def resize_window(self): # Function for resizing the window self.resize(self.minimumSizeHint()) def __init__(self, parent=None): super(MainWindow, self).__init__(parent) # Set window Icon self.setWindowTitle(__appname__) iconImage = QImage(iconByteArray) iconPixmap = QPixmap(iconImage) self.setWindowIcon(QIcon(iconPixmap)) # Set up private key format widgets privateKeyFormatLayout = QHBoxLayout() privateKeyFormatLabel = QLabel('Select Key Format: ') self.privateKeyTypeCombobox = QComboBox() self.privateKeyTypeCombobox.addItems(privateKeyFormats) self.privateKeyLengthLabel = QLabel('0') privateKeyFormatLayout.addWidget(privateKeyFormatLabel) privateKeyFormatLayout.addWidget(self.privateKeyTypeCombobox) privateKeyFormatLayout.addWidget(self.privateKeyLengthLabel) # Set up private key text widgets privateKeyLayout = QVBoxLayout() privateKeyButtonsLayout = QHBoxLayout() generatePrivateKeyButton = QPushButton('Generate Key') generatePrivateKeyButton.clicked.connect(self.get_private_key) self.copyPrivateKeyButton = QPushButton('Copy Key') self.copyPrivateKeyButton.setDisabled(True) self.copyPrivateKeyButton.clicked.connect(self.copy_private_key) privateKeyButtonsLayout.addWidget(generatePrivateKeyButton) privateKeyButtonsLayout.addWidget(self.copyPrivateKeyButton) self.privateKeyEdit = GrowingTextEdit() self.privateKeyEdit.setFont(QFont('Courier')) self.privateKeyEdit.textChanged.connect( self.private_key_or_code_changed) privateKeyLayout.addLayout(privateKeyButtonsLayout) privateKeyLayout.addWidget(self.privateKeyEdit) # Set up cypher code widgets codeLayout = QHBoxLayout() codeLabel = QLabel('Select Cypher Code: ') self.codeSelect = QSpinBox() self.codeSelect.setValue(10) self.codeSelect.setMinimum(2) self.codeSelect.setDisabled(True) self.codeSelect.valueChanged.connect(self.private_key_or_code_changed) codeLayout.addWidget(codeLabel) codeLayout.addWidget(self.codeSelect) # Set up cypher text widgets cypherLayout = QVBoxLayout() cypherButtonsLayout = QHBoxLayout() cardButtonsLayout = QHBoxLayout() self.generateCypherButton = QPushButton('Generate Cypher') self.generateCypherButton.clicked.connect(self.get_cypher) self.generateCypherButton.setDisabled(True) self.copyCypherButton = QPushButton('Copy Cypher') self.copyCypherButton.setDisabled(True) self.copyCypherButton.clicked.connect(self.copy_cypher) cypherButtonsLayout.addWidget(self.generateCypherButton) cypherButtonsLayout.addWidget(self.copyCypherButton) self.cypherEdit = GrowingTextEdit() self.cypherEdit.setFont(QFont('Courier')) self.cypherEdit.setReadOnly(True) self.cypherEdit.setVisible(False) self.cypherEdit.textChanged.connect(self.resize_window) self.cypherPreviewLabel = QLabel('-CYPHER PREVIEW-') self.cypherPreviewLabel.setAlignment(Qt.AlignCenter) self.cypherPreviewLabel.setVisible(False) self.cypherPreview = GrowingTextEdit() self.cypherPreview.setFont(QFont('Courier')) self.cypherPreview.setAlignment(Qt.AlignHCenter) self.cypherPreview.setWordWrapMode(QTextOption.NoWrap) self.cypherPreview.setReadOnly(True) self.cypherPreview.setVisible(False) self.cypherCardsPrintButton = QPushButton('Print Cypher Cards') self.cypherCardsPrintButton.setVisible(False) self.cypherCardsPrintButton.clicked.connect(partial(self.cards, True)) self.cypherCardsCopyButton = QPushButton('Copy Cypher Cards') self.cypherCardsCopyButton.setVisible(False) self.cypherCardsCopyButton.clicked.connect(partial(self.cards, False)) cardButtonsLayout.addWidget(self.cypherCardsPrintButton) cardButtonsLayout.addWidget(self.cypherCardsCopyButton) cypherLayout.addLayout(cypherButtonsLayout) cypherLayout.addWidget(self.cypherEdit) cypherLayout.addWidget(self.cypherPreviewLabel) cypherLayout.addWidget(self.cypherPreview) cypherLayout.addLayout(cardButtonsLayout) # Set up donation widgets donationsLayout = QVBoxLayout() separater = QFrame() separater.setFrameShape(QFrame.HLine) self.donationButton = QPushButton('Donate') self.donationButton.setVisible(False) self.donationButton.clicked.connect(self.donate) self.copyEthAddressButton = QPushButton('ETH: Copy Address') self.copyEthAddressButton.clicked.connect( self.copy_eth_donation_address) self.copyEthAddressButton.setVisible(False) self.copyBtcAddressButton = QPushButton('BTC: Copy Address') self.copyBtcAddressButton.clicked.connect( self.copy_btc_donation_address) self.copyBtcAddressButton.setVisible(False) donationsLayout.addWidget(separater) donationsLayout.addWidget(self.donationButton) donationsLayout.addWidget(self.copyEthAddressButton) donationsLayout.addWidget(self.copyBtcAddressButton) # Add all widgets and sub-layouts to the master layout self.master_layout = QVBoxLayout() self.master_layout.addLayout(privateKeyFormatLayout) self.master_layout.addLayout(privateKeyLayout) self.master_layout.addLayout(codeLayout) self.master_layout.addLayout(cypherLayout) self.master_layout.addLayout(donationsLayout) self.master_widget = QWidget() self.master_widget.setLayout(self.master_layout) self.setCentralWidget(self.master_widget) # Start and connect the window resizing thread self.worker = Worker() self.worker.updateWindowSize.connect(self.resize_window) def copy_private_key( self): # Copies the private key text to the system clipboard clip.setText(self.privateKeyEdit.toPlainText()) self.copyPrivateKeyButton.setText('Key Copied') app.processEvents() sleep(2) self.copyPrivateKeyButton.setText('Copy Key') def copy_cypher(self): # Copies the cypher text to the system clipboard clip.setText(self.cypherEdit.toPlainText()) self.copyCypherButton.setText('Cypher Copied') app.processEvents() sleep(2) self.copyCypherButton.setText('Copy Cypher') def copy_eth_donation_address( self): # Copies the ETH donation address to the system clipboard clip.setText(ethDonationAddress) self.copyEthAddressButton.setText('ETH: Address Copied\nThanks!') app.processEvents() sleep(2) self.copyEthAddressButton.setText('ETH: Copy Address') def copy_btc_donation_address( self): # Copies the BTC donation address to the system clipboard clip.setText(btcDonationAddress) self.copyBtcAddressButton.setText('BTC: Address Copied\nThanks!') app.processEvents() sleep(2) self.copyBtcAddressButton.setText('BTC: Copy Address') def get_private_key( self ): # Generates a key of the desired format using two instances of the SystemRandom function privateKey = generate_private_key.start( self.privateKeyTypeCombobox.currentText()) self.privateKeyEdit.setText(privateKey) self.private_key_or_code_changed() self.copyPrivateKeyButton.setDisabled(False) def private_key_or_code_changed( self ): # Changes visibility and ability of some widgets based on user input self.privateKeyLengthLabel.setText( str(len(self.privateKeyEdit.toPlainText()))) self.copyCypherButton.setDisabled(True) self.cypherEdit.setText('') self.cypherPreview.setText('') self.cypherEdit.setVisible(False) self.cypherPreviewLabel.setVisible(False) self.cypherPreview.setVisible(False) if len(self.privateKeyEdit.toPlainText()) <= 2: self.copyPrivateKeyButton.setDisabled(True) self.generateCypherButton.setDisabled(True) self.codeSelect.setDisabled(True) else: self.codeSelect.setMaximum( len(self.privateKeyEdit.toPlainText()) - 1) self.copyPrivateKeyButton.setDisabled(False) self.generateCypherButton.setDisabled(False) self.codeSelect.setDisabled(False) self.cypherCardsPrintButton.setDisabled(True) self.cypherCardsPrintButton.setVisible(False) self.cypherCardsCopyButton.setDisabled(True) self.cypherCardsCopyButton.setVisible(False) self.worker.start() def get_cypher( self ): # Converts the raw key into a cypher based on the codeSelect value if not 1 >= len(self.privateKeyEdit.toPlainText()) >= int( self.privateKeyLengthLabel.text()): self.generateCypherButton.setDisabled(False) cypherRows, cypherSeed = create_cypher.start( self.privateKeyEdit.toPlainText(), self.codeSelect.value()) self.copyCypherButton.setDisabled(False) self.cypherEdit.setVisible(True) self.cypherEdit.setText(cypherSeed) self.cypherPreviewLabel.setVisible(True) self.cypherPreview.setVisible(True) previewText = '' for i in cypherRows: previewText += i + '\n' self.cypherPreview.setText(previewText) self.worker.start() self.cypherCardsPrintButton.setDisabled(False) self.cypherCardsPrintButton.setVisible(True) self.cypherCardsCopyButton.setDisabled(False) self.cypherCardsCopyButton.setVisible(True) self.donationButton.setVisible(True) else: self.generateCypherButton.setDisabled(True) def cards(self, print): # Creates and prints the output.txt file cardList = split_cypher_into_pairs.start(self.cypherEdit.toPlainText()) printString = format_cards.start(cardList) if print: self.cypherCardsPrintButton.setText('Printing') app.processEvents() cards_output.start(printString) self.cypherCardsPrintButton.setText('Print Cypher Cards') else: clip.setText(printString) self.cypherCardsCopyButton.setText('Cards Copied') app.processEvents() sleep(2) self.cypherCardsCopyButton.setText('Copy Cypher Cards') def donate(self): # Adjusts the visibility of the donation buttons if self.donationButton.text() == 'Donate': self.copyEthAddressButton.setVisible(True) self.copyBtcAddressButton.setVisible(True) self.donationButton.setText('Hide') elif self.donationButton.text() == 'Hide': self.copyEthAddressButton.setVisible(False) self.copyBtcAddressButton.setVisible(False) self.donationButton.setText('Donate') self.worker.start() def cleanup(self): # Clears the clipboard of any copied text clip.setText('')
class UI(gobject.GObject): __gsignals__ = { 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) } def __init__(self,args,continuous): self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) #make a window self.window = QMainWindow() #give the window a name self.window.setWindowTitle("BlatherQt") self.window.setMaximumSize(400,200) center = QWidget() self.window.setCentralWidget(center) layout = QVBoxLayout() center.setLayout(layout) #make a listen/stop button self.lsbutton = QPushButton("Listen") layout.addWidget(self.lsbutton) #make a continuous button self.ccheckbox = QCheckBox("Continuous Listen") layout.addWidget(self.ccheckbox) #connect the buttons self.lsbutton.clicked.connect(self.lsbutton_clicked) self.ccheckbox.clicked.connect(self.ccheckbox_clicked) #add a label to the UI to display the last command self.label = QLabel() layout.addWidget(self.label) #add the actions for quiting quit_action = QAction(self.window) quit_action.setShortcut('Ctrl+Q') quit_action.triggered.connect(self.accel_quit) self.window.addAction(quit_action) def accel_quit(self): #emit the quit self.emit("command", "quit") #function for managing the continuou listening check box being clicked. When it is clicked it #emits an event for blather to let blather know that the state of things has changed. This is #caught by blather's process_command function. def ccheckbox_clicked(self): checked = self.ccheckbox.isChecked() if checked: #disable lsbutton self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") self.set_icon_active() else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") self.set_icon_inactive() #functions related to the listen button. lsbutton_stopped is a quasi place holder for if I #want to expand the end of listening to do other things as well. def lsbutton_stopped(self): self.lsbutton.setText("Listen") def lsbutton_clicked(self): val = self.lsbutton.text() if val == "Listen": self.emit("command", "listen") self.lsbutton.setText("Stop") #clear the label self.label.setText("") self.set_icon_active() else: self.lsbutton_stopped() self.emit("command", "stop") self.set_icon_inactive() #called by blather right before the main loop is started. Mainloop is handled by gst. def run(self): self.set_icon_inactive() self.window.show() if self.continuous: self.set_icon_active() self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") #This function is called when it hears a pause in the audio. #This is called after the command has been sent of to the commander. def finished(self, text): #if the continuous isn't pressed if not self.ccheckbox.isChecked(): self.lsbutton_stopped() self.label.setText(text) #functions dealing with the icon def set_icon(self, icon): self.window.setWindowIcon(QIcon(icon)) def set_icon_active_asset(self, i): self.icon_active = i def set_icon_inactive_asset(self, i): self.icon_inactive = i def set_icon_active(self): self.window.setWindowIcon(QIcon(self.icon_active)) def set_icon_inactive(self): self.window.setWindowIcon(QIcon(self.icon_inactive))
class PythonKeyboard(MAbstractInputMethod): EXAMPLE_SUBVIEW_ID = "ExamplePluginSubview1" def __init__(self, host, mainWindow): MAbstractInputMethod.__init__(self, host, mainWindow) self._showIsInhibited = False self._showRequested = False self._mainWidget = QPushButton("Hello World by PySide", mainWindow) self._mainWidget.clicked[None].connect(self.onButtonClicked) host.sendCommitString("Maliit") host.sendPreeditString("Mali", [], 0, 6) def onButtonClicked(self): self.inputMethodHost().sendCommitString(self._mainWidget.text()) def show(self): self._showRequested = True if self._showIsInhibited: return screenSize = qApp.desktop().screenGeometry().size() self._mainWidget.parentWidget().resize(screenSize) imGeometry = QRect(0, screenSize.height() - 200, screenSize.width(), 200); self._mainWidget.setGeometry(imGeometry) self.inputMethodHost().setScreenRegion(QRegion(self._mainWidget.geometry())) self.inputMethodHost().setInputMethodArea(QRegion(self._mainWidget.geometry())) self._mainWidget.show() def hide(self): if not self._showRequested: return; self._showRequested = False self._mainWidget.hide() self.inputMethodHost().setScreenRegion(QRegion()) self.inputMethodHost().setInputMethodArea(QRegion()) def subViews(self, state): subViews = [] if state == MInputMethod.OnScreen: subView1 = MAbstractInputMethod.MInputMethodSubView() subView1.subViewId = PythonKeyboard.EXAMPLE_SUBVIEW_ID subView1.subViewTitle = "Example plugin subview 1"; subViews.append(subView1) return subViews def activeSubView(self, state): if state == MInputMethod.OnScreen: return PythonKeyboard.EXAMPLE_SUBVIEW_ID else: return "" def setState(self, states): if MInputMethod.OnScreen in states: if self._showRequested and not self._showIsInhibited: self._mainWidget.show() else: self.mainWidget.hide() def handleClientChange(self): if self._showRequested: self.hide() def handleVisualizationPriorityChange(self, inhibitShow): if self._showIsInhibited == inhibitShow: return self._showIsInhibited = inhibitShow if self._showRequested: if inhibitShow: self._mainWidget.hide() else: self._mainWidget.show()
class UI(gobject.GObject): __gsignals__ = { 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) } def __init__(self,args,continuous): self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) #make a window self.window = QMainWindow() #give the window a name self.window.setWindowTitle("BlatherQt") self.window.setMaximumSize(400,200) center = QWidget() self.window.setCentralWidget(center) layout = QVBoxLayout() center.setLayout(layout) #make a listen/stop button self.lsbutton = QPushButton("Listen") layout.addWidget(self.lsbutton) #make a continuous button self.ccheckbox = QCheckBox("Continuous Listen") layout.addWidget(self.ccheckbox) #connect the buttonsc self.lsbutton.clicked.connect(self.lsbutton_clicked) self.ccheckbox.clicked.connect(self.ccheckbox_clicked) #add a label to the UI to display the last command self.label = QLabel() layout.addWidget(self.label) def ccheckbox_clicked(self): checked = self.ccheckbox.isChecked() if checked: #disable lsbutton self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") def lsbutton_stopped(self): self.lsbutton.setText("Listen") def lsbutton_clicked(self): val = self.lsbutton.text() if val == "Listen": self.emit("command", "listen") self.lsbutton.setText("Stop") #clear the label self.label.setText("") else: self.lsbutton_stopped() self.emit("command", "stop") def run(self): self.window.show() if self.continuous: self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") def quit(self): pass def finished(self, text): print text #if the continuous isn't pressed if not self.ccheckbox.isChecked(): self.lsbutton_stopped() self.label.setText(text) def quit(self): #sys.exit() pass
class UI(gobject.GObject): __gsignals__ = { 'command': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )) } def __init__(self, args, continuous): self.continuous = continuous gobject.GObject.__init__(self) #start by making our app self.app = QApplication(args) #make a window self.window = QMainWindow() #give the window a name self.window.setWindowTitle("BlatherQt") self.window.setMaximumSize(400, 200) center = QWidget() self.window.setCentralWidget(center) layout = QVBoxLayout() center.setLayout(layout) #make a listen/stop button self.lsbutton = QPushButton("Listen") layout.addWidget(self.lsbutton) #make a continuous button self.ccheckbox = QCheckBox("Continuous Listen") layout.addWidget(self.ccheckbox) #connect the buttons self.lsbutton.clicked.connect(self.lsbutton_clicked) self.ccheckbox.clicked.connect(self.ccheckbox_clicked) #add a label to the UI to display the last command self.label = QLabel() layout.addWidget(self.label) #add the actions for quiting quit_action = QAction(self.window) quit_action.setShortcut('Ctrl+Q') quit_action.triggered.connect(self.accel_quit) self.window.addAction(quit_action) def accel_quit(self): #emit the quit self.emit("command", "quit") def ccheckbox_clicked(self): checked = self.ccheckbox.isChecked() if checked: #disable lsbutton self.lsbutton.setEnabled(False) self.lsbutton_stopped() self.emit('command', "continuous_listen") else: self.lsbutton.setEnabled(True) self.emit('command', "continuous_stop") def lsbutton_stopped(self): self.lsbutton.setText("Listen") def lsbutton_clicked(self): val = self.lsbutton.text() if val == "Listen": self.emit("command", "listen") self.lsbutton.setText("Stop") #clear the label self.label.setText("") else: self.lsbutton_stopped() self.emit("command", "stop") def run(self): self.window.show() if self.continuous: self.ccheckbox.setCheckState(Qt.Checked) self.ccheckbox_clicked() self.app.exec_() self.emit("command", "quit") def finished(self, text): print text #if the continuous isn't pressed if not self.ccheckbox.isChecked(): self.lsbutton_stopped() self.label.setText(text) def set_icon(self, icon): self.window.setWindowIcon(QIcon(icon))