Python PyQt5.QtWidgets.QApplication.clipboard() Examples

The following are code examples for showing how to use PyQt5.QtWidgets.QApplication.clipboard(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: kucher   Author: Zubax   File: little_bobby_tables_widget.py    GNU General Public License v3.0 7 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.matches(QKeySequence.Copy):
            selected_rows = [x.row() for x in self._table.selectionModel().selectedIndexes()]
            _logger.info('Copying the following rows to the clipboard: %r', selected_rows)

            if len(selected_rows) == 1:
                out_strings = [self._table.item(selected_rows[0], 0).text()]
            else:
                out_strings = []
                for row in selected_rows:
                    header = self._table.verticalHeaderItem(row).text()
                    data = self._table.item(row, 0).text()
                    out_strings.append(f'{header}\t{data}')

            if out_strings:
                QApplication.clipboard().setText(os.linesep.join(out_strings))
        else:
            super(LittleBobbyTablesWidget, self).keyPressEvent(event) 
Example 2
Project: kucher   Author: Zubax   File: __init__.py    GNU General Public License v3.0 6 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent):
        if event.matches(QKeySequence.Copy):
            selected_indexes = [(x.row(), x.column()) for x in self.selectionModel().selectedIndexes()]
            _logger.info('Copying the following items to the clipboard: %r', selected_indexes)

            # Dicts are ordered now. Yay!
            by_row = {}
            for row, column in sorted(selected_indexes):
                by_row.setdefault(row, []).append(column)

            out_strings = []
            for row, column_list in by_row.items():
                out_strings.append('\t'.join([self._model.render_item_for_clipboard(self._model.index(row, col))
                                             for col in column_list]))

            if out_strings:
                QApplication.clipboard().setText(os.linesep.join(out_strings))
        else:
            super(_TableView, self).keyPressEvent(event) 
Example 3
Project: resnet-finetune-demo   Author: cta-ai   File: resnet_demo.py    MIT License 6 votes vote down vote up
def clipboard_changed():
    clipboard = QApplication.clipboard()
    try:
        if clipboard.mimeData().hasImage():
            image = clipboard.pixmap()
            image = helper.qimage_to_array(image)
            clipboard.clear()
            if image.shape:
                print("----------------------------------------------------------------------------------------")
                print("Processing: image from clipboard")
                process(image)
                skimage.io.imshow(image[:,:,::-1])
                plt.show()
                print("\nWaiting for an image...")

    except Exception as e:
        print("ERROR:", e) 
Example 4
Project: PyQt5-Apps   Author: taseikyo   File: main.py    GNU General Public License v3.0 6 votes vote down vote up
def onClipboradChanged(self):
        if self.isCopyFromTrans:
            self.isCopyFromTrans = False
            return
        clipboard = QApplication.clipboard()
        text = clipboard.text()
        if text and self.isRealTimeTrans:
            content = str(text)
            # print(content)
            content = content.replace('€', 'fi').replace('', 'ffi').replace('‚', 'ff').replace('ƒ', 'fl').replace('Œ', 'th').replace('‡', 'ft').replace('‰', 'ft').replace('Š', 'tt')
            if self.paperMode.isChecked(): # if paper mode is true, line breaks will re replaced by blanks
                content = re.sub(r'\n|\s+', ' ', content)
                content = re.sub(r'', '', content)
            self.originText.setPlainText(content)
            self.transText.setPlainText(content)
            try:
                # data = trans_To_zh_CN(content)
                # self.transText.setPlainText(data)
                self.t=GTranslator(self.dest, content)
                self.t.start()
                self.transText.setPlainText("")
                self.transText.setPlaceholderText("...")
                self.t.trigger.connect(self.translated)
            except:
                self.transText.setPlainText("error!") 
