File: Grab.py

package info (click to toggle)
pyqwt5 5.2.1~cvs20091107%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,004 kB
  • sloc: python: 8,762; cpp: 1,217; makefile: 120
file content (76 lines) | stat: -rwxr-xr-x 1,421 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python

try:
    import PyQt4.Qwt5.iqt
except ImportError:
    raise SystemExit, 'Grab.py requires the PyQt4.Qwt5.iqt module'

from PyQt4.Qt import QPixmap

# a list of .py files defining a function make()
# make() must initialize, show and return:
#       a QWidget
# or:
#       a tuple of QWidgets
jobs = [
    'BarPlotDemo',
    'BodeDemo',
    'CPUplot',
    'CartesianDemo',
    'CliDemo',
    'CurveDemo1',
    'CurveDemo2',
    'CurveDemo3',
    'DataDemo',
    'DialDemo',
    'ErrorBarDemo',
    'EventFilterDemo',
    'HistogramDemo',
#    'ImagePlotDemo',
    'MapDemo',
    'MaskedDataDemo',
#    'MultiDemo',
    'PickerDemo',
    'RadioDemo',
    'ReallySimpleDemo',
    'SimpleDemo',
    'SliderDemo',
    'SpectrogramDemo',
    ]


def expose(jobs, cache = {}):
    for job in jobs:
        result = __import__(job).make()
        if type(result) == type(()):
            for i in range(len(result)):
                cache['%s%s' % (job, i)] = result[i]
        else:
            cache[job] = result
    return cache

# expose()


def save(cache):
    for name, widget in cache.items():
        pixmap = QPixmap.grabWidget(widget)
        pixmap.save(name+'.png', 'PNG')

# save()


def main():
    cache = expose(jobs)
    raw_input("Are all widgets looking HAPPY? ")
    save(cache)

# main()


if __name__ == '__main__':
    main()

# Local Variables: ***
# mode: python ***
# End: ***