コード例 #1
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)
コード例 #2
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
コード例 #3
0
    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")
コード例 #4
0
ファイル: ui_common.py プロジェクト: realmhamdy/VisualScrape
 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)
コード例 #5
0
    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")