Example 5
Project: PyFormula   Author: panda2134   File: main_window.py    GNU General Public License v3.0 6 votes vote down vote up
def load_image(self, img: QImage):
        if not (img is None):
            multiplier = config_handler.multipliers[config_handler.get_config_parser().get('DEFAULT', 'Render')]
            img = img.scaledToHeight(img.size().height() * multiplier, Qt.SmoothTransformation)
            if img.size().width() > self.imgLabel.size().width() \
                    or img.size().height() > self.imgLabel.size().height():
                img = MainWindow.scale_image_to_label(img, self.imgLabel)
            self.img = img
            pixmap = QPixmap.fromImage(img)
            self.imgLabel.setPixmap(pixmap)
            self.statusBar().showMessage('Connected.')
        else:
            self.img = None
            self.statusBar().showMessage('Disconnected.')

        if config_handler.get_config_parser().getboolean('DEFAULT', 'ListenToClip'):
            img_transparent = to_transparent_image(img)

            mime = QMimeData()
            mime.setImageData(img_transparent)

            QApplication.clipboard().setMimeData(mime)

        self.waiting = False 
Example 6
Project: sparrow-wifi   Author: ghostop14   File: sparrow-wifi.py    GNU General Public License v3.0 6 votes vote down vote up
def onCopyNet(self):
        self.updateLock.acquire()
        
        curRow = self.networkTable.currentRow()
        curCol = self.networkTable.currentColumn()
        
        if curRow == -1 or curCol == -1:
            self.updateLock.release()
            return
        
        if curCol != 11:
            curText = self.networkTable.item(curRow, curCol).text()
        else:
            curNet = self.networkTable.item(curRow, 2).data(Qt.UserRole+1)
            curText = 'Last Recorded GPS Coordinates:\n' + str(curNet.gps)
            curText += 'Strongest Signal Coordinates:\n'
            curText += 'Strongest Signal: ' + str(curNet.strongestsignal) + '\n'
            curText += str(curNet.strongestgps)
            
        clipboard = QApplication.clipboard()
        clipboard.setText(curText)
        
        self.updateLock.release() 
Example 7
Project: sparrow-wifi   Author: ghostop14   File: telemetry.py    GNU General Public License v3.0 6 votes vote down vote up
def createTable(self):
        # Set up location table
        self.locationTable = QTableWidget(self)
        self.locationTable.setColumnCount(8)
        self.locationTable.setGeometry(10, 10, self.geometry().width()/2-20, self.geometry().height()/2)
        self.locationTable.setShowGrid(True)
        self.locationTable.setHorizontalHeaderLabels(['macAddr','SSID', 'Strength', 'Timestamp','GPS', 'Latitude', 'Longitude', 'Altitude'])
        self.locationTable.resizeColumnsToContents()
        self.locationTable.setRowCount(0)
        self.locationTable.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
        
        self.ntRightClickMenu = QMenu(self)
        newAct = QAction('Copy', self)        
        newAct.setStatusTip('Copy data to clipboard')
        newAct.triggered.connect(self.onCopy)
        self.ntRightClickMenu.addAction(newAct)
        
        self.locationTable.setContextMenuPolicy(Qt.CustomContextMenu)
        self.locationTable.customContextMenuRequested.connect(self.showNTContextMenu) 
Example 8
Project: sparrow-wifi   Author: ghostop14   File: telemetry.py    GNU General Public License v3.0 6 votes vote down vote up
def onCopy(self):
        self.updateLock.acquire()
        
        curRow = self.locationTable.currentRow()
        curCol = self.locationTable.currentColumn()
        
        if curRow == -1 or curCol == -1:
            self.updateLock.release()
            return
        
        curText = self.locationTable.item(curRow, curCol).text()
            
        clipboard = QApplication.clipboard()
        clipboard.setText(curText)
        
        self.updateLock.release() 
