source: orange/orange/orngDebugging.py @ 8998:22040c748eea

Revision 8998:22040c748eea, 4.5 KB checked in by ales_erjavec <ales.erjavec@…>, 3 years ago (diff)

Some more mouse interaction for scroll views.

Line 
1# a simple module used in orange to see whether debugging is enabled, where to write the output and how much output do you want to see
2
3orngDebuggingEnabled = 0                            # do we want to enable debugging
4orngDebuggingFileName = "debuggingOutput.txt"       # where do we want to write output to
5orngVerbosity = 1                                   # what's the level of verbosity
6
7import weakref
8from collections import defaultdict
9
10import PyQt4.QtGui
11from PyQt4 import QtCore, QtGui
12from PyQt4.QtTest import QTest
13from PyQt4.QtCore import Qt
14
15import random
16class debug(object):
17    elements_list = defaultdict(list)
18    random = random
19   
20    @classmethod
21    def registerQItemView(cls, widget, view):
22        cls.elements_list[widget].append(view)
23       
24    @classmethod
25    def regiseterQGraphicsView(cls, widget, view):
26        cls.elements_list[widget].append(view)
27       
28    @classmethod
29    def registerQwtPlot(cls, widget, graph):
30        cls.elements_list[widget].append(graph)
31       
32    @classmethod
33    def register(cls, widget, element):
34        from PyQt4.QtGui import QGraphicsView, QAbstractItemView
35        from OWGraph import OWGraph
36        if isinstance(element, QGraphicsView):
37            cls.regiseterQGraphicsView(widget, element)
38        elif isinstance(element, QAbstractItemView):
39            cls.registerQItemView(widget, element)
40        elif isinstance(element, OWGraph):
41            cls.registerOWGraph(widget, element)
42        else:
43            print "Unhandled type", element
44       
45    @classmethod
46    def scrollAreaInteract(cls, area):
47#        print "scrollAreaInteract", area
48        from PyQt4.QtTest import QTest
49        geom = area.geometry()
50        randpos = lambda: geom.topLeft() + QtCore.QPoint(geom.width() * random.random(), geom.height() * random.random())
51        QTest.mouseMove(area, randpos(), 2)
52        QTest.mouseClick(area, Qt.LeftButton, pos=randpos(), delay=2)
53        QTest.mouseDClick(area, Qt.LeftButton, pos=randpos(), delay=2)
54        QTest.mousePress(area, Qt.LeftButton, pos=randpos(), delay=2)
55        QTest.mouseRelease(area, Qt.LeftButton, pos=randpos(), delay=2)
56       
57#        area.scrollContentsBy(random.randint(-10, 10), random.randint(-10, 10))
58       
59       
60    @classmethod
61    def itemViewInteract(cls, view):
62        cls.scrollAreaInteract(view)
63   
64    @classmethod
65    def graphicsViewInteract(cls, view):
66        cls.scrollAreaInteract(view)
67       
68    @classmethod
69    def graphInteract(cls, view):
70        cls.scrollAreaInteract(view)
71       
72    @classmethod
73    def interact(cls, widget):
74        from PyQt4.QtGui import QGraphicsView, QAbstractItemView
75        from OWGraph import OWGraph
76        if isinstance(widget, QGraphicsView):
77            cls.graphicsViewInteract(widget)
78        elif isinstance(widget, QAbstractItemView):
79            cls.itemViewInteract(widget)
80        elif isinstance(widget, OWGraph):
81            cls.graphInteract(widget)
82        else:
83            print "Unhandled widget interaction", widget
84       
85    @classmethod
86    def interactWithOWWidget(cls, widget):
87        views = cls.candidateDebugWidgets(widget)
88        for view in views:
89            if view.isEnabled() and getattr(view, "debuggingEnabled", True):
90                cls.interact(view)
91       
92    @classmethod             
93    def candidateDebugWidgets(cls, widget):
94        from PyQt4.QtGui import QGraphicsView, QAbstractItemView
95        from OWGraph import QwtPlot
96       
97        gviews_list = widget.findChildren(QGraphicsView)
98        iviews_list = widget.findChildren(QAbstractItemView)
99        pviews_list = widget.findChildren(QwtPlot)
100       
101        return gviews_list + iviews_list + pviews_list
102   
103#    @classmethod
104#    def candidateDebugWidgets(cls, widget, cls_list=None):
105#        if cls_list is None:
106#            from PyQt4.QtGui import QGraphicsView, QAbstractItemView
107#            from OWGraph import QwtPlot
108#            cls_list = [QGraphicsView, QAbstractItemView, QwtPlot]
109#        candidates = []
110#        for child in widget.children():
111#            print [(child, isinstance(child, db_cls)) for db_cls in cls_list]
112#            if any(isinstance(child, db_cls) for db_cls in cls_list):
113#                if getattr(child, "debuggingEnabled", True):
114#                    candidates.append(child)
115#                    candidates.extend(cls.candidateWidgets(child, cls_list))
116#            else:
117#                candidates.extend(cls.candidateWidgets(child, cls_list))
118#        return candidates
119                               
120       
121   
122       
Note: See TracBrowser for help on using the repository browser.