def on_set_clipboard(self): """Set clipboard contents from list selection. Parent ID is retrieved from user selection and mime data is compiled from database search. QMimeData() object is created from bytearray and reference format. Finally, clipboard contents are set, window is hidden, and OS paste command is sent to current active window. When clipboard contents are set, it emits dataChanged() so the app immediately attempts to insert it and runs into a duplicate update. Setting ignore_created will prevent this check from happening. """ self.ignore_created = True # Hide parent window self.window().hide() # Map the view->proxy to the source->db index proxy_index = self.view_main.currentIndex() source_index = self.proxy_main.mapToSource(proxy_index) # Get parent ID by creating a new index for data model_index = self.model_main.index(source_index.row(), ID) parent_id = self.model_main.data(model_index) logging.debug('ParentID: %s' % parent_id) # Find all childs relating to parent_id mime_list = database.get_mime(parent_id) # Create QMimeData object based on formats and byte data mime_data = QtCore.QMimeData() for format, byte_data in mime_list: mime_data.setData(format, byte_data) # Set to clipboard self.clipboard_monitor.set_data(mime_data) # Send Ctrl+V key stroke (paste) to foreground window if settings.get_send_paste(): paste.send_event() # Update the date column in source self.model_main.setData(self.model_main.index(model_index.row(), DATE), QtCore.QDateTime.currentMSecsSinceEpoch()) self.model_main.submit() # Destroy mime data object? del mime_data, mime_list, proxy_index, source_index, model_index del parent_id
def setup_ui(self): """Display each setting widget with saved values from registry/ini. Todo: Renable word_wrap widget when QDelegate Sizing issue fixed. """ self.key_combo_edit = HotKeyEdit(self) # Allow user to insert <SUPER> on a Win OS self.super_check = QtGui.QCheckBox('Win') self.super_check.setToolTip('Insert <SUPER>') if '<SUPER>' in self.key_combo_edit.text().upper(): self.super_check.setCheckState(QtCore.Qt.Checked) # Number of lines to display self.line_count_spin = QtGui.QSpinBox(self) self.line_count_spin.setRange(1, 10) self.line_count_spin.setValue(settings.get_lines_to_display()) # Where to open the dialog self.open_at_pos_combo = QtGui.QComboBox(self) self.open_at_pos_combo.addItem('Mouse cursor', 0) self.open_at_pos_combo.addItem('Last position', 1) self.open_at_pos_combo.addItem('System tray', 2) # Word wrap display text self.word_wrap = QtGui.QCheckBox('Word wrap') self.word_wrap.setCheckState(_check_state(settings.get_word_wrap())) # Send paste key stroke when content set to clipboard self.paste_check = QtGui.QCheckBox('Paste in active window after ' 'selection') self.paste_check.setCheckState(_check_state(settings.get_send_paste())) # Ignore applications group_box = QtGui.QGroupBox('Ignore the following applications') self.exclude_list = QtGui.QLineEdit(self) self.exclude_list.setPlaceholderText('KeePass.exe;binaryname') self.exclude_list.setText(settings.get_exclude()) # Create seperate layout for ignore applications vbox = QtGui.QVBoxLayout() vbox.addWidget(self.exclude_list) group_box.setLayout(vbox) # Save and cancel buttons button_box = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Save| QtGui.QDialogButtonBox.Cancel) # Create form layout to align widgets layout = QtGui.QFormLayout() layout.setFieldGrowthPolicy(QtGui.QFormLayout.FieldsStayAtSizeHint) layout.addRow('Global shortcut:', self.key_combo_edit) layout.addRow('', self.super_check) layout.addRow('Open window at:', self.open_at_pos_combo) layout.addRow('Lines to display:', self.line_count_spin) # Set main layout main_layout = QtGui.QVBoxLayout(self) main_layout.addLayout(layout) # main_layout.addWidget(self.word_wrap) main_layout.addWidget(self.paste_check) main_layout.addWidget(group_box) main_layout.addWidget(button_box) self.setLayout(main_layout) # LINUX: I use Windows key to move windows with my wm self.setFocus(QtCore.Qt.PopupFocusReason) button_box.accepted.connect(self.save) button_box.rejected.connect(self.cancel) self.connect(self.super_check, QtCore.SIGNAL('stateChanged(int)'), self.insert_win_key)