Example 9
Project: sparrow-wifi   Author: ghostop14   File: telemetry.py    GNU General Public License v3.0 6 votes vote down vote up
def createTable(self):
        # Set up location table
        self.locationTable = QTableWidget(self)
        self.locationTable.setColumnCount(10)
        self.locationTable.setGeometry(10, 10, self.geometry().width()/2-20, self.geometry().height()/2)
        self.locationTable.setShowGrid(True)
        self.locationTable.setHorizontalHeaderLabels(['macAddr','Name', 'RSSI', 'TX Power', 'Est Range (m)', 'Timestamp','GPS', 'Latitude', 'Longitude', 'Altitude'])
        self.locationTable.resizeColumnsToContents()
        self.locationTable.setRowCount(0)
        self.locationTable.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
        
        self.ntRightClickMenu = QMenu(self)
        newAct = QAction('Copy', self)        
        newAct.setStatusTip('Copy data to clipboard')
        newAct.triggered.connect(self.onCopy)
        self.ntRightClickMenu.addAction(newAct)
        
        self.locationTable.setContextMenuPolicy(Qt.CustomContextMenu)
        self.locationTable.customContextMenuRequested.connect(self.showNTContextMenu) 
Example 10
Project: ObservationTools   Author: iastro-pt   File: visibility.py    MIT License 6 votes vote down vote up
def add_clipboard_to_figures():
    # replace the original plt.figure() function with one that supports 
    # clipboard-copying
    oldfig = plt.figure

    def newfig(*args, **kwargs):
        fig = oldfig(*args, **kwargs)
        def clipboard_handler(event):
            if event.key == 'ctrl+c':
                # store the image in a buffer using savefig(), this has the
                # advantage of applying all the default savefig parameters
                # such as background color; those would be ignored if you simply
                # grab the canvas using Qt
                buf = io.BytesIO()
                fig.savefig(buf)
                QApplication.clipboard().setImage(QImage.fromData(buf.getvalue()))
                buf.close()
                print('Ctrl+C pressed: image is now in the clipboard')

        fig.canvas.mpl_connect('key_press_event', clipboard_handler)
        return fig

    plt.figure = newfig 
Example 11
Project: legion   Author: GoVanguard   File: eventfilter.py    GNU General Public License v3.0 6 votes vote down vote up
def filterKeyPressInHostsTableView(self, key, receiver):
        if not receiver.selectionModel().selectedRows():
            return True

        index = receiver.selectionModel().selectedRows()[0].row()

        if key == Qt.Key_Down:
            new_index = index + 1
            receiver.selectRow(new_index)
            receiver.clicked.emit(receiver.selectionModel().selectedRows()[0])
        elif key == Qt.Key_Up:
            new_index = index - 1
            receiver.selectRow(new_index)
            receiver.clicked.emit(receiver.selectionModel().selectedRows()[0])
        elif QApplication.keyboardModifiers() == Qt.ControlModifier and key == Qt.Key_C:
            selected = receiver.selectionModel().currentIndex()
            clipboard = QApplication.clipboard()
            clipboard.setText(selected.data().toString())
        return True 
Example 12
Project: paper-translator   Author: lkjie   File: paperTran.py    MIT License 6 votes vote down vote up
def __init__(self, sender, parent=None):
        super().__init__(parent)
        self.editor = sender
        self.form = parent
        self.timer = QTimer()
        self.timer.setInterval(TRANS_INTERVAL)
        self.timer.start()
        # 信号连接到槽
        self.timer.timeout.connect(self.onTimerOut)
        self.lastTran = ''
        self.lastTranWord = ''
        self.clipboard = QApplication.clipboard()

        self.storeTimer = QTimer()
        self.storeTimer.setInterval(STORE_INTERVAL)
        self.storeTimer.start()
        self.timer.timeout.connect(self.restoreTimeOut)

    # 定义槽 
Example 13
Project: MovieHeavens   Author: lt94   File: movies.py    GNU General Public License v2.0 5 votes vote down vote up
def copy_text(self):
        copied_text = self.search_content_text_list.currentItem().text()
        QApplication.clipboard().clear()
        QApplication.clipboard().setText(copied_text)
        self.slot_information() 
