mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
Colorize vertical timeline lines to indicate different threads
This commit is contained in:
parent
44376b41d1
commit
df96f4064c
2 changed files with 120 additions and 13 deletions
|
@ -43,6 +43,77 @@ import gtk.glade
|
|||
|
||||
from GstDebugViewer import Common, Data, Main
|
||||
|
||||
class Color (object):
|
||||
|
||||
def __init__ (self, hex_24):
|
||||
|
||||
if hex_24.startswith ("#"):
|
||||
s = hex_24[1:]
|
||||
else:
|
||||
s = hex_24
|
||||
|
||||
self._fields = tuple ((int (hs, 16) for hs in (s[:2], s[2:4], s[4:],)))
|
||||
|
||||
def hex_string (self):
|
||||
|
||||
return "#%02x%02x%02x" % self._fields
|
||||
|
||||
def float_tuple (self):
|
||||
|
||||
return tuple ((float (x) / 255 for x in self._fields))
|
||||
|
||||
def byte_tuple (self):
|
||||
|
||||
return self._fields
|
||||
|
||||
def short_tuple (self):
|
||||
|
||||
return tuple ((x << 8 for x in self._fields))
|
||||
|
||||
class ColorPalette (object):
|
||||
|
||||
@classmethod
|
||||
def get (cls):
|
||||
|
||||
try:
|
||||
return cls._instance
|
||||
except AttributeError:
|
||||
cls._instance = cls ()
|
||||
return cls._instance
|
||||
|
||||
class TangoPalette (ColorPalette):
|
||||
|
||||
def __init__ (self):
|
||||
|
||||
for name, r, g, b in [("butter1", 252, 233, 79),
|
||||
("butter2", 237, 212, 0),
|
||||
("butter3", 196, 160, 0),
|
||||
("chameleon1", 138, 226, 52),
|
||||
("chameleon2", 115, 210, 22),
|
||||
("chameleon3", 78, 154, 6),
|
||||
("orange1", 252, 175, 62),
|
||||
("orange2", 245, 121, 0),
|
||||
("orange3", 206, 92, 0),
|
||||
("skyblue1", 114, 159, 207),
|
||||
("skyblue2", 52, 101, 164),
|
||||
("skyblue3", 32, 74, 135),
|
||||
("plum1", 173, 127, 168),
|
||||
("plum2", 117, 80, 123),
|
||||
("plum3", 92, 53, 102),
|
||||
("chocolate1", 233, 185, 110),
|
||||
("chocolate2", 193, 125, 17),
|
||||
("chocolate3", 143, 89, 2),
|
||||
("scarletred1", 239, 41, 41),
|
||||
("scarletred2", 204, 0, 0),
|
||||
("scarletred3", 164, 0, 0),
|
||||
("aluminium1", 238, 238, 236),
|
||||
("aluminium2", 211, 215, 207),
|
||||
("aluminium3", 186, 189, 182),
|
||||
("aluminium4", 136, 138, 133),
|
||||
("aluminium5", 85, 87, 83),
|
||||
("aluminium6", 46, 52, 54)]:
|
||||
setattr (self, name, Color ("%02x%02x%02x" % (r, g, b,)))
|
||||
|
||||
class ColorTheme (object):
|
||||
|
||||
def __init__ (self):
|
||||
|
@ -53,6 +124,11 @@ class ColorTheme (object):
|
|||
|
||||
self.colors[key] = (fg_color, bg_color, bg_color2,)
|
||||
|
||||
def colors_float (self, key):
|
||||
|
||||
return tuple ((self.hex_string_to_floats (color)
|
||||
for color in self.colors[key]))
|
||||
|
||||
@staticmethod
|
||||
def hex_string_to_floats (s):
|
||||
|
||||
|
@ -60,11 +136,6 @@ class ColorTheme (object):
|
|||
s = s[1:]
|
||||
return tuple ((float (int (hs, 16)) / 255. for hs in (s[:2], s[2:4], s[4:],)))
|
||||
|
||||
def colors_float (self, key):
|
||||
|
||||
return tuple ((self.hex_string_to_floats (color)
|
||||
for color in self.colors[key]))
|
||||
|
||||
class LevelColorTheme (ColorTheme):
|
||||
|
||||
pass
|
||||
|
@ -82,6 +153,27 @@ class LevelColorThemeTango (LevelColorTheme):
|
|||
self.add_color (Data.debug_level_warning, "#000000", "#fcaf3e", "#ffc266")
|
||||
self.add_color (Data.debug_level_error, "#ffffff", "#ef2929", "#ff4545")
|
||||
|
||||
class ThreadColorTheme (ColorTheme):
|
||||
|
||||
pass
|
||||
|
||||
class ThreadColorThemeTango (ThreadColorTheme):
|
||||
|
||||
def __init__ (self):
|
||||
|
||||
ThreadColorTheme.__init__ (self)
|
||||
|
||||
t = TangoPalette.get ()
|
||||
for i, color in enumerate ([t.butter3,
|
||||
t.orange2,
|
||||
t.chocolate3,
|
||||
t.chameleon3,
|
||||
t.skyblue2,
|
||||
t.plum2,
|
||||
t.scarletred2,
|
||||
t.aluminium5]):
|
||||
self.add_color (i, color)
|
||||
|
||||
class LogModelBase (gtk.GenericTreeModel):
|
||||
|
||||
__metaclass__ = Common.GUI.MetaModel
|
||||
|
|
|
@ -243,7 +243,10 @@ class VerticalTimelineWidget (gtk.DrawingArea):
|
|||
|
||||
self.logger = logging.getLogger ("ui.vtimeline")
|
||||
|
||||
self.theme = GUI.ThreadColorThemeTango ()
|
||||
self.params = None
|
||||
self.thread_colors = {}
|
||||
self.next_thread_color = 0
|
||||
|
||||
self.connect ("expose-event", self.__handle_expose_event)
|
||||
self.connect ("size-request", self.__handle_size_request)
|
||||
|
@ -267,8 +270,8 @@ class VerticalTimelineWidget (gtk.DrawingArea):
|
|||
if self.params is None:
|
||||
return
|
||||
|
||||
first_y, cell_height, ts_list = self.params
|
||||
first_ts, last_ts = ts_list[0], ts_list[-1]
|
||||
first_y, cell_height, data = self.params
|
||||
first_ts, last_ts = data[0][0], data[-1][0]
|
||||
ts_range = last_ts - first_ts
|
||||
|
||||
if ts_range == 0:
|
||||
|
@ -278,7 +281,17 @@ class VerticalTimelineWidget (gtk.DrawingArea):
|
|||
ctx.set_source_rgb (0., 0., 0.)
|
||||
|
||||
first_y += cell_height // 2 - .5
|
||||
for i, ts in enumerate (ts_list):
|
||||
for i, i_data in enumerate (data):
|
||||
ts, thread = i_data
|
||||
if thread in self.thread_colors:
|
||||
ctx.set_source_rgb (*self.thread_colors[thread])
|
||||
else:
|
||||
self.next_thread_color += 1
|
||||
if self.next_thread_color == len (self.theme.colors):
|
||||
self.next_thread_color = 0
|
||||
color = self.theme.colors[self.next_thread_color][0].float_tuple ()
|
||||
self.thread_colors[thread] = color
|
||||
ctx.set_source_rgb (*color)
|
||||
ts_fraction = float (ts - first_ts) / ts_range
|
||||
ts_offset = ts_fraction * h
|
||||
row_offset = first_y + i * cell_height
|
||||
|
@ -295,14 +308,16 @@ class VerticalTimelineWidget (gtk.DrawingArea):
|
|||
def clear (self):
|
||||
|
||||
self.params = None
|
||||
self.thread_colors.clear ()
|
||||
self.next_thread_color = 0
|
||||
self.queue_draw ()
|
||||
|
||||
def update (self, first_y, cell_height, ts_list):
|
||||
def update (self, first_y, cell_height, data):
|
||||
|
||||
# FIXME: Ideally we should be informed of the vertical position
|
||||
# difference of the view (which is 0) with the current UI layout.
|
||||
|
||||
self.params = (first_y, cell_height, ts_list,)
|
||||
self.params = (first_y, cell_height, data,)
|
||||
self.queue_draw ()
|
||||
|
||||
class TimelineWidget (gtk.DrawingArea):
|
||||
|
@ -642,13 +657,13 @@ class TimelineFeature (FeatureBase):
|
|||
bg_rect = self.log_view.get_background_area (start_path, column)
|
||||
cell_height = bg_rect.height
|
||||
|
||||
ts_list = []
|
||||
data = []
|
||||
tree_iter = model.get_iter (start_path)
|
||||
while model.get_path (tree_iter) != end_path:
|
||||
ts_list.append (model.get_value (tree_iter, model.COL_TIME))
|
||||
data.append (model.get (tree_iter, model.COL_TIME, model.COL_THREAD))
|
||||
tree_iter = model.iter_next (tree_iter)
|
||||
|
||||
self.vtimeline.update (first_y, cell_height, ts_list)
|
||||
self.vtimeline.update (first_y, cell_height, data)
|
||||
|
||||
def handle_show_action_toggled (self, action):
|
||||
|
||||
|
|
Loading…
Reference in a new issue