Example #1
0
    def _on_open_preview(self, index):
        """Open preview dialog of selected item.

        Args:
            index (QModelIndex): Selected row index from view
        """
        # Map the view->proxy to the source->db index
        source_index = self.proxy_main.mapToSource(index)

        # No item is selected so quit
        index_id = self.model_main.index(source_index.row(), ID)
        if index_id.row() <= -1:
            return None

        parent_id = self.model_main.data(index_id)
        logging.debug('ID: %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)

        # PreviewDialog(self) so it opens at main window
        preview_dialog = dialogs.PreviewDialog(self)
        preview_dialog.setup_ui(mime_data)
        preview_dialog.exec_()

        del index_id, parent_id, mime_list, mime_data, preview_dialog
Example #2
0
    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