Example 14
Project: persepolis   Author: persepolisdm   File: mainwindow.py    GNU General Public License v3.0 5 votes vote down vote up
def dropEvent(self, droplink):
        link_clipborad = QApplication.clipboard()
        link_clipborad.clear(mode=link_clipborad.Clipboard)
        link_string = droplink.mimeData().text()
        link_clipborad.setText(str(link_string), mode=link_clipborad.Clipboard)
        self.addLinkButtonPressed(button=link_clipborad)

    # aria2 identifies each download by the ID called GID.
    # The GID must be hex string of 16 characters,
    # thus [0-9a-zA-Z] are allowed and leading zeros must
    # not be stripped. The GID all 0 is reserved and must
    # not be used. The GID must be unique, otherwise error
    # is reported and the download is not added.
    # gidGenerator generates GID for downloads 
Example 15
Project: ocelot   Author: ocelot-collab   File: ocl_table.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, evt):
        """
        Grabs string from the clipboard if middle button click.

        Tries to then add the PV to the parent GUI pv lists.
        Calls parent.addPv() method.

        Args:
                evt (QEvent): Event object passed in from QT
        """
        button = evt.button()
        #print("TW Release event: ", button)
        if button == 4:

            pv = QApplication.clipboard().text()
            print(pv)
            #self.parent.addPv(pv)
            #print(QtGui.QApplication.clipboard().text())
        #elif button == 1:
        #
        #    #pv = QApplication.clipboard().text()
        #    #print(pv)
        #    #self.parent.addPv(pv)
        #    #print(QtGui.QApplication.clipboard().text())
        #    for currentQTableWidgetItem in self.parent.ui.tableWidget.selectedItems():
        #        print(currentQTableWidgetItem.row(), currentQTableWidgetItem.column(), currentQTableWidgetItem.text())
        #        if currentQTableWidgetItem.checkState() == QtCore.Qt.Checked:
        #            currentQTableWidgetItem.setCheckState(QtCore.Qt.Unchecked)
        #            print(currentQTableWidgetItem.checkState(), QtCore.Qt.Unchecked)
        #        else:
        #            currentQTableWidgetItem.setCheckState(QtCore.Qt.Checked)
        else:
            QTableWidget.mouseReleaseEvent(self, evt) 
Example 16
Project: kdFileFinder   Author: bkdwei   File: copy_filename.py    GNU General Public License v3.0 5 votes vote down vote up
def execute(self,script_variable):
        cur_file = script_variable["file_list"][0]
        clipboard = QApplication.clipboard()
        clipboard.setText(cur_file) 
Example 17
Project: kdFileFinder   Author: bkdwei   File: copy.py    GNU General Public License v3.0 5 votes vote down vote up
def execute(self,script_variable):
        cur_path = script_variable["cur_path"]
        file_list = script_variable["file_list"]
        
        files = ""
        for f in file_list :
            files += "file://" +  cur_path + "/" + f + "\r\n"
        
        mimeData = QMimeData()
        mimeData.setData("text/uri-list",files.encode())
        clipboard = QApplication.clipboard()
        clipboard.setMimeData(mimeData)
        
        print("成功复制到剪切板" , files) 
Example 18
Project: kdFileFinder   Author: bkdwei   File: copy_filepath.py    GNU General Public License v3.0 5 votes vote down vote up
def execute(self,script_variable):
        cur_filepath = join(script_variable["cur_path"],script_variable["file_list"][0])
        clipboard = QApplication.clipboard()
        clipboard.setText(cur_filepath) 
Example 19
Project: urxui   Author: SintefManufacturing   File: mainwindow.py    GNU General Public License v3.0 5 votes vote down vote up
def copy_joints(self):
        QApplication.clipboard().setText(self.ui.jointsLineEdit.text()) 
Example 20
Project: urxui   Author: SintefManufacturing   File: mainwindow.py    GNU General Public License v3.0 5 votes vote down vote up
def copy_pose(self):
        QApplication.clipboard().setText(self.ui.poseLineEdit.text()) 
Example 21
Project: PyQt5-Apps   Author: taseikyo   File: main.py    GNU General Public License v3.0 5 votes vote down vote up
def copySlot(self):
        s = self.transText.toPlainText()
        if s:
            self.isCopyFromTrans = True
            clipboard = QApplication.clipboard()
            clipboard.setText(s) 
