Exemplo n.º 1
0
Arquivo: accd.py Projeto: Sugz/Python
    def mousePressEvent( self, event ):
        # handle an internal move

        # start a drag event
        if event.button() == Qt.LeftButton and self.dragDropRect().contains(event.pos()):
            # create the pixmap
            pixmap = QPixmap.grabWidget(self, self.rect())

            # create the mimedata
            mimeData = QMimeData()
            mimeData.setText('ItemTitle::%s' % (self.title()))

            # create the drag
            drag = QDrag(self)
            drag.setMimeData(mimeData)
            drag.setPixmap(pixmap)
            drag.setHotSpot(event.pos())

            if not drag.exec_():
                self._accordianWidget.emitItemDragFailed(self)

            event.accept()

        # determine if the expand/collapse should occur
        elif event.button() == Qt.LeftButton and self.expandCollapseRect().contains(event.pos()):
            self._clicked = True
            event.accept()

        else:
            event.ignore()
Exemplo n.º 2
0
    def set_clipboard_image(self):
        """Export the formatted output to an image and store it in the
        clipboard.

        The image stored in the clipboard is a PNG file with alpha
        transparency.

        """
        div = self.view.page().mainFrame().findFirstElement('.output')
        images = {}
        for background in (Qt.transparent, Qt.white):
            image = QImage(div.geometry().size(),
                           QImage.Format_ARGB32_Premultiplied)
            image.fill(background)
            painter = QPainter(image)
            div.render(painter)
            painter.end()
            images[background] = image

        # Windows needs this buffer hack to get alpha transparency in
        # the copied PNG.
        buffer_ = QBuffer()
        buffer_.open(QIODevice.WriteOnly)
        images[Qt.transparent].save(buffer_, 'PNG')
        buffer_.close()
        data = QMimeData()
        data.setData('PNG', buffer_.data())
        data.setImageData(images[Qt.white])
        QApplication.clipboard().setMimeData(data)
Exemplo n.º 3
0
 def mimeData(self, indexes):
     """Encodes ``indexes`` as mime data for dragging."""
     # serialize data as xml
     root = etree.Element('stringlist')
     for index in indexes:
         element = self._get_element_for_index(index)
         root.append(deepcopy(element))
     serialized = etree.tostring(root, xml_declaration=True)
     mimedata = QMimeData()
     mimedata.setData('text/xml', serialized)
     return mimedata
    def test_edit_order_add_rename_documents(self):

        app = self.app
        widget = self.widget
        mw = self.mw

        widget.edit_new_order(self.customer_id)

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)

        self._fill_order_part("Order part one")

        # Put the cursor back on the first line so the next document drop is tied to it.
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_Up)
        app.processEvents()
        # app.exec_()

        # Drop a document
        tmp_file, tmp_path = self._make_tmp_file()
        mime_data = QMimeData()
        url = "file:///{}".format(os.path.abspath(tmp_path).replace('\\', '/'))
        mainlog.debug("Dropping at {}".format(QUrl(url).toString()))
        mime_data.setUrls([QUrl(url)])

        make_document_drop(widget.documents_widget.view, QPoint(10, 10),
                           mime_data)

        self._clear_tmp_file(tmp_file, tmp_path)

        # Now it has been dropped, rename it
        # (this tests things like non-delayed create, delayed rename)

        model = widget.documents_widget.model
        fn_ndx = model.prototype.index_of("filename")
        ndx = model.index(0, fn_ndx)
        model.setData(ndx, "New name", Qt.UserRole)

        #app.exec_()

        # Now save the whole order
        widget.setFocus()
        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        #app.exec_()
        self.assertEqual(1, len(order.parts[0].documents),
                         "One document was added on the first part")

        documents = [d for d in order.parts[0].documents]  # Set to array
        self.assertEqual("New name", documents[0].filename,
                         "Rename should've been applied")
 def mouseMoveEvent(self, mme):
   if mme.button() == Qt.NoButton and self._drag_start: # for some reason, the left button is being mapped to NoButton
     drag_distance = mme.pos() - self._drag_start
     drag_distance = drag_distance.manhattanLength()
     if drag_distance > QApplication.startDragDistance():
       drag = QDrag(self)
       mime_data = QMimeData()
       mime_data.setText(self.label_spidername.text())
       drag.setMimeData(mime_data)
       drag.exec_(Qt.CopyAction | Qt.MoveAction)
   super(SpiderToolButton, self).mouseMoveEvent(mme)
