2007-11-22 08:47:06 +00:00
|
|
|
# -*- coding: utf-8; mode: python; -*-
|
|
|
|
#
|
|
|
|
# GStreamer Debug Viewer - View and analyze GStreamer debug log files
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 René Stadler <mail@renestadler.de>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3 of the License, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""GStreamer Debug Viewer timeline widget plugin."""
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2009-08-06 23:54:10 +00:00
|
|
|
from GstDebugViewer import Common, Data
|
|
|
|
from GstDebugViewer.GUI.colors import LevelColorThemeTango, ThreadColorThemeTango
|
2016-09-28 18:34:53 +00:00
|
|
|
from GstDebugViewer.Plugins import FeatureBase, PluginBase
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:34:53 +00:00
|
|
|
from gettext import gettext as _
|
2015-10-20 13:21:01 +00:00
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
2007-11-26 14:52:21 +00:00
|
|
|
import cairo
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def iter_model_reversed(model):
|
|
|
|
|
|
|
|
count = model.iter_n_children(None)
|
2018-04-14 13:22:11 +00:00
|
|
|
for i in range(count - 1, 0, -1):
|
2007-11-14 08:30:19 +00:00
|
|
|
yield model[i]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
class LineFrequencySentinel (object):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, model):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
self.model = model
|
2016-09-28 18:38:55 +00:00
|
|
|
self.clear()
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def clear(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
self.data = None
|
2007-11-21 15:40:31 +00:00
|
|
|
self.n_partitions = None
|
2007-11-16 15:25:08 +00:00
|
|
|
self.partitions = None
|
|
|
|
self.step = None
|
2007-11-26 14:52:21 +00:00
|
|
|
self.ts_range = None
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def _search_ts(self, target_ts, first_index, last_index):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-20 11:56:15 +00:00
|
|
|
model_get = self.model.get_value
|
2007-11-14 08:30:19 +00:00
|
|
|
model_iter_nth_child = self.model.iter_nth_child
|
|
|
|
col_id = self.model.COL_TIME
|
|
|
|
|
2008-01-23 15:07:51 +00:00
|
|
|
# TODO: Rewrite using a lightweight view object + bisect.
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
while True:
|
|
|
|
middle = (last_index - first_index) // 2 + first_index
|
|
|
|
if middle == first_index:
|
2009-06-12 21:58:36 +00:00
|
|
|
return first_index
|
2016-09-28 18:38:55 +00:00
|
|
|
ts = model_get(model_iter_nth_child(None, middle), col_id)
|
2007-11-14 08:30:19 +00:00
|
|
|
if ts < target_ts:
|
2009-06-12 21:58:36 +00:00
|
|
|
first_index = middle
|
2007-11-14 08:30:19 +00:00
|
|
|
elif ts > target_ts:
|
2009-06-12 21:58:36 +00:00
|
|
|
last_index = middle
|
2007-11-14 08:30:19 +00:00
|
|
|
else:
|
|
|
|
return middle
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def run_for(self, n):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if n == 0:
|
2016-09-28 18:38:55 +00:00
|
|
|
raise ValueError("illegal value for n")
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.n_partitions = n
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def process(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
model = self.model
|
|
|
|
result = []
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions = []
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-21 11:42:32 +00:00
|
|
|
first_ts = None
|
|
|
|
for row in self.model:
|
|
|
|
first_ts = row[model.COL_TIME]
|
|
|
|
if first_ts is not None:
|
|
|
|
break
|
|
|
|
|
|
|
|
if first_ts is None:
|
|
|
|
return
|
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
last_ts = None
|
2007-11-29 13:34:35 +00:00
|
|
|
i = 0
|
|
|
|
UNPARSABLE_LIMIT = 500
|
2016-09-28 18:38:55 +00:00
|
|
|
for row in iter_model_reversed(self.model):
|
2007-11-14 08:30:19 +00:00
|
|
|
last_ts = row[model.COL_TIME]
|
2007-11-21 11:42:32 +00:00
|
|
|
# FIXME: We ignore 0 here (unparsable lines!), this should be
|
|
|
|
# handled differently!
|
2007-11-29 13:34:35 +00:00
|
|
|
i += 1
|
|
|
|
if i == UNPARSABLE_LIMIT:
|
|
|
|
break
|
2007-11-14 08:30:19 +00:00
|
|
|
if last_ts:
|
|
|
|
last_index = row.path[0]
|
|
|
|
break
|
|
|
|
|
2007-11-29 13:34:35 +00:00
|
|
|
if last_ts is None or last_ts < first_ts:
|
2007-11-16 15:25:08 +00:00
|
|
|
return
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
step = int(float(last_ts - first_ts) / float(self.n_partitions))
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
YIELD_LIMIT = 100
|
|
|
|
limit = YIELD_LIMIT
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
first_index = 0
|
2007-11-21 11:42:32 +00:00
|
|
|
target_ts = first_ts + step
|
2007-11-14 08:30:19 +00:00
|
|
|
old_found = 0
|
|
|
|
while target_ts < last_ts:
|
2007-11-21 15:40:31 +00:00
|
|
|
limit -= 1
|
|
|
|
if limit == 0:
|
|
|
|
limit = YIELD_LIMIT
|
|
|
|
yield True
|
2016-09-28 18:38:55 +00:00
|
|
|
found = self._search_ts(target_ts, first_index, last_index)
|
|
|
|
result.append(found - old_found)
|
|
|
|
partitions.append(found)
|
2007-11-14 08:30:19 +00:00
|
|
|
old_found = found
|
|
|
|
first_index = found
|
|
|
|
target_ts += step
|
|
|
|
|
2007-11-29 13:25:31 +00:00
|
|
|
if step == 0:
|
|
|
|
result = []
|
|
|
|
partitions = []
|
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
self.step = step
|
|
|
|
self.data = result
|
|
|
|
self.partitions = partitions
|
2007-11-21 11:42:32 +00:00
|
|
|
self.ts_range = (first_ts, last_ts,)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2007-11-16 13:06:59 +00:00
|
|
|
class LevelDistributionSentinel (object):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, freq_sentinel, model):
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.freq_sentinel = freq_sentinel
|
2007-11-16 13:06:59 +00:00
|
|
|
self.model = model
|
2007-11-16 15:25:08 +00:00
|
|
|
self.data = []
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def clear(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
del self.data[:]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def process(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2018-05-13 12:02:11 +00:00
|
|
|
MAX_LEVELS = 9
|
2007-11-21 15:40:31 +00:00
|
|
|
YIELD_LIMIT = 10000
|
|
|
|
y = YIELD_LIMIT
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-20 11:56:15 +00:00
|
|
|
model_get = self.model.get_value
|
2007-11-16 13:06:59 +00:00
|
|
|
model_next = self.model.iter_next
|
|
|
|
id_time = self.model.COL_TIME
|
|
|
|
id_level = self.model.COL_LEVEL
|
2007-11-22 07:31:37 +00:00
|
|
|
del self.data[:]
|
|
|
|
data = self.data
|
2007-11-16 13:06:59 +00:00
|
|
|
i = 0
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions_i = 0
|
2007-11-21 15:40:31 +00:00
|
|
|
partitions = self.freq_sentinel.partitions
|
2010-07-06 08:42:08 +00:00
|
|
|
counts = [0] * MAX_LEVELS
|
2016-09-28 18:38:55 +00:00
|
|
|
tree_iter = self.model.get_iter_first()
|
2007-11-26 12:42:46 +00:00
|
|
|
|
|
|
|
if not partitions:
|
|
|
|
return
|
2007-11-30 12:05:18 +00:00
|
|
|
|
2012-09-21 20:52:25 +00:00
|
|
|
level_index = 0
|
|
|
|
level_iter = None
|
|
|
|
|
2007-11-30 12:05:18 +00:00
|
|
|
finished = False
|
2007-11-16 13:06:59 +00:00
|
|
|
while tree_iter:
|
2007-11-21 15:40:31 +00:00
|
|
|
y -= 1
|
|
|
|
if y == 0:
|
|
|
|
y = YIELD_LIMIT
|
|
|
|
yield True
|
2012-09-21 20:52:25 +00:00
|
|
|
if level_iter is None:
|
|
|
|
stop_index = level_index + 512
|
2016-09-28 18:38:55 +00:00
|
|
|
levels = self.model.get_value_range(id_level,
|
|
|
|
level_index, stop_index)
|
2012-09-21 20:52:25 +00:00
|
|
|
level_index = stop_index
|
2016-09-28 18:38:55 +00:00
|
|
|
level_iter = iter(levels)
|
2012-09-21 20:52:25 +00:00
|
|
|
try:
|
2018-04-14 13:22:11 +00:00
|
|
|
level = level_iter.__next__()
|
2012-09-21 20:52:25 +00:00
|
|
|
except StopIteration:
|
|
|
|
level_iter = None
|
|
|
|
continue
|
2007-11-30 12:05:18 +00:00
|
|
|
while i > partitions[partitions_i]:
|
2016-09-28 18:38:55 +00:00
|
|
|
data.append(tuple(counts))
|
2010-07-06 08:42:08 +00:00
|
|
|
counts = [0] * MAX_LEVELS
|
2007-11-16 15:25:08 +00:00
|
|
|
partitions_i += 1
|
2016-09-28 18:38:55 +00:00
|
|
|
if partitions_i == len(partitions):
|
2007-11-30 12:05:18 +00:00
|
|
|
finished = True
|
2007-11-16 15:25:08 +00:00
|
|
|
break
|
2007-11-30 12:05:18 +00:00
|
|
|
if finished:
|
|
|
|
break
|
2007-11-16 13:06:59 +00:00
|
|
|
counts[level] += 1
|
2007-11-30 12:05:18 +00:00
|
|
|
i += 1
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-29 11:51:46 +00:00
|
|
|
# Now handle the last one:
|
2016-09-28 18:38:55 +00:00
|
|
|
data.append(tuple(counts))
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
yield False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
class UpdateProcess (object):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, freq_sentinel, dist_sentinel):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
self.freq_sentinel = freq_sentinel
|
|
|
|
self.dist_sentinel = dist_sentinel
|
|
|
|
self.is_running = False
|
2016-09-28 18:38:55 +00:00
|
|
|
self.dispatcher = Common.Data.GSourceDispatcher()
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __process(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if self.freq_sentinel is None or self.dist_sentinel is None:
|
|
|
|
return
|
|
|
|
|
2007-11-21 15:40:31 +00:00
|
|
|
self.is_running = True
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
for x in self.freq_sentinel.process():
|
2007-11-21 15:40:31 +00:00
|
|
|
yield True
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.handle_sentinel_finished(self.freq_sentinel)
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
for x in self.dist_sentinel.process():
|
2007-11-21 15:40:31 +00:00
|
|
|
yield True
|
2016-09-28 18:38:55 +00:00
|
|
|
self.handle_sentinel_progress(self.dist_sentinel)
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
self.is_running = False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.handle_sentinel_finished(self.dist_sentinel)
|
|
|
|
self.handle_process_finished()
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
yield False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def run(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
if self.is_running:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.dispatcher(self.__process())
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def abort(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
if not self.is_running:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.dispatcher.cancel()
|
2007-11-21 15:40:31 +00:00
|
|
|
self.is_running = False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_sentinel_progress(self, sentinel):
|
2007-11-22 07:31:37 +00:00
|
|
|
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_sentinel_finished(self, sentinel):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_process_finished(self):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
class VerticalTimelineWidget (Gtk.DrawingArea):
|
2007-11-23 09:46:43 +00:00
|
|
|
|
|
|
|
__gtype_name__ = "GstDebugViewerVerticalTimelineWidget"
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, log_view):
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
GObject.GObject.__init__(self)
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger = logging.getLogger("ui.vtimeline")
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2008-02-05 15:29:52 +00:00
|
|
|
self.log_view = log_view
|
2016-09-28 18:38:55 +00:00
|
|
|
self.theme = ThreadColorThemeTango()
|
2007-11-23 09:46:43 +00:00
|
|
|
self.params = None
|
2007-11-23 14:06:10 +00:00
|
|
|
self.thread_colors = {}
|
|
|
|
self.next_thread_color = 0
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2007-12-07 10:02:15 +00:00
|
|
|
try:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.set_tooltip_text(_("Vertical timeline\n"
|
|
|
|
"Different colors represent different threads"))
|
2007-12-07 10:02:15 +00:00
|
|
|
except AttributeError:
|
|
|
|
# Compatibility.
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_draw(self, ctx):
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
alloc = self.get_allocation()
|
2015-10-20 13:21:01 +00:00
|
|
|
x = alloc.x
|
|
|
|
y = alloc.y
|
|
|
|
w = alloc.width
|
|
|
|
h = alloc.height
|
2007-11-23 09:46:43 +00:00
|
|
|
|
|
|
|
# White background rectangle.
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_line_width(0.)
|
|
|
|
ctx.rectangle(0, 0, w, h)
|
|
|
|
ctx.set_source_rgb(1., 1., 1.)
|
|
|
|
ctx.fill()
|
|
|
|
ctx.new_path()
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2008-02-05 15:29:52 +00:00
|
|
|
if self.params is None:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__update_params()
|
2008-02-05 15:29:52 +00:00
|
|
|
|
2007-11-23 09:46:43 +00:00
|
|
|
if self.params is None:
|
|
|
|
return
|
|
|
|
|
2007-11-23 14:06:10 +00:00
|
|
|
first_y, cell_height, data = self.params
|
2016-09-28 18:38:55 +00:00
|
|
|
if len(data) < 2:
|
2007-11-30 15:33:08 +00:00
|
|
|
return
|
2007-11-23 14:06:10 +00:00
|
|
|
first_ts, last_ts = data[0][0], data[-1][0]
|
2007-11-23 09:46:43 +00:00
|
|
|
ts_range = last_ts - first_ts
|
|
|
|
if ts_range == 0:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_line_width(1.)
|
|
|
|
ctx.set_source_rgb(0., 0., 0.)
|
2007-11-26 16:01:30 +00:00
|
|
|
|
|
|
|
half_height = cell_height // 2 - .5
|
|
|
|
quarter_height = cell_height // 4 - .5
|
|
|
|
first_y += half_height
|
2016-09-28 18:38:55 +00:00
|
|
|
for i, i_data in enumerate(data):
|
2007-11-23 14:06:10 +00:00
|
|
|
ts, thread = i_data
|
|
|
|
if thread in self.thread_colors:
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*self.thread_colors[thread])
|
2007-11-23 14:06:10 +00:00
|
|
|
else:
|
|
|
|
self.next_thread_color += 1
|
2016-09-28 18:38:55 +00:00
|
|
|
if self.next_thread_color == len(self.theme.colors):
|
2007-11-23 14:06:10 +00:00
|
|
|
self.next_thread_color = 0
|
2016-09-28 18:38:55 +00:00
|
|
|
color = self.theme.colors[
|
|
|
|
self.next_thread_color][0].float_tuple()
|
2007-11-23 14:06:10 +00:00
|
|
|
self.thread_colors[thread] = color
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*color)
|
|
|
|
ts_fraction = float(ts - first_ts) / ts_range
|
2007-11-23 09:46:43 +00:00
|
|
|
ts_offset = ts_fraction * h
|
|
|
|
row_offset = first_y + i * cell_height
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.move_to(-.5, ts_offset)
|
|
|
|
ctx.line_to(half_height, ts_offset)
|
|
|
|
ctx.line_to(w - quarter_height, row_offset)
|
|
|
|
ctx.stroke()
|
|
|
|
ctx.line_to(w - quarter_height, row_offset)
|
|
|
|
ctx.line_to(w + .5, row_offset - half_height)
|
|
|
|
ctx.line_to(w + .5, row_offset + half_height)
|
|
|
|
ctx.fill()
|
2015-10-21 13:03:03 +00:00
|
|
|
return True
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_configure_event(self, event):
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2015-10-21 13:03:03 +00:00
|
|
|
self.params = None
|
2016-09-28 18:38:55 +00:00
|
|
|
self.queue_draw()
|
2015-10-21 13:03:03 +00:00
|
|
|
|
|
|
|
return False
|
2016-09-28 18:34:53 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_get_preferred_width(self):
|
2015-10-21 13:03:03 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
return 64, 64 # FIXME
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def clear(self):
|
2007-11-23 13:04:14 +00:00
|
|
|
|
|
|
|
self.params = None
|
2016-09-28 18:38:55 +00:00
|
|
|
self.thread_colors.clear()
|
2007-11-23 14:06:10 +00:00
|
|
|
self.next_thread_color = 0
|
2016-09-28 18:38:55 +00:00
|
|
|
self.queue_draw()
|
2007-11-23 13:04:14 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __update_params(self):
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2007-11-29 11:53:42 +00:00
|
|
|
# FIXME: Ideally we should take the vertical position difference of the
|
|
|
|
# view into account (which is 0 with the current UI layout).
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2008-02-05 15:29:52 +00:00
|
|
|
view = self.log_view
|
2016-09-28 18:38:55 +00:00
|
|
|
model = view.get_model()
|
|
|
|
visible_range = view.get_visible_range()
|
2008-02-05 15:29:52 +00:00
|
|
|
if visible_range is None:
|
|
|
|
return
|
|
|
|
start_path, end_path = visible_range
|
|
|
|
|
|
|
|
if not start_path or not end_path:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
column = view.get_column(0)
|
|
|
|
bg_rect = view.get_background_area(start_path, column)
|
2008-02-05 15:29:52 +00:00
|
|
|
cell_height = bg_rect.height
|
2016-09-28 18:38:55 +00:00
|
|
|
cell_rect = view.get_cell_area(start_path, column)
|
2008-02-05 15:29:52 +00:00
|
|
|
try:
|
2016-09-28 18:38:55 +00:00
|
|
|
first_y = view.convert_bin_window_to_widget_coords(
|
|
|
|
cell_rect.x, cell_rect.y)[1]
|
2008-02-05 15:29:52 +00:00
|
|
|
except (AttributeError, SystemError,):
|
|
|
|
# AttributeError is with PyGTK before 2.12. SystemError is raised
|
|
|
|
# with PyGTK 2.12.0, pygtk bug #479012.
|
|
|
|
first_y = cell_rect.y % cell_height
|
|
|
|
|
|
|
|
global _warn_tree_view_coords
|
|
|
|
try:
|
|
|
|
_warn_tree_view_coords
|
|
|
|
except NameError:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.warning("tree view coordinate conversion method "
|
|
|
|
"not available, using aproximate offset")
|
2008-02-05 15:29:52 +00:00
|
|
|
# Only warn once:
|
|
|
|
_warn_tree_view_coords = True
|
|
|
|
|
|
|
|
data = []
|
2016-09-28 18:38:55 +00:00
|
|
|
tree_iter = model.get_iter(start_path)
|
2008-02-05 15:29:52 +00:00
|
|
|
if tree_iter is None:
|
|
|
|
return
|
2016-09-28 18:38:55 +00:00
|
|
|
while model.get_path(tree_iter) != end_path:
|
|
|
|
data.append(
|
|
|
|
model.get(tree_iter, model.COL_TIME, model.COL_THREAD))
|
|
|
|
tree_iter = model.iter_next(tree_iter)
|
2008-02-05 15:29:52 +00:00
|
|
|
|
2007-11-23 14:06:10 +00:00
|
|
|
self.params = (first_y, cell_height, data,)
|
2008-02-05 15:29:52 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def update(self):
|
2008-02-05 15:29:52 +00:00
|
|
|
|
|
|
|
self.params = None
|
2016-09-28 18:38:55 +00:00
|
|
|
self.queue_draw()
|
|
|
|
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
class TimelineWidget (Gtk.DrawingArea):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-17 08:06:09 +00:00
|
|
|
__gtype_name__ = "GstDebugViewerTimelineWidget"
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
__gsignals__ = {"change-position": (GObject.SignalFlags.RUN_LAST,
|
|
|
|
None,
|
|
|
|
(GObject.TYPE_INT,),)}
|
2012-09-20 18:11:48 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
GObject.GObject.__init__(self)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger = logging.getLogger("ui.timeline")
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.add_events(Gdk.EventMask.BUTTON1_MOTION_MASK |
|
|
|
|
Gdk.EventMask.BUTTON_PRESS_MASK |
|
|
|
|
Gdk.EventMask.BUTTON_RELEASE_MASK)
|
2012-09-20 18:11:48 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.process = UpdateProcess(None, None)
|
2007-11-26 14:52:21 +00:00
|
|
|
self.process.handle_sentinel_progress = self.__handle_sentinel_progress
|
|
|
|
self.process.handle_sentinel_finished = self.__handle_sentinel_finished
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
self.model = None
|
2007-11-21 15:40:31 +00:00
|
|
|
self.__offscreen = None
|
2011-09-09 19:47:16 +00:00
|
|
|
self.__offscreen_size = (0, 0)
|
2012-09-24 00:15:09 +00:00
|
|
|
self.__offscreen_dirty = (0, 0)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-26 14:52:21 +00:00
|
|
|
self.__position_ts_range = None
|
|
|
|
|
2010-06-30 13:16:45 +00:00
|
|
|
try:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.set_tooltip_text(_("Log event histogram\n"
|
|
|
|
"Different colors represent different log-levels"))
|
2010-06-30 13:16:45 +00:00
|
|
|
except AttributeError:
|
|
|
|
# Compatibility.
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __handle_sentinel_progress(self, sentinel):
|
2007-11-22 07:31:37 +00:00
|
|
|
|
2012-09-24 00:15:09 +00:00
|
|
|
if sentinel == self.process.dist_sentinel:
|
|
|
|
old_progress = self.__dist_sentinel_progress
|
2016-09-28 18:38:55 +00:00
|
|
|
new_progress = len(sentinel.data)
|
2012-09-24 00:15:09 +00:00
|
|
|
if new_progress - old_progress >= 32:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__invalidate_offscreen(old_progress, new_progress)
|
2012-09-24 00:15:09 +00:00
|
|
|
self.__dist_sentinel_progress = new_progress
|
2007-11-22 07:31:37 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __handle_sentinel_finished(self, sentinel):
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if sentinel == self.process.freq_sentinel:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__invalidate_offscreen(0, -1)
|
2012-09-24 00:15:09 +00:00
|
|
|
else:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__invalidate_offscreen(self.__dist_sentinel_progress, -1)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __ensure_offscreen(self):
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
alloc = self.get_allocation()
|
2015-10-20 13:21:01 +00:00
|
|
|
if self.__offscreen_size == (alloc.width, alloc.height):
|
2012-09-24 00:15:09 +00:00
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__offscreen = cairo.ImageSurface(
|
|
|
|
cairo.FORMAT_ARGB32, alloc.width, alloc.height)
|
2015-10-20 13:21:01 +00:00
|
|
|
self.__offscreen_size = (alloc.width, alloc.height)
|
|
|
|
self.__offscreen_dirty = (0, alloc.width)
|
2007-11-26 14:52:21 +00:00
|
|
|
if not self.__offscreen:
|
2011-09-09 19:47:16 +00:00
|
|
|
self.__offscreen_size = (0, 0)
|
2016-09-28 18:38:55 +00:00
|
|
|
raise ValueError("could not obtain offscreen image surface")
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __invalidate_offscreen(self, start, stop):
|
2012-09-21 22:33:41 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
alloc = self.get_allocation()
|
2012-09-24 00:15:09 +00:00
|
|
|
if stop < 0:
|
2015-10-20 13:21:01 +00:00
|
|
|
stop += alloc.width
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2012-09-24 00:15:09 +00:00
|
|
|
dirty_start, dirty_stop = self.__offscreen_dirty
|
|
|
|
if dirty_start != dirty_stop:
|
2016-09-28 18:38:55 +00:00
|
|
|
dirty_start = min(dirty_start, start)
|
|
|
|
dirty_stop = max(dirty_stop, stop)
|
2012-09-24 00:15:09 +00:00
|
|
|
else:
|
|
|
|
dirty_start = start
|
|
|
|
dirty_stop = stop
|
|
|
|
self.__offscreen_dirty = (dirty_start, dirty_stop)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2012-09-24 00:15:09 +00:00
|
|
|
# Just like in __draw_offscreen. FIXME: Need this in one place!
|
|
|
|
start -= 8
|
|
|
|
stop += 8
|
2016-09-28 18:38:55 +00:00
|
|
|
self.queue_draw_area(start, 0, stop - start, alloc.height)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __draw_from_offscreen(self, ctx):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
if not self.props.visible:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
alloc = self.get_allocation()
|
2012-09-21 22:33:41 +00:00
|
|
|
offscreen_width, offscreen_height = self.__offscreen_size
|
2016-09-28 18:38:55 +00:00
|
|
|
rect = Gdk.Rectangle() # TODO: damage region
|
2015-10-21 13:03:03 +00:00
|
|
|
rect.x, rect.y, rect.width, rect.height = 0, 0, alloc.width, alloc.height
|
2011-09-09 19:47:16 +00:00
|
|
|
|
|
|
|
# Fill the background (where the offscreen pixmap doesn't fit) with
|
|
|
|
# white. This happens after enlarging the window, until all sentinels
|
|
|
|
# have finished running.
|
2015-10-20 13:21:01 +00:00
|
|
|
if offscreen_width < alloc.width or offscreen_height < alloc.height:
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.rectangle(rect.x, rect.y, rect.width, rect.height)
|
|
|
|
ctx.clip()
|
2011-09-09 19:47:16 +00:00
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
if offscreen_width < alloc.width:
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.rectangle(
|
|
|
|
offscreen_width, 0, alloc.width, offscreen_height)
|
2015-10-20 13:21:01 +00:00
|
|
|
if offscreen_height < alloc.height:
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.new_path()
|
|
|
|
ctx.rectangle(0, offscreen_height, alloc.width, alloc.height)
|
2011-09-09 19:47:16 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_line_width(0.)
|
|
|
|
ctx.set_source_rgb(1., 1., 1.)
|
|
|
|
ctx.fill()
|
2011-09-09 19:47:16 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_surface(self.__offscreen)
|
|
|
|
ctx.rectangle(rect.x, rect.y, rect.width, rect.height)
|
|
|
|
ctx.paint()
|
2016-09-28 18:34:53 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__draw_position(ctx, clip=rect)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def update(self, model):
|
2007-11-22 14:06:55 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.clear()
|
2007-11-22 14:06:55 +00:00
|
|
|
self.model = model
|
2007-11-22 08:29:23 +00:00
|
|
|
|
2012-08-27 20:45:57 +00:00
|
|
|
if model is not None:
|
2012-09-24 00:15:09 +00:00
|
|
|
self.__dist_sentinel_progress = 0
|
2016-09-28 18:38:55 +00:00
|
|
|
self.process.freq_sentinel = LineFrequencySentinel(model)
|
|
|
|
self.process.dist_sentinel = LevelDistributionSentinel(
|
|
|
|
self.process.freq_sentinel, model)
|
|
|
|
width = self.get_allocation().width
|
|
|
|
self.process.freq_sentinel.run_for(width)
|
|
|
|
self.process.run()
|
2007-11-22 14:06:55 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def clear(self):
|
2007-11-22 14:06:55 +00:00
|
|
|
|
2012-08-27 20:46:14 +00:00
|
|
|
self.model = None
|
2016-09-28 18:38:55 +00:00
|
|
|
self.process.abort()
|
2007-11-22 14:06:55 +00:00
|
|
|
self.process.freq_sentinel = None
|
|
|
|
self.process.dist_sentinel = None
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__invalidate_offscreen(0, -1)
|
2007-11-22 08:29:23 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def update_position(self, start_ts, end_ts):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.process.freq_sentinel:
|
|
|
|
return
|
|
|
|
|
|
|
|
if not self.process.freq_sentinel.data:
|
2007-11-21 15:40:31 +00:00
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
alloc = self.get_allocation()
|
2012-09-21 23:27:37 +00:00
|
|
|
|
|
|
|
# Queue old position rectangle for redraw:
|
|
|
|
if self.__position_ts_range is not None:
|
2016-09-28 18:38:55 +00:00
|
|
|
start, stop = self.ts_range_to_position(*self.__position_ts_range)
|
|
|
|
self.queue_draw_area(start - 1, 0, stop - start + 2, alloc.height)
|
2012-09-21 23:27:37 +00:00
|
|
|
# And the new one:
|
2016-09-28 18:38:55 +00:00
|
|
|
start, stop = self.ts_range_to_position(start_ts, end_ts)
|
|
|
|
self.queue_draw_area(start - 1, 0, stop - start + 2, alloc.height)
|
2012-09-21 23:27:37 +00:00
|
|
|
|
|
|
|
self.__position_ts_range = (start_ts, end_ts,)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def find_indicative_time_step(self):
|
2007-11-14 18:35:18 +00:00
|
|
|
|
|
|
|
MINIMUM_PIXEL_STEP = 32
|
2007-11-22 14:06:55 +00:00
|
|
|
time_per_pixel = self.process.freq_sentinel.step
|
2016-09-28 18:38:55 +00:00
|
|
|
return 32 # FIXME use self.freq_sentinel.step and len (self.process.freq_sentinel.data)
|
2007-11-14 18:35:18 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __draw_offscreen(self):
|
2011-09-09 19:47:16 +00:00
|
|
|
|
2012-09-24 00:15:09 +00:00
|
|
|
dirty_start, dirty_stop = self.__offscreen_dirty
|
|
|
|
if dirty_start == dirty_stop:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.__offscreen_dirty = (0, 0)
|
2012-09-21 22:33:41 +00:00
|
|
|
width, height = self.__offscreen_size
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx = cairo.Context(self.__offscreen)
|
2007-11-22 08:19:36 +00:00
|
|
|
|
2012-09-24 00:15:09 +00:00
|
|
|
# Indicator (triangle) size is 8, so we need to draw surrounding areas
|
|
|
|
# a bit:
|
|
|
|
dirty_start -= 8
|
|
|
|
dirty_stop += 8
|
2016-09-28 18:38:55 +00:00
|
|
|
dirty_start = max(dirty_start, 0)
|
|
|
|
dirty_stop = min(dirty_stop, width)
|
2012-09-24 00:15:09 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.rectangle(dirty_start, 0., dirty_stop, height)
|
|
|
|
ctx.clip()
|
2012-09-24 00:15:09 +00:00
|
|
|
|
2007-11-22 08:19:36 +00:00
|
|
|
# White background rectangle.
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_line_width(0.)
|
|
|
|
ctx.rectangle(0, 0, width, height)
|
|
|
|
ctx.set_source_rgb(1., 1., 1.)
|
|
|
|
ctx.fill()
|
|
|
|
ctx.new_path()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 08:19:36 +00:00
|
|
|
# Horizontal reference lines.
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_line_width(1.)
|
|
|
|
ctx.set_source_rgb(.95, .95, .95)
|
|
|
|
for i in range(height // 16):
|
2007-11-14 13:49:03 +00:00
|
|
|
y = i * 16 - .5
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.move_to(0, y)
|
|
|
|
ctx.line_to(width, y)
|
|
|
|
ctx.stroke()
|
2007-11-14 13:49:03 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if self.process.freq_sentinel is None:
|
|
|
|
return
|
|
|
|
|
2007-11-22 08:19:36 +00:00
|
|
|
# Vertical reference lines.
|
2016-09-28 18:38:55 +00:00
|
|
|
pixel_step = self.find_indicative_time_step()
|
|
|
|
ctx.set_source_rgb(.9, .9, .9)
|
2012-09-24 00:15:09 +00:00
|
|
|
start = dirty_start - dirty_start % pixel_step
|
2018-04-14 13:22:11 +00:00
|
|
|
for x in range(start + pixel_step, dirty_stop, pixel_step):
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.move_to(x - .5, 0)
|
|
|
|
ctx.line_to(x - .5, height)
|
|
|
|
ctx.stroke()
|
2007-11-14 18:35:18 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.process.freq_sentinel.data:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("frequency sentinel has no data yet")
|
2007-11-14 08:30:19 +00:00
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.translate(dirty_start, 0.)
|
2012-09-24 00:15:09 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
maximum = max(self.process.freq_sentinel.data)
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(0., 0., 0.)
|
2012-09-24 00:15:09 +00:00
|
|
|
data = self.process.freq_sentinel.data[dirty_start:dirty_stop]
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__draw_graph(ctx, height, maximum, data)
|
2007-11-21 15:40:31 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.process.dist_sentinel.data:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("level distribution sentinel has no data yet")
|
2007-11-21 15:40:31 +00:00
|
|
|
return
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
colors = LevelColorThemeTango().colors
|
2012-09-24 00:15:09 +00:00
|
|
|
dist_data = self.process.dist_sentinel.data[dirty_start:dirty_stop]
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def cumulative_level_counts(*levels):
|
2007-11-19 08:59:52 +00:00
|
|
|
for level_counts in dist_data:
|
2016-09-28 18:38:55 +00:00
|
|
|
yield sum((level_counts[level] for level in levels))
|
2007-11-19 08:59:52 +00:00
|
|
|
|
|
|
|
level = Data.debug_level_info
|
2011-11-06 11:49:43 +00:00
|
|
|
levels_prev = (Data.debug_level_trace,
|
|
|
|
Data.debug_level_fixme,
|
|
|
|
Data.debug_level_log,
|
|
|
|
Data.debug_level_debug,)
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*(colors[level][1].float_tuple()))
|
|
|
|
self.__draw_graph(ctx, height, maximum,
|
|
|
|
list(cumulative_level_counts(level, *levels_prev)))
|
2007-11-19 08:59:52 +00:00
|
|
|
|
2007-11-16 13:06:59 +00:00
|
|
|
level = Data.debug_level_debug
|
2011-11-06 11:49:43 +00:00
|
|
|
levels_prev = (Data.debug_level_trace,
|
|
|
|
Data.debug_level_fixme,
|
|
|
|
Data.debug_level_log,)
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*(colors[level][1].float_tuple()))
|
|
|
|
self.__draw_graph(ctx, height, maximum,
|
|
|
|
list(cumulative_level_counts(level, *levels_prev)))
|
2007-11-16 13:06:59 +00:00
|
|
|
|
|
|
|
level = Data.debug_level_log
|
2016-09-28 18:38:55 +00:00
|
|
|
levels_prev = (Data.debug_level_trace, Data.debug_level_fixme,)
|
|
|
|
ctx.set_source_rgb(*(colors[level][1].float_tuple()))
|
|
|
|
self.__draw_graph(ctx, height, maximum,
|
|
|
|
list(cumulative_level_counts(level, *levels_prev)))
|
2010-07-06 08:42:08 +00:00
|
|
|
|
|
|
|
level = Data.debug_level_fixme
|
|
|
|
levels_prev = (Data.debug_level_trace,)
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*(colors[level][1].float_tuple()))
|
|
|
|
self.__draw_graph(ctx, height, maximum,
|
|
|
|
list(cumulative_level_counts(level, *levels_prev)))
|
2010-07-06 08:42:08 +00:00
|
|
|
|
|
|
|
level = Data.debug_level_trace
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*(colors[level][1].float_tuple()))
|
|
|
|
self.__draw_graph(ctx, height, maximum, [
|
|
|
|
counts[level] for counts in dist_data])
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-19 08:59:52 +00:00
|
|
|
# Draw error and warning triangle indicators:
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def triangle(ctx, size=8):
|
|
|
|
ctx.move_to(-size // 2, 0)
|
|
|
|
ctx.line_to((size + 1) // 2, 0)
|
|
|
|
ctx.line_to(0, size / 1.41)
|
|
|
|
ctx.close_path()
|
2007-12-07 12:10:03 +00:00
|
|
|
|
2007-11-16 13:56:57 +00:00
|
|
|
for level in (Data.debug_level_warning, Data.debug_level_error,):
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(*(colors[level][1].float_tuple()))
|
|
|
|
for i, counts in enumerate(dist_data):
|
2007-11-16 13:56:57 +00:00
|
|
|
if counts[level] == 0:
|
|
|
|
continue
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.translate(i, 0.)
|
|
|
|
triangle(ctx)
|
|
|
|
ctx.fill()
|
|
|
|
ctx.translate(-i, 0.)
|
2007-11-16 13:56:57 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __draw_graph(self, ctx, height, maximum, data):
|
2007-11-16 13:06:59 +00:00
|
|
|
|
2007-11-16 15:25:08 +00:00
|
|
|
if not data:
|
|
|
|
return
|
|
|
|
|
2018-03-13 12:48:00 +00:00
|
|
|
if maximum:
|
|
|
|
heights = [height * float(d) / maximum for d in data]
|
|
|
|
else:
|
|
|
|
heights = [0. for d in data]
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.move_to(0, height)
|
|
|
|
for i in range(len(heights)):
|
|
|
|
ctx.line_to(i - .5, height - heights[i] + .5)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.line_to(i, height)
|
|
|
|
ctx.close_path()
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.fill()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __have_position(self):
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2012-09-24 00:23:22 +00:00
|
|
|
if ((self.process is not None) and
|
2007-11-26 14:52:21 +00:00
|
|
|
(self.process.freq_sentinel is not None) and
|
2016-09-28 18:38:55 +00:00
|
|
|
(self.process.freq_sentinel.ts_range is not None)):
|
2007-11-26 14:52:21 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def ts_range_to_position(self, start_ts, end_ts):
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if not self.__have_position():
|
2012-09-21 23:27:37 +00:00
|
|
|
return (0, 0)
|
2007-11-26 14:52:21 +00:00
|
|
|
|
|
|
|
first_ts, last_ts = self.process.freq_sentinel.ts_range
|
|
|
|
step = self.process.freq_sentinel.step
|
2007-11-29 13:11:40 +00:00
|
|
|
if step == 0:
|
2012-09-21 23:27:37 +00:00
|
|
|
return (0, 0)
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
position1 = int(float(start_ts - first_ts) / step)
|
|
|
|
position2 = int(float(end_ts - first_ts) / step)
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2012-09-21 23:27:37 +00:00
|
|
|
return (position1, position2)
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __draw_position(self, ctx, clip=None):
|
2012-09-21 23:27:37 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if not self.__have_position() or self.__position_ts_range is None:
|
|
|
|
if not self.__have_position():
|
|
|
|
self.logger.debug("have no positions")
|
2015-10-21 13:03:03 +00:00
|
|
|
else:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("have no positions_ts_range")
|
2012-09-21 23:27:37 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
start_ts, end_ts = self.__position_ts_range
|
2016-09-28 18:38:55 +00:00
|
|
|
position1, position2 = self.ts_range_to_position(start_ts, end_ts)
|
2012-09-21 23:27:37 +00:00
|
|
|
|
2008-01-25 10:40:51 +00:00
|
|
|
if clip:
|
2015-10-21 13:03:03 +00:00
|
|
|
if clip.x + clip.width < position1 - 1 or clip.x > position2 + 1:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug(
|
|
|
|
"outside of clip range: %d + %d, pos: %d, %d", clip.x, clip.width, position1, position2)
|
2008-01-25 10:40:51 +00:00
|
|
|
return
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.rectangle(clip.x, clip.y, clip.width, clip.height)
|
|
|
|
ctx.clip()
|
2008-01-25 10:40:51 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
height = self.get_allocation().height
|
2007-11-26 14:52:21 +00:00
|
|
|
|
|
|
|
line_width = position2 - position1
|
|
|
|
if line_width <= 1:
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgb(1., 0., 0.)
|
|
|
|
ctx.set_line_width(1.)
|
|
|
|
ctx.move_to(position1 + .5, 0)
|
|
|
|
ctx.line_to(position1 + .5, height)
|
|
|
|
ctx.stroke()
|
2007-11-26 14:52:21 +00:00
|
|
|
else:
|
2016-09-28 18:38:55 +00:00
|
|
|
ctx.set_source_rgba(1., 0., 0., .5)
|
|
|
|
ctx.rectangle(position1, 0, line_width, height)
|
|
|
|
ctx.fill()
|
2007-11-26 14:52:21 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_draw(self, cr):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.__ensure_offscreen()
|
|
|
|
self.__draw_offscreen()
|
|
|
|
self.__draw_from_offscreen(cr)
|
2012-09-21 22:33:41 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
return True
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_configure_event(self, event):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger.debug("widget size configured to %ix%i",
|
|
|
|
event.width, event.height)
|
2007-11-16 15:25:08 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
if event.width < 16:
|
2007-11-16 15:25:08 +00:00
|
|
|
return False
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.update(self.model)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_get_preferred_height(self):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
return 64, 64 # FIXME:
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_button_press_event(self, event):
|
2012-09-20 18:11:48 +00:00
|
|
|
|
|
|
|
if event.button != 1:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# TODO: Check if clicked inside a warning/error indicator triangle and
|
|
|
|
# navigate there.
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if not self.has_grab():
|
|
|
|
self.grab_add()
|
2012-09-26 00:28:00 +00:00
|
|
|
self.props.has_tooltip = False
|
2012-09-20 18:20:58 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
pos = int(event.x)
|
|
|
|
self.emit("change-position", pos)
|
2012-09-20 18:11:48 +00:00
|
|
|
return True
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_button_release_event(self, event):
|
2012-09-20 18:20:58 +00:00
|
|
|
|
|
|
|
if event.button != 1:
|
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
if self.has_grab():
|
|
|
|
self.grab_remove()
|
2012-09-26 00:28:00 +00:00
|
|
|
self.props.has_tooltip = True
|
2012-09-20 18:20:58 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def do_motion_notify_event(self, event):
|
2012-09-20 18:11:48 +00:00
|
|
|
|
2015-10-20 13:21:01 +00:00
|
|
|
if event.get_state() & Gdk.ModifierType.BUTTON1_MASK:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.emit("change-position", int(event.x))
|
|
|
|
Gdk.event_request_motions(event)
|
2012-09-20 18:11:48 +00:00
|
|
|
return True
|
|
|
|
else:
|
2016-09-28 18:38:55 +00:00
|
|
|
self._handle_motion(event.x, event.y)
|
|
|
|
Gdk.event_request_motions(event)
|
2012-09-20 18:11:48 +00:00
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def _handle_motion(self, x, y):
|
2012-09-20 18:11:48 +00:00
|
|
|
|
|
|
|
# TODO: Prelight warning and error indicator triangles.
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2008-01-24 09:47:27 +00:00
|
|
|
class AttachedWindow (object):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, feature, window):
|
2007-11-26 12:42:46 +00:00
|
|
|
|
2008-01-24 09:47:27 +00:00
|
|
|
self.window = window
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
ui = window.ui_manager
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ui.insert_action_group(feature.action_group, 0)
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.merge_id = ui.new_merge_id()
|
|
|
|
ui.add_ui(self.merge_id, "/menubar/ViewMenu/ViewMenuAdditions",
|
|
|
|
"ViewTimeline", "show-timeline",
|
|
|
|
Gtk.UIManagerItemType.MENUITEM, False)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
ui.add_ui(self.merge_id, "/", "TimelineContextMenu", None,
|
|
|
|
Gtk.UIManagerItemType.POPUP, False)
|
2007-12-07 09:25:30 +00:00
|
|
|
# TODO: Make hide before/after operate on the partition that the mouse
|
|
|
|
# is pointed at instead of the currently selected line.
|
2012-09-20 22:40:07 +00:00
|
|
|
# ui.add_ui (self.merge_id, "/TimelineContextMenu", "TimelineHideLinesBefore",
|
2015-10-20 13:21:01 +00:00
|
|
|
# "hide-before-line", Gtk.UIManagerItemType.MENUITEM, False)
|
2012-09-20 22:40:07 +00:00
|
|
|
# ui.add_ui (self.merge_id, "/TimelineContextMenu", "TimelineHideLinesAfter",
|
2015-10-20 13:21:01 +00:00
|
|
|
# "hide-after-line", Gtk.UIManagerItemType.MENUITEM, False)
|
2016-09-28 18:38:55 +00:00
|
|
|
ui.add_ui(
|
|
|
|
self.merge_id, "/TimelineContextMenu", "TimelineShowHiddenLines",
|
|
|
|
"show-hidden-lines", Gtk.UIManagerItemType.MENUITEM, False)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
box = window.get_top_attach_point()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline = TimelineWidget()
|
|
|
|
self.timeline.connect("change-position",
|
|
|
|
self.handle_timeline_change_position)
|
|
|
|
box.pack_start(self.timeline, False, False, 0)
|
|
|
|
self.timeline.hide()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.popup = ui.get_widget("/TimelineContextMenu")
|
|
|
|
Common.GUI.widget_add_popup_menu(self.timeline, self.popup)
|
2007-12-07 14:24:01 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
box = window.get_side_attach_point()
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.vtimeline = VerticalTimelineWidget(self.window.log_view)
|
|
|
|
box.pack_start(self.vtimeline, False, False, 0)
|
|
|
|
self.vtimeline.hide()
|
2007-11-23 09:46:43 +00:00
|
|
|
|
2008-01-24 09:12:05 +00:00
|
|
|
handler = self.handle_log_view_adjustment_value_changed
|
|
|
|
adjustment = window.widgets.log_view_scrolled_window.props.vadjustment
|
2016-09-28 18:38:55 +00:00
|
|
|
adjustment.connect("value-changed", handler)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
handler = self.handle_show_action_toggled
|
2016-09-28 18:38:55 +00:00
|
|
|
action = feature.action_group.get_action("show-timeline")
|
|
|
|
action.connect("toggled", handler)
|
|
|
|
handler(action)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-27 14:50:41 +00:00
|
|
|
handler = self.handle_log_view_notify_model
|
2016-09-28 18:38:55 +00:00
|
|
|
self.notify_model_id = window.log_view.connect(
|
|
|
|
"notify::model", handler)
|
2007-11-27 14:50:41 +00:00
|
|
|
|
2011-09-06 20:27:33 +00:00
|
|
|
self.idle_scroll_path = None
|
|
|
|
self.idle_scroll_id = None
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def detach(self, feature):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.window.log_view.disconnect(self.notify_model_id)
|
2008-01-24 09:47:27 +00:00
|
|
|
self.notify_model_id = None
|
2007-11-27 14:50:41 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.window.ui_manager.remove_ui(self.merge_id)
|
2007-11-14 08:30:19 +00:00
|
|
|
self.merge_id = None
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.window.ui_manager.remove_action_group(feature.action_group)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.destroy()
|
2007-11-17 08:06:09 +00:00
|
|
|
self.timeline = None
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2011-09-06 20:27:33 +00:00
|
|
|
self.idle_scroll_path = None
|
|
|
|
if self.idle_scroll_id is not None:
|
2016-09-28 18:38:55 +00:00
|
|
|
GObject.source_remove(self.idle_scroll_id)
|
2011-09-06 20:27:33 +00:00
|
|
|
self.idle_scroll_id = None
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_detach_log_file(self, log_file):
|
2007-11-27 14:50:41 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.clear()
|
|
|
|
self.vtimeline.clear()
|
2007-11-27 14:50:41 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_log_view_notify_model(self, view, gparam):
|
2007-11-27 14:50:41 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
model = view.get_model()
|
2007-11-27 14:50:41 +00:00
|
|
|
|
|
|
|
if model is None:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.clear()
|
|
|
|
self.vtimeline.clear()
|
2007-11-27 14:50:41 +00:00
|
|
|
return
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.update(model)
|
2007-11-26 14:52:21 +00:00
|
|
|
|
|
|
|
# Need to dispatch these idly with a low priority to avoid triggering a
|
|
|
|
# warning in treeview.get_visible_range:
|
2016-09-28 18:38:55 +00:00
|
|
|
def idle_update():
|
|
|
|
self.update_timeline_position()
|
|
|
|
self.vtimeline.update()
|
2007-11-26 14:52:21 +00:00
|
|
|
return False
|
2016-09-28 18:38:55 +00:00
|
|
|
GObject.idle_add(idle_update, priority=GObject.PRIORITY_LOW)
|
2007-11-22 14:06:55 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_log_view_adjustment_value_changed(self, adj):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
|
|
|
# FIXME: If not visible, disconnect this handler!
|
|
|
|
if not self.timeline.props.visible:
|
|
|
|
return
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.update_timeline_position()
|
|
|
|
self.vtimeline.update()
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def update_timeline_position(self):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-10-10 13:59:49 +00:00
|
|
|
visible_range = self.window.get_range()
|
2007-11-29 12:29:10 +00:00
|
|
|
if visible_range is None:
|
|
|
|
return
|
2016-10-10 13:59:49 +00:00
|
|
|
ts1, ts2 = visible_range
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.update_position(ts1, ts2)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_show_action_toggled(self, action):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
|
|
|
show = action.props.active
|
|
|
|
|
|
|
|
if show:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.show()
|
|
|
|
self.vtimeline.show()
|
2007-11-14 08:30:19 +00:00
|
|
|
else:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.timeline.hide()
|
|
|
|
self.vtimeline.hide()
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_timeline_change_position(self, widget, pos):
|
2007-12-07 12:10:03 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.goto_time_position(pos)
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def goto_time_position(self, pos):
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-22 14:06:55 +00:00
|
|
|
if not self.timeline.process.freq_sentinel:
|
|
|
|
return True
|
|
|
|
|
|
|
|
data = self.timeline.process.freq_sentinel.data
|
2007-11-14 08:30:19 +00:00
|
|
|
if not data:
|
|
|
|
return True
|
2007-11-22 09:03:09 +00:00
|
|
|
|
|
|
|
if pos < 0:
|
|
|
|
pos = 0
|
2016-09-28 18:38:55 +00:00
|
|
|
elif pos >= len(data):
|
|
|
|
pos = len(data) - 1
|
2007-11-22 09:03:09 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
count = sum(data[:pos + 1])
|
2007-11-14 08:30:19 +00:00
|
|
|
|
2007-11-29 09:19:00 +00:00
|
|
|
path = (count,)
|
2011-09-06 20:27:33 +00:00
|
|
|
self.idle_scroll_path = path
|
|
|
|
|
|
|
|
if self.idle_scroll_id is None:
|
2016-09-28 18:38:55 +00:00
|
|
|
self.idle_scroll_id = GObject.idle_add(self.idle_scroll)
|
2011-09-06 20:27:33 +00:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def idle_scroll(self):
|
2011-09-06 20:27:33 +00:00
|
|
|
|
|
|
|
self.idle_scroll_id = None
|
|
|
|
|
|
|
|
if self.idle_scroll_path is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
path = self.idle_scroll_path
|
|
|
|
self.idle_scroll_path = None
|
|
|
|
|
|
|
|
view = self.window.log_view
|
2016-09-28 18:38:55 +00:00
|
|
|
view.scroll_to_cell(path, use_align=True, row_align=.5)
|
2009-03-14 21:02:45 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
return False
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
|
2008-01-24 09:47:27 +00:00
|
|
|
class TimelineFeature (FeatureBase):
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, app):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.logger = logging.getLogger("ui.timeline")
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.action_group = Gtk.ActionGroup("TimelineActions")
|
|
|
|
self.action_group.add_toggle_actions([("show-timeline",
|
2018-04-18 12:03:01 +00:00
|
|
|
None, _("_Timeline"),
|
|
|
|
"<Ctrl>t")])
|
2008-01-24 09:47:27 +00:00
|
|
|
|
|
|
|
self.state = app.state.sections[TimelineState._name]
|
|
|
|
|
|
|
|
self.attached_windows = {}
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
action = self.action_group.get_action("show-timeline")
|
2008-01-24 09:47:27 +00:00
|
|
|
action.props.active = self.state.shown
|
2016-09-30 20:29:43 +00:00
|
|
|
action.connect("toggled", self.handle_show_action_toggled)
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_show_action_toggled(self, action):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-30 20:29:43 +00:00
|
|
|
self.state.shown = action.props.active
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_attach_window(self, window):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
self.attached_windows[window] = AttachedWindow(self, window)
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_detach_window(self, window):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
attached_window = self.attached_windows.pop(window)
|
|
|
|
attached_window.detach(self)
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_attach_log_file(self, window, log_file):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
|
|
|
pass
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def handle_detach_log_file(self, window, log_file):
|
2008-01-24 09:47:27 +00:00
|
|
|
|
|
|
|
attached_window = self.attached_windows[window]
|
2016-09-28 18:38:55 +00:00
|
|
|
attached_window.handle_detach_log_file(log_file)
|
|
|
|
|
2008-01-24 09:47:27 +00:00
|
|
|
|
|
|
|
class TimelineState (Common.GUI.StateSection):
|
|
|
|
|
|
|
|
_name = "timeline"
|
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
shown = Common.GUI.StateBool("shown", default=True)
|
|
|
|
|
2008-01-24 09:47:27 +00:00
|
|
|
|
2007-11-14 08:30:19 +00:00
|
|
|
class Plugin (PluginBase):
|
|
|
|
|
2016-09-28 19:19:29 +00:00
|
|
|
features = (TimelineFeature,)
|
2007-11-26 12:42:46 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
def __init__(self, app):
|
2007-11-26 12:42:46 +00:00
|
|
|
|
2016-09-28 18:38:55 +00:00
|
|
|
app.state.add_section_class(TimelineState)
|
2007-11-26 12:42:46 +00:00
|
|
|
self.state = app.state.sections[TimelineState._name]
|