File: timechart.py

package info (click to toggle)
pytimechart 1.0.0~rc1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 540 kB
  • sloc: python: 2,239; makefile: 77; sh: 60
file content (101 lines) | stat: -rwxr-xr-x 3,317 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/python
#------------------------------------------------------------------------------
import sys
try:
    from enthought.etsconfig.api import ETSConfig
except:
    print >>sys.stderr, "did you install python-chaco?"
    print >>sys.stderr, "maybe you did install chaco>=4, then you will need to install the package etsproxy"
    print >>sys.stderr, "sudo easy_install etsproxy"
    sys.exit(1)

# select the toolkit we want to use
# WX is more stable for now
#ETSConfig.toolkit = 'qt4'
ETSConfig.toolkit = 'wx'

# workaround bad bg color in ubuntu, with Ambiance theme
# wxgtk (or traitsGUI, I dont know) looks like using the menu's bgcolor 
# for all custom widgets bg colors. :-(

if ETSConfig.toolkit == 'wx':
    import wx, os
    if "gtk2" in wx.PlatformInfo:
        from gtk import rc_parse, MenuBar
        m = MenuBar()
        if m.rc_get_style().bg[0].red_float < 0.5: # only customize dark bg
            rc_parse(os.path.join(os.path.dirname(__file__),"images/gtkrc"))
        m.destroy()

# workaround bug in kiva's font manager that fails to find a correct default font on linux
if os.name=="posix":
    import warnings
    def devnull(*args):
        pass
    warnings.showwarning = devnull
    from  kiva.fonttools.font_manager import fontManager, FontProperties
    try: 
        font = FontProperties()
        font.set_name("DejaVu Sans")
        fontManager.defaultFont = fontManager.findfont(font)
        fontManager.warnings = None
    except: # this code will throw exception on ETS4, which has actually fixed fontmanager
        pass

from pyface.api import GUI
from window import open_file



def main():
    import optparse
    parser = optparse.OptionParser(usage="""\
%prog [options] [trace.txt|trace.txt.gz|trace.txt.lzma|trace.dat]

pytimechart - Fast graphical exploration and visualisation for linux kernel traces.""")
    parser.add_option("-p", "--prof", dest="prof", action="store_true",
                      help="activate profiling",
                      default=False)
    (options, args) = parser.parse_args()

    # Create the GUI (this does NOT start the GUI event loop).
    gui = GUI()
    if len(args) == 0:
        args.append("dummy")
    for fn in args:
        if not open_file(fn):
            sys.exit(0)
    if options.prof:
        import cProfile
        dict = {"gui":gui}
        cProfile.runctx('gui.start_event_loop()',dict,dict,'timechart.prof')
    else:
        gui.start_event_loop()

# used for profiling, and regression tests
def just_open():
    import optparse
    parser = optparse.OptionParser(usage="""\
%prog [options] [trace.txt|trace.txt.gz|trace.txt.lzma|trace.dat]

pytimechart_parse_test - just test parsing backend...""")
    parser.add_option("-p", "--prof", dest="prof", action="store_true",
                      help="activate profiling",
                      default=False)
    (options, args) = parser.parse_args()
    if len(args) > 0:
        fn = args[0]
    else:
        return
    if options.prof:
        import cProfile
        dict = {"open_file":open_file,"fn":fn}
        cProfile.runctx('open_file(fn)',dict,dict,'timechart.prof')
    else:
        open_file(fn)

if __name__ == '__main__':
    main()
import py2exe_wximports

##### EOF #####################################################################