Exemplo n.º 6
0
 def mouseMoveEvent(self, mme):
     if mme.button(
     ) == Qt.NoButton and self._drag_start:  # for some reason, the left button is being mapped to NoButton
         drag_distance = mme.pos() - self._drag_start
         drag_distance = drag_distance.manhattanLength()
         if drag_distance > QApplication.startDragDistance():
             drag = QDrag(self)
             mime_data = QMimeData()
             mime_data.setText(self.label_spidername.text())
             drag.setMimeData(mime_data)
             drag.exec_(Qt.CopyAction | Qt.MoveAction)
     super(SpiderToolButton, self).mouseMoveEvent(mme)
    def test_edit_order_documents(self):

        app = self.app
        widget = self.widget
        mw = self.mw

        # order = self._make_order()
        # order_id = order.order_id
        # widget.reset_order(order.order_id)

        widget.edit_new_order(self.customer_id)

        widget.controller_part.view.setFocus(Qt.OtherFocusReason)

        # QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_Escape) # modifier, delay
        # QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_F5, Qt.ShiftModifier) # modifier, delay
        # app.processEvents()

        self._fill_order_part("Order part two")

        # Put the cursor back on the first line so the next document drop is tied to it.
        QTest.keyEvent(QTest.Click, widget.controller_part.view, Qt.Key_Up)
        app.processEvents()
        # app.exec_()

        tmp_file, tmp_path = self._make_tmp_file()
        mime_data = QMimeData()
        url = "file:///{}".format(os.path.abspath(tmp_path).replace('\\', '/'))
        mainlog.debug("Dropping at {}".format(QUrl(url).toString()))
        mime_data.setUrls([QUrl(url)])
        make_document_drop(widget.documents_widget.view, QPoint(10, 10),
                           mime_data)

        self._clear_tmp_file(tmp_file, tmp_path)

        # That's fine, but I'll need to pilot the file chooser dialog, and that's hard :-(
        # But even if I find my way around that, I'll have to mock the file server... :-(
        # b.click()

        QTest.keyEvent(QTest.Click, app.focusWidget(), Qt.Key_S,
                       Qt.ControlModifier)  # modifier, delay
        app.processEvents()

        order = dao.order_dao.find_by_id(widget._current_order.order_id)

        #app.exec_()
        self.assertEqual(1, len(order.parts[0].documents),
                         "One document was added on the first part")
Exemplo n.º 8
0
    def __init__(self, p_data=None):
        """
        Initialise the instance.
        """
        QMimeData.__init__(self)

        # Keep a local reference to be returned if possible.
        self._local_instance = p_data

        if p_data is not None:
            # We may not be able to pickle the data.
            try:
                p_data = dumps(p_data)
            except Exception:
                return

            self.setData(self.MIME_TYPE, dumps(p_data.__class__) + p_data)
Exemplo n.º 9
0
    def __init__ ( self, data = None ):
        """ Initialise the instance.
        """
        QMimeData.__init__( self )

        # Keep a local reference to be returned if possible:
        self._local_instance = data

        if data is not None:
            # We may not be able to pickle the data:
            try:
                pdata = dumps( data )
            except:
                import traceback
                traceback.print_exc()
                pdata = dumps( None )

            # This format (as opposed to using a single sequence) allows the
            # type to be extracted without unpickling the data itself.
            self.setData( self.MIME_TYPE, dumps( data.__class__ ) + pdata )
Exemplo n.º 10
0
 def copy(self):
     """Copy to the clipboard"""
     data = QMimeData()
     text = '\n'.join([cursor.selectedText() \
                         for cursor in self.cursors()])
     data.setText(text)
     data.setData(self.MIME_TYPE, text.encode('utf8'))
     QApplication.clipboard().setMimeData(data)
Exemplo n.º 11
0
    def _drag_urls ( self, urls ):
        mime_data = QMimeData()
        mime_data.setUrls( urls )

        return mime_data
Exemplo n.º 12
0
    def _drag_color ( self, color ):
        mime_data = QMimeData()
        mime_data.setColorData( color )

        return mime_data
Exemplo n.º 13
0
    def _drag_files ( self, files ):
        mime_data = QMimeData()
        mime_data.setUrls( [ QUrl( file ) for file in files ] )

        return mime_data
Exemplo n.º 14
0
    def _drag_hmtl ( self, html ):
        mime_data = QMimeData()
        mime_data.setHtml( html )

        return mime_data
Exemplo n.º 15
0
    def _drag_text ( self, text ):
        mime_data = QMimeData()
        mime_data.setText( text )

        return mime_data
Exemplo n.º 16
0
    def _drag_image ( self, image ):
        mime_data = QMimeData()
        mime_data.setImageData( image )

        return mime_data
Exemplo n.º 17
-1
    def set_clipboard_html(self):
        """Place the HTML displayed in the HTML view widget into the
        system clipboard.

        """
        data = QMimeData()
        data.setText(self.plain)
        data.setHtml(self.html)
        QApplication.clipboard().setMimeData(data)