Example 22
Project: PyFormula   Author: panda2134   File: main_window.py    GNU General Public License v3.0 5 votes vote down vote up
def load_from_clipboard(self):
        text = QApplication.clipboard().text()
        sep = config_handler.get_config_parser().get('DEFAULT', 'Sep')
        if len(text) >= 2 and text[0:len(sep)] == sep and text[-len(sep):] == sep:
            self.plainTextEdit.setPlainText(text[len(sep):-len(sep)]) 
Example 23
Project: PyFormula   Author: panda2134   File: main_window.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        # noinspection PyArgumentList
        super().__init__()

        self.init_window_flags()

        self.setWindowIcon(QIcon('ui/icon.png'))
        loadUi('ui/main.ui', self)

        # inject the event handler
        self.imgLabel.mouseMoveEvent = MethodType(mouseMoveEvent, self.imgLabel)

        if config_handler.get_config_parser().getboolean('DEFAULT', 'ListenToClip'):
            QApplication.clipboard().dataChanged.connect(self.load_from_clipboard) 
Example 24
Project: sparrow-wifi   Author: ghostop14   File: sparrowdialogs.py    GNU General Public License v3.0 5 votes vote down vote up
def onCopy(self):
        curRow = self.historyTable.currentRow()
        curCol = self.historyTable.currentColumn()
        
        if curRow == -1 or curCol == -1:
            return
        
        curText = self.historyTable.item(curRow, curCol).text()
            
        clipboard = QApplication.clipboard()
        clipboard.setText(curText) 
Example 25
Project: sparrow-wifi   Author: ghostop14   File: sparrowdialogs.py    GNU General Public License v3.0 5 votes vote down vote up
def onCopy(self):
        curRow = self.bluetoothTable.currentRow()
        curCol = self.bluetoothTable.currentColumn()
        
        if curRow == -1 or curCol == -1:
            return
        
        curText = self.bluetoothTable.item(curRow, curCol).text()
            
        clipboard = QApplication.clipboard()
        clipboard.setText(curText) 
Example 26
Project: CustomWidgets   Author: PyQt5   File: TestCFontIcon.py    GNU General Public License v3.0 5 votes vote down vote up
def onDoubleClicked(self, index):
        index = self.fmodel.mapToSource(index)
        text = index.data(Qt.ToolTipRole)
        if text:
            QApplication.clipboard().setText(text)
            self.statusBar.showMessage('已复制: %s' % text) 
Example 27
Project: ClosestX11Color   Author: jabbalaci   File: helper.py    MIT License 5 votes vote down vote up
def copy_text_to_clipboard(text: str) -> None:
    cb: QClipboard = QApplication.clipboard()
    cb.setText(text) 
Example 28
Project: ClosestX11Color   Author: jabbalaci   File: helper.py    MIT License 5 votes vote down vote up
def get_text_from_clipboard() -> str:
    cb: QClipboard = QApplication.clipboard()
    return str(cb.text()) 
Example 29
Project: Hash-Checker   Author: Rizwan-Hasan   File: main.py    MIT License 5 votes vote down vote up
def clipboardButtonActions_OnClick(self, hashName):
        try:
            self.clipboardMD5Button.clicked.disconnect()
            self.clipboardSHA256Button.clicked.disconnect()
            self.clipboardSHA512Button.clicked.disconnect()
        except:
            pass
        if(self.currentFileLoc != None):
            if(hashName == 'md5'):
                clipText = self.textBoxMD5.toPlainText()
                pyperclip.copy(clipText.strip())
                self.statusBar().showMessage('MD5sum has been copied to clipboard')
            elif(hashName == 'sha256'):
                clipText = self.textBoxSHA256.toPlainText()
                pyperclip.copy(clipText.strip())
                self.statusBar().showMessage('SHA256sum has been copied to clipboard')
            elif(hashName == 'sha512'):
                clipText = self.textBoxSHA512.toPlainText()
                pyperclip.copy(clipText.strip())
                self.statusBar().showMessage('SHA512sum has been copied to clipboard')
        else:
            pass
        self.clipboardMD5Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'md5'))
        self.clipboardSHA256Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'sha256'))
        self.clipboardSHA512Button.clicked.connect(partial(self.clipboardButtonActions_OnClick, 'sha512'))

    # Clipboard Text ↓ 
