This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tracemallocqt.py
executable file
·759 lines (655 loc) · 25.7 KB
/
tracemallocqt.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
#!/usr/bin/env python
try:
unicode
except NameError:
# Python 3
unicode = str
try:
from PySide import QtCore, QtGui
from PySide.QtCore import Qt
def fmt(x, *args):
return x % args
print("Qt binding: PySide")
except ImportError:
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import Qt
print("Qt binding: PyQt4")
def fmt(x, *args):
# QString in PyQt4 doesn't support the % operation
return unicode(x) % args
import datetime
import functools
import io
import linecache
import os.path
import pickle
import sys
import tracemalloc
import xml.sax.saxutils
from tools import detect_encoding
SORT_ROLE = Qt.UserRole
MORE_TEXT = '...'
def escape_html(text):
return xml.sax.saxutils.escape(text)
# FIXME
def tr(text):
return text
class StatsModel(QtCore.QAbstractTableModel):
def __init__(self, manager):
QtCore.QAbstractTableModel.__init__(self, manager.window)
self.manager = manager
self.show_frames = 3
self.tooltip_frames = 25
self.set_stats(None, None, 'filename', False)
def set_stats(self, snapshot1, snapshot2, group_by, cumulative):
self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()"))
if snapshot1 is not None:
if snapshot2 is not None:
stats = snapshot2.compare_to(snapshot1, group_by, cumulative)
else:
stats = snapshot1.statistics(group_by, cumulative)
self.stats = stats
self.diff = isinstance(stats[0], tracemalloc.StatisticDiff)
self.total = sum(stat.size for stat in self.stats)
self.total_text = tracemalloc._format_size(self.total, False)
if snapshot2 is not None:
total1 = sum(trace.size for trace in snapshot1.traces)
total2 = self.total
self.total_text += ' (%s)' % tracemalloc._format_size(total2 - total1, True)
else:
self.stats = ()
self.diff = False
self.total = 0
self.total_text = tracemalloc._format_size(0, False)
self.group_by = group_by
if self.group_by == 'traceback':
source = self.tr("Traceback")
elif self.group_by == 'lineno':
source = self.tr("Line")
else:
source = self.tr("Filename")
self.headers = [source, self.tr("Size")]
if self.diff:
self.headers.append(self.tr("Size Diff"))
self.headers.append(self.tr("Count"))
if self.diff:
self.headers.append(self.tr("Count Diff"))
self.headers.extend([self.tr("Item Size"), self.tr("%Total")])
self.emit(QtCore.SIGNAL("layoutChanged()"))
def get_default_sort_column(self):
if self.diff:
return 2
else:
return 1
def rowCount(self, parent):
return len(self.stats)
def columnCount(self, parent):
return len(self.headers)
def get_stat(self, index):
row = index.row()
return self.stats[row]
def format_size(self, role, size, diff):
if role == SORT_ROLE:
return size
if role == Qt.ToolTipRole:
if abs(size) < 10 * 1024:
return None
if diff:
return "%+i" % size
else:
return str(size)
return tracemalloc._format_size(size, diff)
def format_frame(self, role, frame):
filename = frame.filename
if role == Qt.DisplayRole:
filename = self.manager.format_filename(filename)
elif role == Qt.ToolTipRole:
filename = escape_html(filename)
lineno = frame.lineno
if self.group_by != "filename":
if role == SORT_ROLE:
return (filename, lineno)
else:
return "%s:%s" % (filename, lineno)
else:
return filename
def _data(self, column, role, stat):
if column == 0:
if self.group_by == 'traceback':
if role == Qt.ToolTipRole:
max_frames = self.tooltip_frames
else:
max_frames = self.show_frames
lines = []
if role == Qt.ToolTipRole:
lines.append(self.tr("Traceback (most recent first):"))
for frame in stat.traceback[:max_frames]:
line = self.format_frame(role, frame)
if role == Qt.ToolTipRole:
lines.append(' ' * 2 + line)
line = linecache.getline(frame.filename, frame.lineno).strip()
if line:
lines.append(' ' * 4 + '<b>%s</b>' % escape_html(line))
else:
lines.append(line)
if len(stat.traceback) > max_frames:
lines.append(MORE_TEXT)
if role == Qt.DisplayRole:
return ' <= '.join(lines)
elif role == Qt.ToolTipRole:
return '<br />'.join(lines)
else: # role == SORT_ROLE
return lines
else:
frame = stat.traceback[0]
if role == Qt.ToolTipRole:
if frame.lineno:
line = linecache.getline(frame.filename, frame.lineno).strip()
if line:
return line
return None
else:
if role == Qt.ToolTipRole:
return frame.filename
return None
else:
return self.format_frame(role, frame)
if column == 1:
size = stat.size
return self.format_size(role, size, False)
if self.diff:
if column == 2:
size = stat.size_diff
return self.format_size(role, size, True)
if column == 3:
if role == Qt.ToolTipRole:
return None
return stat.count
if column == 4:
if role == Qt.ToolTipRole:
return None
return "%+d" % stat.count_diff
if column == 5:
# Item Size
if stat.count:
size = stat.size / stat.count
return self.format_size(role, size, False)
else:
return 0
else:
if column == 2:
if role == Qt.ToolTipRole:
return None
return stat.count
if column == 3:
# Item Size
if not stat.count:
return 0
size = stat.size / stat.count
return self.format_size(role, size, False)
# %Total
if role == Qt.ToolTipRole:
return None
if not self.total:
return 0
percent = float(stat.size) / self.total
if role == Qt.DisplayRole:
return "%.1f %%" % (percent * 100.0)
else:
return percent
def data(self, index, role):
if not index.isValid():
return None
if role not in (Qt.DisplayRole, Qt.ToolTipRole):
return None
stat = self.stats[index.row()]
column = index.column()
return self._data(column, role, stat)
def headerData(self, col, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.headers[col]
return None
def sort(self, col, order):
"""sort table by given column number col"""
self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()"))
self.stats = sorted(self.stats,
key=functools.partial(self._data, col, SORT_ROLE),
reverse=(order == Qt.DescendingOrder))
self.emit(QtCore.SIGNAL("layoutChanged()"))
class HistoryState:
def __init__(self, group_by, filters, cumulative):
self.group_by = group_by
self.filters = filters
self.cumulative = cumulative
class History:
def __init__(self, stats):
self.stats = stats
self.states = []
self.index = -1
def clear(self):
del self.states[:]
self.index = -1
def append(self, state):
if self.index != len(self.states) - 1:
del self.states[self.index+1:]
self.states.append(state)
self.index += 1
def restore_state(self):
state = self.states[self.index]
self.stats.restore_state(state)
def go_next(self):
if self.index >= len(self.states) - 1:
return
self.index += 1
self.restore_state()
def go_previous(self):
if self.index == 0:
return
self.index -= 1
self.restore_state()
class StatsManager:
GROUP_BY = ['filename', 'lineno', 'traceback']
# index in the combo box
GROUP_BY_FILENAME = 0
GROUP_BY_LINENO = 1
GROUP_BY_TRACEBACK = 2
def __init__(self, window, app):
self.app = app
self.window = window
self.snapshots = window.snapshots
self.source = window.source
self.filename_parts = 3
self._auto_refresh = False
self.filters = []
self.history = History(self)
self.model = StatsModel(self)
self.view = QtGui.QTableView(window)
self.view.setModel(self.model)
self.cumulative_checkbox = QtGui.QCheckBox(window.tr("Cumulative sizes"), window)
self.group_by = QtGui.QComboBox(window)
self.group_by.addItems([
window.tr("Filename"),
window.tr("Line number"),
window.tr("Traceback"),
])
self.filters_label = QtGui.QLabel(window)
self.summary = QtGui.QLabel(window)
self.view.verticalHeader().hide()
self.view.resizeColumnsToContents()
self.view.setSortingEnabled(True)
window.connect(self.group_by, QtCore.SIGNAL("currentIndexChanged(int)"), self.group_by_changed)
window.connect(self.view, QtCore.SIGNAL("doubleClicked(const QModelIndex&)"), self.double_clicked)
window.connect(self.cumulative_checkbox, QtCore.SIGNAL("stateChanged(int)"), self.change_cumulative)
window.connect(self.snapshots.load_button, QtCore.SIGNAL("clicked(bool)"), self.load_snapshots)
window.connect(self.view.selectionModel(), QtCore.SIGNAL("selectionChanged(const QItemSelection&, const QItemSelection&)"), self.selection_changed)
self.clear()
self._auto_refresh = True
def clear(self):
del self.filters[:]
# self.filters.append(tracemalloc.Filter(False, "<frozen importlib._bootstrap>"))
self.cumulative_checkbox.setCheckState(Qt.Unchecked)
self.group_by.setCurrentIndex(self.GROUP_BY_FILENAME)
self.history.clear()
self.append_history()
self.refresh()
def load_snapshots(self, checked):
self.source.clear()
self.clear()
def append_history(self):
group_by = self.group_by.currentIndex()
filters = self.filters[:]
cumulative = self.cumulative_checkbox.checkState()
state = HistoryState(group_by, filters, cumulative)
self.history.append(state)
def restore_state(self, state):
self.filters = state.filters[:]
self._auto_refresh = False
self.cumulative_checkbox.setCheckState(state.cumulative)
self.group_by.setCurrentIndex(state.group_by)
self._auto_refresh = True
self.refresh()
def format_filename(self, filename):
parts = filename.split(os.path.sep)
if len(parts) > self.filename_parts:
parts = [MORE_TEXT] + parts[-self.filename_parts:]
return os.path.join(*parts)
def get_group_by(self):
index = self.group_by.currentIndex()
return self.GROUP_BY[index]
def get_cumulative(self):
return (self.cumulative_checkbox.checkState() == Qt.Checked)
def refresh(self):
group_by = self.get_group_by()
if group_by != 'traceback':
cumulative = self.get_cumulative()
else:
# FIXME: add visual feedback
cumulative = False
snapshot1, snapshot2 = self.snapshots.load_snapshots(self.filters)
self.view.clearSelection()
group_by = self.get_group_by()
self.model.set_stats(snapshot1, snapshot2, group_by, cumulative)
self.view.resizeColumnsToContents()
self.view.sortByColumn(self.model.get_default_sort_column(), Qt.DescendingOrder)
if self.filters:
filters = []
for filter in self.filters:
text = self.format_filename(filter.filename_pattern)
if filter.lineno:
text = "%s:%s" % (text, filter.lineno)
if filter.all_frames:
text += self.window.tr(" (any frame)")
if filter.inclusive:
text = fmt(self.window.tr("include %s"), text)
else:
text = fmt(self.window.tr("exclude %s"), text)
filters.append(text)
filters_text = ", ".join(filters)
else:
filters_text = self.window.tr("(none)")
filters_text = fmt(self.window.tr("Filters: %s"), filters_text)
self.filters_label.setText(filters_text)
total = self.model.total_text
lines = len(self.model.stats)
if group_by == 'filename':
lines = fmt(self.window.tr("Files: %s"), lines)
elif group_by == 'lineno':
lines = fmt(self.window.tr("Lines: %s"), lines)
else:
lines = fmt(self.window.tr("Tracebacks: %s"), lines)
total = fmt(self.window.tr("%s - Total: %s"), lines, total)
self.summary.setText(total)
def selection_changed(self, selected, unselected):
indexes = selected.indexes()
if not indexes:
return
stat = self.model.get_stat(indexes[0])
if stat is None:
return
self.source.set_traceback(stat.traceback,
self.get_group_by() != 'filename')
self.source.show_frame(stat.traceback[0])
def double_clicked(self, index):
stat = self.model.get_stat(index)
if stat is None:
return
group_by = self.get_group_by()
if group_by == 'filename':
all_frames = self.get_cumulative()
self.filters.append(tracemalloc.Filter(True, stat.traceback[0].filename, all_frames=all_frames))
self._auto_refresh = False
self.group_by.setCurrentIndex(self.GROUP_BY_LINENO)
self.append_history()
self._auto_refresh = True
self.refresh()
elif group_by == 'lineno':
# Replace filter by filename with filter by line
new_filter = tracemalloc.Filter(True, stat.traceback[0].filename, stat.traceback[0].lineno, all_frames=False)
if self.filters:
old_filter = self.filters[-1]
replace = (old_filter.inclusive == new_filter.inclusive
and old_filter.filename_pattern == new_filter.filename_pattern
and old_filter.lineno == None)
else:
replace = False
if replace:
self.filters[-1] = new_filter
else:
self.filters.append(new_filter)
self._auto_refresh = False
self.group_by.setCurrentIndex(self.GROUP_BY_TRACEBACK)
self.append_history()
self._auto_refresh = True
self.refresh()
def group_by_changed(self, index):
if not self._auto_refresh:
return
self.append_history()
self.refresh()
def change_cumulative(self, state):
if not self._auto_refresh:
return
self.append_history()
self.refresh()
class MySnapshot:
def __init__(self, filename):
self.filename = filename
ts = int(os.stat(filename).st_mtime)
self.timestamp = datetime.datetime.fromtimestamp(ts)
self.snapshot = None
self.ntraces = None
self.total = None
def load(self):
if self.snapshot is None:
print("Load snapshot %s" % self.filename)
with open(self.filename, "rb") as fp:
self.snapshot = pickle.load(fp)
self.ntraces = len(self.snapshot.traces)
self.total = sum(trace.size for trace in self.snapshot.traces)
return self.snapshot
def unload(self):
self.snapshot = None
def get_label(self):
if self.ntraces is None:
print("Process snapshot %s..." % self.filename)
# fill ntraces and total
self.load()
self.unload()
print("Process snapshot %s... done" % self.filename)
name = os.path.basename(self.filename)
infos = [
tracemalloc._format_size(self.total, False),
fmt(tr("%s traces"), self.ntraces),
str(self.timestamp),
]
return "%s (%s)" % (name, ', '.join(infos))
class SnapshotManager:
def __init__(self, parent):
self.snapshots = []
self.combo1 = QtGui.QComboBox(parent)
self.combo1.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
self.combo2 = QtGui.QComboBox(parent)
self.combo2.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
self.load_button = QtGui.QPushButton(tr("Load"), parent)
self.load_button.setEnabled(True)
def set_filenames(self, filenames):
self.snapshots = [MySnapshot(filename) for filename in filenames]
self.snapshots.sort(key=lambda snapshot: snapshot.timestamp)
self.snapshots[0].load()
if len(self.snapshots) > 1:
self.snapshots[1].load()
items = [snapshot.get_label() for snapshot in self.snapshots]
self.combo1.addItems(items)
self.combo1.setCurrentIndex(0)
items = ['(none)'] + items
self.combo2.addItems(items)
if len(self.snapshots) > 1:
self.combo2.setCurrentIndex(2)
else:
self.combo2.setCurrentIndex(0)
def load_snapshots(self, filters):
index1 = self.combo1.currentIndex()
index2 = self.combo2.currentIndex()
snapshot1 = self.snapshots[index1].load()
snapshot2 = None
if index2:
index2 -= 1
if index2 != index1:
snapshot2 = self.snapshots[index2].load()
else:
self.combo2.setCurrentIndex(0)
# FIXME: incremental filter
if filters:
snapshot1 = snapshot1.filter_traces(filters)
if snapshot2 is not None:
if filters:
snapshot2 = snapshot2.filter_traces(filters)
return (snapshot1, snapshot2)
class SourceCodeManager:
def __init__(self, window):
self.text_edit = QtGui.QTextEdit(window)
self.text_edit.setReadOnly(True)
# FIXME: write an optimized model
self.traceback = None
self.traceback_model = QtGui.QStringListModel()
self.traceback_view = QtGui.QListView(window)
self.traceback_view.setModel(self.traceback_model)
self.traceback_view.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
window.connect(self.traceback_view.selectionModel(), QtCore.SIGNAL("selectionChanged(const QItemSelection&, const QItemSelection&)"), self.frame_selection_changed)
# filename => (lines, mtime)
self._file_cache = {}
self.clear()
def clear(self):
self._current_file = None
self._current_lineno = None
self.traceback_model.setStringList([])
self.text_edit.setText('')
self._file_cache.clear()
def frame_selection_changed(self, selected, unselected):
indexes = selected.indexes()
if not indexes:
return
row = indexes[0].row()
frame = self.traceback[row]
self.show_frame(frame)
def set_traceback(self, traceback, show_lineno):
self.traceback = traceback
if show_lineno:
lines = ['%s:%s' % (frame.filename, frame.lineno) for frame in traceback]
else:
lines = [frame.filename for frame in traceback]
self.traceback_model.setStringList(lines)
def read_file(self, filename):
try:
mtime = os.stat(filename).st_mtime
except OSError:
return None
if filename in self._file_cache:
text, cache_mtime = self._file_cache[filename]
if mtime == cache_mtime:
return text
print("Read %s content (mtime: %s)" % (filename, mtime))
with open(filename, 'rb') as fp:
encoding, lines = detect_encoding(fp.readline)
lineno = 1
lines = []
with io.open(filename, 'r', encoding=encoding) as fp:
for lineno, line in enumerate(fp, 1):
lines.append('%d: %s' % (lineno, line.rstrip()))
text = '\n'.join(lines)
self._file_cache[filename] = (text, mtime)
return text
def load_file(self, filename):
if filename.startswith("<") and filename.startswith(">"):
return False
if self._current_file == filename:
return True
text = self.read_file(filename)
if text is None:
return False
self.text_edit.setText(text)
self._current_file = filename
self._current_lineno = None
return True
def set_line_number(self, lineno):
if self._current_lineno == lineno:
return
self._current_lineno = lineno
doc = self.text_edit.document()
# FIXME: complexity in O(number of lines)?
block = doc.findBlockByLineNumber(lineno - 1)
cursor = QtGui.QTextCursor(block)
cursor.select(QtGui.QTextCursor.BlockUnderCursor)
# FIXME: complexity in O(number of lines)?
self.text_edit.setTextCursor(cursor)
def show_frame(self, frame):
filename = frame.filename
if not self.load_file(filename):
self._current_file = None
self.text_edit.setText('')
return
if frame.lineno > 0:
self.set_line_number(frame.lineno)
class MainWindow(QtGui.QMainWindow):
def __init__(self, app, filenames):
QtGui.QMainWindow.__init__(self)
self.setGeometry(300, 200, 1300, 450)
self.setWindowTitle("Tracemalloc")
# actions
action_previous = QtGui.QAction(self.tr("Previous"), self)
self.connect(action_previous, QtCore.SIGNAL("triggered(bool)"), self.go_previous)
action_next = QtGui.QAction(self.tr("Next"), self)
self.connect(action_next, QtCore.SIGNAL("triggered(bool)"), self.go_next)
# toolbar
toolbar = self.addToolBar(self.tr("Navigation"))
toolbar.addAction(action_previous)
toolbar.addAction(action_next)
# create classes
self.snapshots = SnapshotManager(self)
self.snapshots.set_filenames(filenames)
self.source = SourceCodeManager(self)
self.stats = StatsManager(self, app)
self.history = self.stats.history
# snapshots
hbox1 = QtGui.QHBoxLayout()
hbox1.addWidget(QtGui.QLabel(self.tr("Snapshot:")))
hbox1.addWidget(self.snapshots.combo1)
hbox2 = QtGui.QHBoxLayout()
hbox2.addWidget(QtGui.QLabel(self.tr("compared to:")))
hbox2.addWidget(self.snapshots.combo2)
vbox = QtGui.QVBoxLayout()
vbox.addLayout(hbox1)
vbox.addLayout(hbox2)
hbox3 = QtGui.QHBoxLayout()
hbox3.addLayout(vbox)
hbox3.addWidget(self.snapshots.load_button)
snap_box = QtGui.QWidget()
snap_box.setLayout(hbox3)
# Group by
hbox = QtGui.QHBoxLayout()
hbox.addWidget(QtGui.QLabel(self.tr("Group by:")))
hbox.addWidget(self.stats.group_by)
hbox.addWidget(self.stats.cumulative_checkbox)
hbox.addWidget(self.stats.filters_label)
self.stats.filters_label.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
group_by_box = QtGui.QWidget()
group_by_box.setLayout(hbox)
# Source
source_splitter = QtGui.QSplitter()
source_splitter.addWidget(self.source.traceback_view)
self.source.traceback_view.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum))
source_splitter.addWidget(self.source.text_edit)
self.source.text_edit.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
# Top widgets
layout = QtGui.QVBoxLayout()
layout.addWidget(snap_box)
layout.addWidget(group_by_box)
layout.addWidget(self.stats.view)
layout.addWidget(self.stats.summary)
top_widget = QtGui.QWidget(self)
top_widget.setLayout(layout)
# main splitter
main_splitter = QtGui.QSplitter(Qt.Vertical)
main_splitter.addWidget(top_widget)
main_splitter.addWidget(source_splitter)
self.setCentralWidget(main_splitter)
def go_previous(self, checked):
self.history.go_previous()
def go_next(self, checked):
self.history.go_next()
class Application:
def __init__(self):
if len(sys.argv) >= 2:
filenames = sys.argv[1:]
else:
print("usage: %s snapshot1.pickle [snapshot2.pickle snapshot3.pickle ...]")
sys.exit(1)
# Create a Qt application
self.app = QtGui.QApplication(sys.argv)
self.window = MainWindow(self, filenames)
def main(self):
self.window.show()
self.app.exec_()
sys.exit()
if __name__ == "__main__":
Application().main()