def copy(self): cb = QClipboard() try: cb.setText(self.ip) lable except: self.fouceEx()
def __init__(self, config, icon=None): super().__init__() self.config = config if icon: self.setWindowIcon(icon) # info panel about_html = self.generate_about_html(html_template) self.about = QTextBrowser() self.about.setOpenExternalLinks(True) self.about.setMinimumSize(400, 260) self.about.setHtml(about_html) # widgets self.clipboard = QClipboard(self) self.status_bar = QLabel() copy_button = QPushButton("Copy") copy_button.setMaximumWidth(75) copy_button.clicked.connect(self.copy_to_clipboard) close_button = QPushButton("Close") close_button.setMaximumWidth(75) close_button.clicked.connect(self.close) # layoyut clipboard_layout = QHBoxLayout() clipboard_layout.addWidget(self.status_bar) clipboard_layout.addWidget(copy_button) clipboard_layout.addWidget(close_button) # Create main layout and add widgets main_layout = QVBoxLayout() main_layout.addWidget(self.about) main_layout.addLayout(clipboard_layout) self.setLayout(main_layout)
class About(QDialog): def __init__(self, config, icon=None): super().__init__() self.config = config if icon: self.setWindowIcon(icon) # info panel about_html = self.generate_about_html(html_template) self.about = QTextBrowser() self.about.setOpenExternalLinks(True) self.about.setMinimumSize(400, 260) self.about.setHtml(about_html) # widgets self.clipboard = QClipboard(self) self.status_bar = QLabel() copy_button = QPushButton("Copy") copy_button.setMaximumWidth(75) copy_button.clicked.connect(self.copy_to_clipboard) close_button = QPushButton("Close") close_button.setMaximumWidth(75) close_button.clicked.connect(self.close) # layoyut clipboard_layout = QHBoxLayout() clipboard_layout.addWidget(self.status_bar) clipboard_layout.addWidget(copy_button) clipboard_layout.addWidget(close_button) # Create main layout and add widgets main_layout = QVBoxLayout() main_layout.addWidget(self.about) main_layout.addLayout(clipboard_layout) self.setLayout(main_layout) def generate_about_html(self, html_template): html = html_template html = html.replace('{{product_name}}', self.config["product_name"]) html = html.replace('{{version}}', self.config["version"]) html = html.replace('{{home_page}}', self.config["home_page"]) html = html.replace('{{database_path}}', self.config["database_path"]) html = html.replace('{{preferences_path}}', self.config["preferences_path"]) html = html.replace('{{install_dir}}', self.config["install_dir"]) html = html.replace('{{logs_dir}}', self.config["logs_dir"]) return html def copy_to_clipboard(self): logger.debug('copying text from "About" dialog into clipboard') self.clipboard.setText(self.about.toPlainText()) self.status_bar.setText("Copied into clipboard") self.status_bar.setStyleSheet("font-family: arial; color: #4169e1;")
class ClipboardHelper(QObject): """ Simple wrapper around a QClipboard with methods exposed as Slots for QML use. """ def __init__(self, parent=None): super(ClipboardHelper, self).__init__(parent) self._clipboard = QClipboard(parent=self) @Slot(str) def setText(self, value): self._clipboard.setText(value) @Slot() def clear(self): self._clipboard.clear()
def __init__(self): super().__init__() self.schedule_object = None self.init_ui() self.setStyleSheet(WINDOW_STYLE) self.setWindowTitle("NRC a iCalendar") self.setWindowIcon(QIcon(get_path("assets", "icon.svg"))) self.clikboard = QClipboard() # Dialogo para guardar el archivo self.save_dialog = QFileDialog(self) self.save_dialog.setFileMode(QFileDialog.AnyFile) self.save_dialog.setNameFilter("iCalendar (*.ics)") self.save_dialog.setDefaultSuffix("ics") self.save_dialog.setAcceptMode(QFileDialog.AcceptSave)
def paste_nodes(self): """ Pastes nodes from the clipboard. """ clipboard = QClipboard() cb_string = clipboard.text() if not cb_string: return self._undo_stack.beginMacro('pasted nodes') serial_data = json.loads(cb_string) self.clear_selection() nodes = self._deserialize(serial_data, True) [n.set_selected(True) for n in nodes] self._undo_stack.endMacro()
def test_mainnet_rest_url_copy_button(self, qtbot: QTest, launch_widget: LaunchWidget): qtbot.mouseClick(launch_widget.mainnet_group_box.rest_url_copy_button, Qt.LeftButton) rest_url = launch_widget.node_launcher.command_generator.mainnet_rest_url( ) assert QClipboard().text() == rest_url
def __init__(self, args): super().__init__() self.initUI() t = QTimer() t.singleShot(0, self.onQApplicationStarted) self.preferencesGui = PreferencesGUI(self.appctxt, self.PreferenceWindow) self.receiversInst = Receivers(self.ui) self.receiversInst.setClipboardInst(QClipboard(self)) self.connectReceivers() self.ui.floatingToolBox.restoreDefaults() if not os.path.exists(self.homeDir): os.makedirs(self.homeDir) if args != '': if os.path.isfile(args): self.receiversInst.loadPdf(os.path.abspath(args)) elif args: self.receiversInst.newPdf(os.path.abspath(args))
def test_grpc_url_copy_button(self, qtbot: QTest, launch_widget: LaunchWidget): launch_widget.testnet_group_box.zap_layout.copy_grpc_url.button.setEnabled( True) qtbot.mouseClick( launch_widget.testnet_group_box.zap_layout.copy_grpc_url.button, Qt.LeftButton) rest_url = launch_widget.testnet_group_box.node_set.lnd.grpc_url assert QClipboard().text() == rest_url
def copy_nodes(self, nodes=None): """ copy nodes to the clipboard by default this method copies the selected nodes from the node graph. Args: nodes (list[NodeGraphQt.Node]): list of node instances. """ nodes = nodes or self.selected_nodes() if not nodes: return False clipboard = QClipboard() serial_data = self._serialize(nodes) serial_str = json.dumps(serial_data) if serial_str: clipboard.setText(serial_str) return True return False
def test_lncli_copy_button(self, qtbot: QTest, launch_widget: LaunchWidget): launch_widget.testnet_group_box.cli_layout.copy_lncli.button.setEnabled( True) qtbot.mouseClick( launch_widget.testnet_group_box.cli_layout.copy_lncli.button, Qt.LeftButton) command = launch_widget.testnet_group_box.node_set.lnd.lncli assert QClipboard().text() == ' '.join(command)
def copy_lncli_command(self): command = getattr(self.node_launcher.command_generator, f'{self.network}_lncli')() QClipboard().setText(' '.join(command))
def test_copy_rest(self, joule_layout: JouleLayout, qtbot: QTest): qtbot.mouseClick(joule_layout.copy_rest.button, Qt.LeftButton) assert QClipboard().text() == 'test rest'
class MainWindow(QMainWindow): """Main Window of the application""" def __init__(self): super().__init__() self.schedule_object = None self.init_ui() self.setStyleSheet(WINDOW_STYLE) self.setWindowTitle("NRC a iCalendar") self.setWindowIcon(QIcon(get_path("assets", "icon.svg"))) self.clikboard = QClipboard() # Dialogo para guardar el archivo self.save_dialog = QFileDialog(self) self.save_dialog.setFileMode(QFileDialog.AnyFile) self.save_dialog.setNameFilter("iCalendar (*.ics)") self.save_dialog.setDefaultSuffix("ics") self.save_dialog.setAcceptMode(QFileDialog.AcceptSave) def init_ui(self): """Makes the layout""" # Barra de opciones y links de interés menu_bar = self.menuBar() options_menu = menu_bar.addMenu("&Opciones") act_allways_visible = options_menu.addAction("Siempre visible") act_allways_visible.setCheckable(True) act_allways_visible.toggled.connect(self.__allways_visible) uc_calendars_menu = menu_bar.addMenu("&Calendarios") for name, link in OTHER_CALENDARS: calendar_option = uc_calendars_menu.addAction(name) # TODO: Ni idea pq se necesita tener una variable `s`, sin esta no funciona calendar_option.triggered.connect( lambda s=None, l=link: self.__to_clipboard(l)) go_to_menu = menu_bar.addMenu("&Ir a") go_to_options = [ ("Feed del calendario de Canvas", "https://cursos.canvas.uc.cl/calendar"), ( "Importar calendario a Google", "https://calendar.google.com/calendar/a/uc.cl/r/settings/export", ), ] for name, link in go_to_options: new_option = go_to_menu.addAction(name) new_option.triggered.connect( lambda s=None, l=link: webbrowser.open(l)) # Main widget main_widget = QFrame() self.setCentralWidget(main_widget) main_layout = QVBoxLayout(main_widget) main_widget.setLayout(main_layout) main_layout.setSizeConstraint(QLayout.SetMinimumSize) # Lista de códigos a ingresar code_layout = QHBoxLayout() main_layout.addLayout(code_layout) self.code_list = [QLineEdit(main_widget) for i in range(6)] code_validator = QIntValidator(main_layout, 10**4, 10**5) for code in self.code_list: code.setObjectName("code_field") code.setAlignment(Qt.AlignCenter) code.setMaxLength(5) code.setValidator(code_validator) code.textEdited.connect(self.check_codes) code_layout.addWidget(code) self.get_button = QPushButton("Obtener horario", main_widget) self.get_button.clicked.connect(self.get_schedule) self.get_button.setCursor(Qt.PointingHandCursor) self.get_button.setDisabled(True) main_layout.addWidget(self.get_button) self.schedule_view = ScheduleView(8, 6, main_widget) main_layout.addWidget(self.schedule_view) self.save_button = QPushButton("Guardar horario", main_widget) self.save_button.clicked.connect(self.save_schedule) self.save_button.setCursor(Qt.PointingHandCursor) self.save_button.setDisabled(True) main_layout.addWidget(self.save_button) self.status_bar = QStatusBar(self) self.status_bar.showMessage("Ingrese los códigos NRC") self.setStatusBar(self.status_bar) self.adjustSize() def __allways_visible(self, option): flags = self.windowFlags() if option: self.setWindowFlags(flags | Qt.WindowStaysOnTopHint) else: self.setWindowFlags(flags ^ Qt.WindowStaysOnTopHint) self.show() def __to_clipboard(self, link): self.clikboard.setText(link) self.status_bar.showMessage( "URL del calendario copiado a portapapeles") def check_codes(self): """Check if the codes are valid""" at_least_one_valid = False for code in self.code_list: if valid_nrc(code.text()): at_least_one_valid = True elif code.text(): # TODO: cambiar el estilo al ser invalido y tener texto pass else: pass self.get_button.setDisabled(not at_least_one_valid) if at_least_one_valid: self.status_bar.clearMessage() else: self.status_bar.showMessage("Ingrese los códigos NRC") def get_schedule(self): """Get the schedule of Buscacursos UC""" valid_codes = list( filter(valid_nrc, map(QLineEdit.text, self.code_list))) if not valid_codes: return try: self.schedule_object = Schedule.get(valid_codes) except OSError: error_box = QMessageBox(QMessageBox.Critical, "Error", "No se ha podido importar el horario") error_box.exec_() else: self.show_schedule() def show_schedule(self): """Show the schedule in the table""" # Limpia el horario self.schedule_view.clearContents() # Si no hay módulos, se deshabilita la opción de guardar y termina if not self.schedule_object.courses: self.schedule_view.update_size() self.save_button.setDisabled(True) return # Si existen módulos, se muestran en el horario for i_row, row in enumerate(self.schedule_object.get_table()): for sub_row in row: for i_col, element in enumerate(sub_row): if not element: continue module_label = QLabel(self.schedule_view) module_label.setText(element.code) module_label.setObjectName(element.type_) module_label.setAlignment(Qt.AlignCenter) module_label.setFixedHeight(20) cell_frame = self.schedule_view.cellWidget(i_row, i_col) # Se crea un frame para los widgets si no existe if not cell_frame: cell_frame = QFrame(self.schedule_view) cell_layout = QVBoxLayout(cell_frame) cell_layout.setSpacing(0) cell_layout.setMargin(0) self.schedule_view.setCellWidget( i_row, i_col, cell_frame) cell_frame.layout().addWidget(module_label) self.schedule_view.update_size() self.save_button.setDisabled(False) def save_schedule(self): """Saves the schedule""" if self.save_dialog.exec_(): out_dir = self.save_dialog.selectedFiles()[0] with open(out_dir, mode="w", encoding="utf-8") as file: file.write(self.schedule_object.to_ics())
def copy(self): QClipboard().setText(self.copy_text) self.button.setText('Copied!') self.button.repaint() self.timer.singleShot(1000, self.remove_text)
def __init__(self, parent: QWidget = None): super(ColorWidget, self).__init__(parent) self.cp: QClipboard = QClipboard() self.pressed: bool = False self.timer: QTimer = QTimer() self.gridLayout: QGridLayout = QGridLayout(self) self.gridLayout.setSpacing(6) self.gridLayout.setContentsMargins(11, 11, 11, 11) self.verticalLayout: QVBoxLayout = QVBoxLayout() self.verticalLayout.setSpacing(0) self.labColor: QLabel = QLabel() self.labColor.setText('+') self.labColor.setStyleSheet("background-color: rgb(255, 107, 107);color: rgb(250, 250, 250);") self.labColor.setAlignment(Qt.AlignCenter) font: QFont = QFont() font.setPixelSize(35) font.setBold(True) self.labColor.setFont(font) sizePolicy: QSizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.labColor.sizePolicy().hasHeightForWidth()) self.labColor.setSizePolicy(sizePolicy) self.labColor.setMinimumSize(QSize(80, 70)) self.labColor.setMaximumSize(QSize(80, 70)) self.labColor.setCursor(QCursor(Qt.CrossCursor)) self.labColor.setFrameShape(QFrame.StyledPanel) self.labColor.setFrameShadow(QFrame.Sunken) self.verticalLayout.addWidget(self.labColor) self.label: QLabel = QLabel(self) self.label.setMinimumSize(QSize(0, 18)) self.label.setStyleSheet("background-color: rgb(0, 0, 0);color: rgb(200, 200, 200);") self.label.setAlignment(Qt.AlignCenter) self.verticalLayout.addWidget(self.label) self.gridLayout.addLayout(self.verticalLayout, 0, 0, 3, 1) self.labWeb: QLabel = QLabel(self) self.gridLayout.addWidget(self.labWeb, 0, 1, 1, 1) self.txtWeb: QLineEdit = QLineEdit(self) self.gridLayout.addWidget(self.txtWeb, 0, 2, 1, 1) self.labRgb: QLabel = QLabel(self) self.gridLayout.addWidget(self.labRgb, 1, 1, 1, 1) self.txtRgb: QLineEdit = QLineEdit(self) self.gridLayout.addWidget(self.txtRgb, 1, 2, 1, 1) self.labPoint: QLabel = QLabel(self) self.gridLayout.addWidget(self.labPoint, 2, 1, 1, 1) self.txtPoint: QLineEdit = QLineEdit(self) self.gridLayout.addWidget(self.txtPoint, 2, 2, 1, 1) self.label.setText('当前颜色显示') self.labWeb.setText('web值: ') self.labRgb.setText('rgb值: ') self.labPoint.setText('坐标值: ') self.setLayout(self.gridLayout) self.setWindowTitle('屏幕拾色器') self.setFixedSize(270, 108) self.cp = QApplication.clipboard() self.pressed = False timer = QTimer(self) timer.setInterval(100) timer.timeout.connect(self.showColorValue) timer.start()
def test_mainnet_lncli_copy_button(self, qtbot: QTest, launch_widget: LaunchWidget): qtbot.mouseClick(launch_widget.mainnet_group_box.lncli_copy_button, Qt.LeftButton) command = launch_widget.node_launcher.command_generator.mainnet_lncli() assert QClipboard().text() == ' '.join(command)
def test_copy_lncli(self, cli_layout: CliLayout, qtbot: QTest): qtbot.mouseClick(cli_layout.copy_lncli.button, Qt.LeftButton) assert QClipboard().text() == 'test lncli'
def test_copy_button(self, copy_button: CopyButton, qtbot: QTest): qtbot.mouseClick(copy_button.button, Qt.LeftButton) assert QClipboard().text() == 'copy_this'
def __init__(self, parent=None): super(ClipboardHelper, self).__init__(parent) self._clipboard = QClipboard(parent=self)
def get_description(self): npc_description = f"{self.name_label.text()} est {self.job_label.text()} {self.specie_label.text()} " \ f"plutôt {self.appearance_label.text()}, {self.behavior_label.text()}, semble être " \ f"{self.personality_label.text()} et a {self.accessories_label.text()}" QClipboard().setText(npc_description)
def copy_rest_url(self): rest_url = getattr(self.node_launcher.command_generator, f'{self.network}_rest_url')() QClipboard().setText(rest_url)
def test_rest_url_copy_button(self, qtbot: QTest, launch_widget: LaunchWidget): qtbot.mouseClick(launch_widget.testnet_group_box.joule_layout.copy_rest.button, Qt.LeftButton) rest_url = launch_widget.testnet_group_box.node_set.lnd.rest_url assert QClipboard().text() == rest_url
def __init__(self, node_set: NodeSet, system_tray): super().__init__() self.node_set = node_set self.system_tray = system_tray self.bitcoind_status_action = self.addAction('bitcoind off') self.bitcoind_status_action.setEnabled(False) # bitcoin console self.bitcoin_cli_widget = ConsoleDialog( title='bitcoin-cli', program=self.node_set.bitcoin.software.bitcoin_cli, args=self.node_set.bitcoin.args, commands=BITCOIN_CLI_COMMANDS) self.bitcoin_console_action = self.addAction('Open Bitcoin Console') self.bitcoin_console_action.triggered.connect( self.bitcoin_cli_widget.show) # bitcoind output self.bitcoind_output_widget = BitcoindOutputWidget( node_set=self.node_set, system_tray=self.system_tray) self.bitcoind_output_action = self.addAction('See Bitcoin Output') self.bitcoind_output_action.triggered.connect( self.bitcoind_output_widget.show) self.addSeparator() self.lnd_status_action = self.addAction('lnd off') self.lnd_status_action.setEnabled(False) # lnd console self.lncli_widget = ConsoleDialog( title='lncli', program=self.node_set.lnd.software.lncli, args=self.node_set.lnd.lncli_arguments(), commands=LNCLI_COMMANDS) self.lnd_console_action = self.addAction('Open LND Console') self.lnd_console_action.triggered.connect(self.lncli_widget.show) # lnd output self.lnd_output_widget = LndOutputWidget(node_set=self.node_set, system_tray=self.system_tray) self.lnd_output_action = self.addAction('See LND Output') self.lnd_output_action.triggered.connect(self.lnd_output_widget.show) self.addSeparator() # Joule self.joule_status_action = self.addAction('Joule Browser Extension') self.joule_status_action.setEnabled(False) self.joule_url_action = self.addAction('Copy Node URL (REST)') self.joule_macaroons_action = self.addAction('Show Macaroons') self.joule_url_action.triggered.connect( lambda: QClipboard().setText(self.node_set.lnd.rest_url)) self.joule_macaroons_action.triggered.connect( lambda: reveal(self.node_set.lnd.macaroon_path)) self.addSeparator() # settings self.settings_action = self.addAction('&Settings') self.settings_action.setShortcut(QKeySequence.Preferences) self.settings_tab = SettingsTabDialog(node_set=self.node_set) self.settings_action.triggered.connect(self.settings_tab.show) # advanced self.advanced_widget = AdvancedWidget(node_set=self.node_set) self.advanced_action = self.addAction('Advanced...') self.advanced_action.triggered.connect(self.advanced_widget.show) self.addSeparator() # quit self.quit_action = self.addAction('Quit') self.quit_action.triggered.connect(lambda _: QCoreApplication.exit(0))
def test_joule_url_action(self, reveal_patch: MagicMock, webbrowser_patch: MagicMock, menu: Menu, qtbot: QTest): menu.joule_url_action.trigger() assert QClipboard().text() == 'test rest'
def test_copy_rest(self, menu: Menu, qtbot: QTest): menu.joule_url_action.trigger() assert QClipboard().text() == 'test rest'
def __init__(self, node_set: NodeSet, system_tray): super().__init__() self.node_set = node_set self.system_tray = system_tray # Bitcoind self.bitcoind_status_action = self.addAction('bitcoind off') self.bitcoind_status_action.setEnabled(False) self.bitcoind_manager_tabs_dialog = BitcoindManagerTabsDialog( bitcoin=self.node_set.bitcoin, system_tray=self.system_tray) self.bitcoin_manage_action = self.addAction('Manage Bitcoind') self.bitcoin_manage_action.triggered.connect( self.bitcoind_manager_tabs_dialog.show) QTimer.singleShot(500, self.node_set.bitcoin.process.start) self.bitcoind_manager_tabs_dialog.output_tab.bitcoind_synced.connect( self.node_set.lnd.process.start) self.addSeparator() # LND self.lnd_status_action = self.addAction('lnd off') self.lnd_status_action.setEnabled(False) self.lnd_manager_tabs_dialog = LndManagerTabsDialog( lnd=self.node_set.lnd, system_tray=self.system_tray) self.lnd_manage_action = self.addAction('Manage LND') self.lnd_manage_action.triggered.connect( self.lnd_manager_tabs_dialog.show) self.addSeparator() # Joule self.joule_status_action = self.addAction('Joule Browser UI') self.joule_status_action.setEnabled(False) self.joule_url_action = self.addAction('Copy Node URL (REST)') self.joule_macaroons_action = self.addAction('Show Macaroons') self.joule_url_action.triggered.connect( lambda: QClipboard().setText(self.node_set.lnd.rest_url)) self.joule_macaroons_action.triggered.connect( lambda: reveal(self.node_set.lnd.macaroon_path)) self.addSeparator() # Zap self.zap_status_action = self.addAction('Zap Desktop UI') self.zap_status_action.setEnabled(False) self.zap_open_action = self.addAction('Open Zap Desktop') self.zap_open_action.triggered.connect( lambda: webbrowser.open(self.node_set.lnd.lndconnect_url)) self.zap_qr_code_label = ZapQrcodeLabel( self.node_set.lnd.lndconnect_qrcode) self.show_zap_qrcode_action = self.addAction('Pair Zap Mobile') self.show_zap_qrcode_action.triggered.connect( self.zap_qr_code_label.show) self.addSeparator() # Quit self.quit_action = self.addAction('Quit') self.quit_action.triggered.connect(lambda _: QCoreApplication.exit(0))
def copy_rest_url(self): QClipboard().setText(self.node_set.lnd_node.configuration.rest_url)
def use_clipboard(): clipboard_text = QClipboard().text() return clipboard_text