~ubuntu-branches/ubuntu/utopic/pytimechart/utopic

« back to all changes in this revision

Viewing changes to timechart/timechart.py

  • Committer: Package Import Robot
  • Author(s): Varun Hiremath
  • Date: 2011-11-13 18:14:30 UTC
  • Revision ID: package-import@ubuntu.com-20111113181430-bg2ompukqunnyhtt
Tags: upstream-1.0.0~rc1
ImportĀ upstreamĀ versionĀ 1.0.0~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#------------------------------------------------------------------------------
 
3
import sys
 
4
try:
 
5
    from enthought.etsconfig.api import ETSConfig
 
6
except:
 
7
    print >>sys.stderr, "did you install python-chaco?"
 
8
    print >>sys.stderr, "maybe you did install chaco>=4, then you will need to install the package etsproxy"
 
9
    print >>sys.stderr, "sudo easy_install etsproxy"
 
10
    sys.exit(1)
 
11
 
 
12
# select the toolkit we want to use
 
13
# WX is more stable for now
 
14
#ETSConfig.toolkit = 'qt4'
 
15
ETSConfig.toolkit = 'wx'
 
16
 
 
17
# workaround bad bg color in ubuntu, with Ambiance theme
 
18
# wxgtk (or traitsGUI, I dont know) looks like using the menu's bgcolor 
 
19
# for all custom widgets bg colors. :-(
 
20
 
 
21
if ETSConfig.toolkit == 'wx':
 
22
    import wx, os
 
23
    if "gtk2" in wx.PlatformInfo:
 
24
        from gtk import rc_parse, MenuBar
 
25
        m = MenuBar()
 
26
        if m.rc_get_style().bg[0].red_float < 0.5: # only customize dark bg
 
27
            rc_parse(os.path.join(os.path.dirname(__file__),"images/gtkrc"))
 
28
        m.destroy()
 
29
 
 
30
# workaround bug in kiva's font manager that fails to find a correct default font on linux
 
31
if os.name=="posix":
 
32
    import warnings
 
33
    def devnull(*args):
 
34
        pass
 
35
    warnings.showwarning = devnull
 
36
    from  enthought.kiva.fonttools.font_manager import fontManager, FontProperties
 
37
    try: 
 
38
        font = FontProperties()
 
39
        font.set_name("DejaVu Sans")
 
40
        fontManager.defaultFont = fontManager.findfont(font)
 
41
        fontManager.warnings = None
 
42
    except: # this code will throw exception on ETS4, which has actually fixed fontmanager
 
43
        pass
 
44
 
 
45
from enthought.pyface.api import GUI
 
46
from window import open_file
 
47
 
 
48
 
 
49
 
 
50
def main():
 
51
    import optparse
 
52
    parser = optparse.OptionParser(usage="""\
 
53
%prog [options] [trace.txt|trace.txt.gz|trace.txt.lzma|trace.dat]
 
54
 
 
55
pytimechart - Fast graphical exploration and visualisation for linux kernel traces.""")
 
56
    parser.add_option("-p", "--prof", dest="prof", action="store_true",
 
57
                      help="activate profiling",
 
58
                      default=False)
 
59
    (options, args) = parser.parse_args()
 
60
 
 
61
    # Create the GUI (this does NOT start the GUI event loop).
 
62
    gui = GUI()
 
63
    if len(args) == 0:
 
64
        args.append("dummy")
 
65
    for fn in args:
 
66
        if not open_file(fn):
 
67
            sys.exit(0)
 
68
    if options.prof:
 
69
        import cProfile
 
70
        dict = {"gui":gui}
 
71
        cProfile.runctx('gui.start_event_loop()',dict,dict,'timechart.prof')
 
72
    else:
 
73
        gui.start_event_loop()
 
74
 
 
75
# used for profiling, and regression tests
 
76
def just_open():
 
77
    import optparse
 
78
    parser = optparse.OptionParser(usage="""\
 
79
%prog [options] [trace.txt|trace.txt.gz|trace.txt.lzma|trace.dat]
 
80
 
 
81
pytimechart_parse_test - just test parsing backend...""")
 
82
    parser.add_option("-p", "--prof", dest="prof", action="store_true",
 
83
                      help="activate profiling",
 
84
                      default=False)
 
85
    (options, args) = parser.parse_args()
 
86
    if len(args) > 0:
 
87
        fn = args[0]
 
88
    else:
 
89
        return
 
90
    if options.prof:
 
91
        import cProfile
 
92
        dict = {"open_file":open_file,"fn":fn}
 
93
        cProfile.runctx('open_file(fn)',dict,dict,'timechart.prof')
 
94
    else:
 
95
        open_file(fn)
 
96
 
 
97
if __name__ == '__main__':
 
98
    main()
 
99
import py2exe_wximports
 
100
 
 
101
##### EOF #####################################################################