Example 30
Project: Hash-Checker   Author: Rizwan-Hasan   File: main.py    MIT License 5 votes vote down vote up
def clipboardText(self):
        try:
            self.clipboardButton.clicked.disconnect()
        except:
            pass
        clipText = QApplication.clipboard().text()
        clipText = clipText.strip()
        self.textBoxCheck.setText(clipText)
        self.loadingBallAnimation('start')
        self.clipboardButton.clicked.connect(self.clipboardText)

    # Clear Button's Action ↓ 
Example 31
Project: quartz-browser-qt5   Author: ksharindam   File: webkit.py    GNU General Public License v3.0 5 votes vote down vote up
def contextMenuEvent(self,event):
        menu = self.createStandardContextMenu()
        menu.addSeparator()
        cliptext = QApplication.clipboard().text()
        if not cliptext == '':
            menu.addAction('Paste and Go', self.pasteNgo)
        menu.addAction("Download Link", self.downloadLink)
        menu.exec_(self.mapToGlobal(event.pos())) 
Example 32
Project: quartz-browser-qt5   Author: ksharindam   File: webkit.py    GNU General Public License v3.0 5 votes vote down vote up
def pasteNgo(self):
        text = QApplication.clipboard().text()
        self.setText(text)
        self.openUrlRequested.emit() 
Example 33
Project: guppy-proxy   Author: roglew   File: util.py    MIT License 5 votes vote down vote up
def copy_to_clipboard(s):
    QApplication.clipboard().setText(s) 
Example 34
Project: guppy-proxy   Author: roglew   File: util.py    MIT License 5 votes vote down vote up
def paste_clipboard():
    return QApplication.clipboard().text() 
Example 35
Project: BlindWatermark   Author: fire-keeper   File: main_win.py    GNU General Public License v3.0 5 votes vote down vote up
def checkItem(self,index):

        file_path = (index.data().split('→'))[-1]
        if index.data()[:4]=='使用密钥':
            clipboard = QApplication.clipboard()
            clipboard.setText(file_path) #此处为密钥
        else:
            self.open_pic = open_pic_thread(file_path)
            self.open_pic.finished.connect(self.open_pic.deleteLater)
            self.open_pic.start()
        # QMessageBox.information(self,"ListView",'row:%s, text:%s' % (index.row(), index.data())) 
Example 36
Project: BlindWatermark   Author: fire-keeper   File: main_win.py    GNU General Public License v3.0 5 votes vote down vote up
def on_pushButton_6_clicked(self):
        """
        从剪切板导入密钥
        """
        clipboard = QApplication.clipboard()
        text = clipboard.text()
        try:
            key = json.loads(text)
            self.refresh_UI(key)
        except json.decoder.JSONDecodeError:
            QMessageBox.warning(self,"警告",'剪切板中的文本不符合key的格式(即json格式)',QMessageBox.Ok) 
Example 37
Project: paper-translator   Author: lkjie   File: paperTran.py    MIT License 5 votes vote down vote up
def translateSentence(self):
        '''
        condition: 
        not clipText 剪切板为空
        clipText == self.lastTran 剪切板无变化
        self.isActiveWindow() 当前窗口为活动窗口
        :return: 
        '''
        clipText = self.clipboard.text()
        clipText = self.form.translator.textClean(clipText)
        if not clipText or clipText in self.lastTran or self.isActiveWindow():
            return
        self.lastTran = clipText
        self.tranTrigger.emit(clipText) 
