예제 #1
0
    def test_qbasewindow():

        def long_job( signalmgr=None ):
            if not signalmgr:
                signalmgr = Fake()

            signalmgr.add_progress.emit(5)

            for i in range(5):
                signalmgr.handle_if_abort()
                time.sleep(0.3)
                signalmgr.incr_progress.emit(1)



        with QApplication():
            win = QBaseWindow(title='test title')

            # add arbitrary widget
            layout = QtWidgets.QVBoxLayout()
            btn    = QtWidgets.QPushButton('test button')
            win.setLayout(layout)
            layout.addWidget(btn)

            def run_long_job(win):
                task = win.new_task( long_job )
                task.start()

            win.show()

            # connections
            btn.clicked.connect( functools.partial( run_long_job, win ) )
예제 #2
0
    def test_hierarchy_fixedcols():
        with QApplication():

            model = QtGui.QStandardItemModel()
            model = DictModel(hierarchy=('jedi_class', 'user'),
                              columns={
                                  'jedi_class': ['class'],
                                  'user': ('username', 'firstname', 'lastname')
                              })

            model.add_row(10, columnvals={'class': 'sith'})
            model.add_row(11, columnvals={'class': 'jedi'})

            model[10].add_child(101,
                                columnvals={
                                    'username': '******',
                                    'firstname': 'anakin',
                                    'lastname': 'skywalker'
                                })
            model[10].add_child(102, columnvals={'username': '******'})
            model[10].add_row(12, columnvals={'class': 'other'})

            jediclassId = 10
            userId = 101
            print(model[jediclassId][userId].columnvals())

            # add model to tree (so it is visible)
            tree = QtWidgets.QTreeView()
            tree.setModel(model)
            tree.show()
예제 #3
0
    def test_solo_threadedtask():
        def long_running_job(thread_num, signalmgr=None):
            print('[%s] thread started' % thread_num)
            signalmgr.print_txt.emit('test signal')
            for i in range(3):
                print('[%s] thread step %s/3' % (thread_num, i + 1))
                signalmgr.handle_if_abort()
                time.sleep(1)
            print('[%s] thread finished' % thread_num)

        def printtxt(msg):
            print(msg)

        with QApplication():
            label = QtWidgets.QLabel('watch progress in terminal window..')
            label.show()

            solotask = SoloThreadedTask(
                callback=long_running_job,
                signals={'print_txt': str},
                connections={'print_txt': [printtxt]},
            )

            # every 1s, cancel current job with
            # a new job.
            for i in range(5):
                solotask.start(thread_num=i + 1)
                time.sleep(1)
예제 #4
0
    def test_threadedtask():
        def long_running_job(thread_num, signalmgr=None):
            print('thread started (%s)' % thread_num)
            for i in range(3):
                signalmgr.handle_if_abort()
                time.sleep(1)
            print('job finished (%s)' % thread_num)

        with QApplication():
            label = QtWidgets.QLabel('watch progress in terminal window..')
            label.show()
            for i in range(5):
                task = ThreadedTask(
                    callback=long_running_job,
                    # args/kwds
                    thread_num=i,
                )
                task.start()
예제 #5
0
    def test_indented_style():

        with QApplication():
            model = DictModel( columns=['name'] )
            model.add_row( 1, {'name':'one'} )
            model.add_row( 2, {'name':'two'} )
            model.add_row( 3, {'name':'three'} )

            model[1].add_child( '1a', {'name':'one-a'} )
            model[1].add_child( '1b', {'name':'one-b'} )

            menu   = DictModelQMenu( model, menustyle='indented', indexinfo={'id':'_id','name':'name'} )
            button = QtWidgets.QPushButton('press me')
            button.setMenu( menu )

            menu.triggered_row.connect( printargs )

            button.show()
예제 #6
0
    def test_simple():

        with QApplication():
            model = DictModel(columns=('a', 'b', 'c'))

            # add toplevel rows
            model.add_row(100, columnvals={'a': 'AAA', 'b': 'BBB'})
            model.add_row(200, columnvals={'a': 'ZZZ', 'b': 'XXX'})
            print(model[100].columnvals())
            print(model[200].columnvals())

            # add child-rows (and nested children)
            model[100].add_child(10, columnvals={'c': 'CCC'})
            model[100][10].add_row(11)
            model[100][10].add_row(12)
            model[100][10].add_child(1, columnvals={'c': 'DDD'})
            print(model[100][10].columnvals())
            print(model[100][10][1].columnvals())

            # add model to tree (so it is visible)
            tree = QtWidgets.QTreeView()
            tree.setModel(model)
            tree.show()
예제 #7
0
#builtin
from functools import partial
import time
#external
import unittest
from Qt import QtCore, QtWidgets
import six
#internal
from qconcurrency.testutils import mock
from qconcurrency._qbasewindow_ import *
from qconcurrency import QApplication

qapplication = QApplication()


class Test_QBaseWindow(unittest.TestCase):
    def test_assignlayout(self):
        """
        If unhandled exception, this is broken.
        """
        class MyWin(QBaseWindow):
            pass

        win = MyWin()
        win.setLayout(QtWidgets.QVBoxLayout())

    def test_new_task__customsignal(self):
        class MyWin(QBaseWindow):
            def __init__(self):
                QBaseWindow.__init__(self)
                self.threadpool = QtCore.QThreadPool()
예제 #8
0
        # QApp events (causing item to be rendered) until it runs
        # out of signals to fire. It is unlikely you will
        # need the following line in your production code.
        #
        QtCore.QCoreApplication.instance().processEvents()


if __name__ == '__main__':
    from qconcurrency import QApplication
    from qconcurrency.threading_ import ThreadedTask
    import supercli.logging
    import time

    supercli.logging.SetLog(lv=20)

    with QApplication():
        # create/load the list
        mylist = MyThreadedList()
        mylist.show()
        mylist.load()

        # from a separate thread (so that it is visible)
        # continuously reload the list


        def multiload_list(listwidget, signalmgr=None):
            for i in range(3):
                time.sleep(0.5)
                listwidget.load()

        task = ThreadedTask(multiload_list, listwidget=mylist)