Example 38
Project: SEASide-py   Author: awolk   File: terminal.py    GNU General Public License v3.0 4 votes vote down vote up
def keyPressEvent(self, evt):
        key = evt.key()

        modifiers = evt.modifiers()
        shift = bool(modifiers & Qt.ShiftModifier)
        control = bool(modifiers & Qt.ControlModifier)
        alt = bool(modifiers & Qt.AltModifier)
        meta = bool(modifiers & Qt.MetaModifier)  # ctrl

        text = evt.text()

        if control and key == Qt.Key_C:
            # Copy
            super(Terminal, self).keyPressEvent(evt)

        if not self._term_em.open_connection():
            return

        w = self._term_em.write
        if control and key == Qt.Key_V:
            # Paste
            clip_text = QApplication.clipboard().text()
            w(clip_text)
        elif key == Qt.Key_Backspace:
            return w(ctrl.DEL)
        elif key == Qt.Key_Up:
            self._term_em.key_up()
        elif key == Qt.Key_Down:
            self._term_em.key_down()
        elif key == Qt.Key_Left:
            self._term_em.key_left()
        elif key == Qt.Key_Right:
            self._term_em.key_right()
        elif key == Qt.Key_Escape:
            return w(ctrl.ESC)
        elif meta:
            if text == ' ':
                return w(b'\000')
            elif ord('A') <= key <= ord('Z'):
                return w(chr(key - ord('A') + 1))
            elif text == '[':
                return w('\033')
            elif text == '\\':
                return w('\034')
            elif text == ']':
                return w('\035')
            elif text == '~':
                return w('\036')
            elif text == '?':
                return w('\037')
        elif alt and 0 <= key <= 255:
            # TODO: Make more robust
            char = chr(key)
            if not shift:
                char = char.lower()
            w(ctrl.ESC + char)
        else:
            w(text) 
Example 39
Project: sparrow-wifi   Author: ghostop14   File: sparrowdialogs.py    GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, mainWin, parent = None):
        super(GPSCoordDialog, self).__init__(parent)

        self.visibility.connect(self.onVisibilityChanged)
        
        self.mainWin = mainWin
        

        # Set up GPS check timer
        self.gpsTimer = QTimer()
        self.gpsTimer.timeout.connect(self.onGPSTimer)
        self.gpsTimer.setSingleShot(True)
        self.gpsTimerTimeout = 2000
        self.gpsTimer.start(self.gpsTimerTimeout)
        
        self.lastGPS = None
        self.firstUpdate = True
        
        self.lblMsg = QLabel("Newest coordinates are at the top", self)
        self.lblMsg.move(10, 20)

        self.historyTable = QTableWidget(self)
        self.historyTable.setColumnCount(6)
        self.historyTable.setShowGrid(True)
        self.historyTable.setHorizontalHeaderLabels(['Timestamp','Valid','Latitude', 'Longitude', 'Altitude', 'Speed'])
        self.historyTable.setGeometry(10, 30, 100, 30)
        self.historyTable.resizeColumnsToContents()
        self.historyTable.setRowCount(0)
        self.historyTable.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
       #  self.historyTable.horizontalHeader().sectionClicked.connect(self.onTableHeadingClicked)
       
        self.ntRightClickMenu = QMenu(self)
        newAct = QAction('Copy', self)        
        newAct.setStatusTip('Copy data to clipboard')
        newAct.triggered.connect(self.onCopy)
        self.ntRightClickMenu.addAction(newAct)
 
        # Attach it to the table
        self.historyTable.setContextMenuPolicy(Qt.CustomContextMenu)
        self.historyTable.customContextMenuRequested.connect(self.showNTContextMenu)
        
        self.setBlackoutColors()
        
        self.setGeometry(self.geometry().x(), self.geometry().y(), 500,320)
        self.setWindowTitle("GPS Coordinate Viewer")
        self.center()

        # initial update:
        if self.mainWin:
            curGPS = self.mainWin.getCurrentGPS()
            self.updateTable(curGPS) 
Example 40
Project: sparrow-wifi   Author: ghostop14   File: sparrowdialogs.py    GNU General Public License v3.0 4 votes vote down vote up
def __init__(self, mainWin, agentIP, agentPort, parent = None):
        super(RemoteFilesDialog, self).__init__(parent)

        self.visibility.connect(self.onVisibilityChanged)
        
        self.mainWin = mainWin
        
        self.remoteAgentIP = agentIP
        self.remoteAgentPort = agentPort

        self.lblMsg = QLabel("Remote Files", self)
        self.lblMsg.move(10, 20)

        self.btnRefresh = QPushButton("&Refresh", self)
        self.btnRefresh.setShortcut('Ctrl+R')
        self.btnRefresh.clicked.connect(self.onRefreshFiles)
        # self.btnRefresh.setStyleSheet("background-color: rgba(0,128,192,255); border: none;")
        # self.btnRefresh.move(90, 30)

        self.btnCopy = QPushButton("&Copy", self)
        self.btnCopy.clicked.connect(self.onCopyFiles)
        
        self.btnDelete = QPushButton("&Delete", self)
        self.btnDelete.clicked.connect(self.onDeleteFiles)
        
        self.fileTable = QTableWidget(self)
        self.fileTable.setColumnCount(3)
        self.fileTable.setShowGrid(True)
        self.fileTable.setHorizontalHeaderLabels(['Filename','Size','Last Modified'])
        #self.fileTable.setGeometry(10, 30, 100, 30)
        self.fileTable.resizeColumnsToContents()
        self.fileTable.setRowCount(0)
        self.fileTable.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
        self.fileTable.horizontalHeader().sectionClicked.connect(self.onTableHeadingClicked)
       
        self.fileTableSortOrder = Qt.DescendingOrder
        self.fileTableSortIndex = -1
        
        self.ntRightClickMenu = QMenu(self)
        newAct = QAction('Copy', self)        
        newAct.setStatusTip('Copy data to clipboard')
        newAct.triggered.connect(self.onCopy)
        self.ntRightClickMenu.addAction(newAct)
 
        # Attach it to the table
        self.fileTable.setContextMenuPolicy(Qt.CustomContextMenu)
        self.fileTable.customContextMenuRequested.connect(self.showNTContextMenu)
        
        self.setBlackoutColors()
        
        self.setGeometry(self.geometry().x(), self.geometry().y(), 650,400)
        self.setWindowTitle("Remote Files: " + self.remoteAgentIP + ':' + str(self.remoteAgentPort))
        self.center()
        
        self.onRefreshFiles() 
Example 41
Project: PyQt   Author: PyQt5   File: CopyContent.py    GNU General Public License v3.0 4 votes vote down vote up
def copyData(self):
        count = len(self.selectedIndexes())
        if count == 0:
            return
        if count == 1:  # 只复制了一个
            QApplication.clipboard().setText(
                self.selectedIndexes()[0].data())  # 复制到剪贴板中
            QMessageBox.information(self, "提示", "已复制一个数据")
            return
        rows = set()
        cols = set()
        for index in self.selectedIndexes():  # 得到所有选择的
            rows.add(index.row())
            cols.add(index.column())
            # print(index.row(),index.column(),index.data())
        if len(rows) == 1:  # 一行
            QApplication.clipboard().setText("\t".join(
                [index.data() for index in self.selectedIndexes()]))  # 复制
            QMessageBox.information(self, "提示", "已复制一行数据")
            return
        if len(cols) == 1:  # 一列
            QApplication.clipboard().setText("\r\n".join(
                [index.data() for index in self.selectedIndexes()]))  # 复制
            QMessageBox.information(self, "提示", "已复制一列数据")
            return
        mirow, marow = min(rows), max(rows)  # 最(少/多)行
        micol, macol = min(cols), max(cols)  # 最(少/多)列
        print(mirow, marow, micol, macol)
        arrays = [
            [
                "" for _ in range(macol - micol + 1)
            ] for _ in range(marow - mirow + 1)
        ]  # 创建二维数组(并排除前面的空行和空列)
        print(arrays)
        # 填充数据
        for index in self.selectedIndexes():  # 遍历所有选择的
            arrays[index.row() - mirow][index.column() - micol] = index.data()
        print(arrays)
        data = ""  # 最后的结果
        for row in arrays:
            data += "\t".join(row) + "\r\n"
        print(data)
        QApplication.clipboard().setText(data)  # 复制到剪贴板中
        QMessageBox.information(self, "提示", "已复制")