3 """Module managing the tree and all stuff around it
5 :author: Sébastien CHAZALLET <s.chazallet@gmail.com>
6 :organization: InsPyration EURL
7 :copyright: Copyright © InsPyration EURL <www.inspyration.org>
8 :license: GPL 3 <http://www.gnu.org/licenses/gpl.html>
14 from gettext import gettext as _
16 from gi.repository import Gtk
18 SP_COL_TITLES = (_("Code"), _("L"), _("C"), _("Errors / Warnings"))
19 SP_COL_TYPES = (str, int, int, str)
21 PYTHON_ICON = 'gnome-mime-text-x-python'
24 class GeditFlake8Tree(Gtk.TreeView):
25 """Tree inside gedit side panel containing all flake8 warnings"""
27 def __init__(self, window):
28 """Configure tree columns, tree selection and add it to side panel
30 :type self: GeditFlake8Tree
31 :param self: Current tree
32 :type window: Gedit.Window
33 :param window: GEdit window object
38 # use a list store to manage warnings
39 Gtk.TreeView.__init__(self, Gtk.ListStore(*SP_COL_TYPES))
45 for index, title in enumerate(SP_COL_TITLES):
46 self.append_column(Gtk.TreeViewColumn(
48 Gtk.CellRendererText(),
51 # Allow to do something when a tree line is selected
52 self.get_selection().connect("changed", self.on_tree_selection)
54 # create an icon for the side panel
56 image.set_from_icon_name(PYTHON_ICON, Gtk.IconSize.MENU)
58 # get the side panel (created by GEdit)
59 sp = self.window.get_side_panel()
61 # Add the tree in the side panel
69 # set the side panel invisible
70 sp.set_property("visible", False)
73 """remove the tree from the side panel
75 :type self: GeditFlake8Tree
76 :param self: Current tree
81 # get the side panel (created by GEdit)
82 sp = self.window.get_side_panel()
86 """show the tree in the side panel
88 :type self: GeditFlake8Tree
89 :param self: Current tree
94 sp = self.window.get_side_panel()
95 sp.set_property("visible", True)
96 sp.activate_item(self)
98 def on_tree_selection(self, selection):
99 """When a tree line is selected, go to the file linked line
101 :type self: GeditFlake8Tree
102 :param self: Current tree
103 :type selection: Gtk.TreeSelection
104 :param selection: Current selection
109 doc = self.window.get_active_document()
113 # get the tree line selected and put the cursor to the file linked line
114 model, treeiter = selection.get_selected()
115 doc.goto_line(model[treeiter][1] - 1)
117 # scroll the view to the cursor
118 self.window.get_active_view().scroll_to_cursor()
120 def update_model(self, datas):
121 """Update the tree with new datas
123 :type self: GeditFlake8Tree
124 :param self: Current tree
126 :param datas: list of ready to use (str, int, int, str) tuples
131 # get the model (Gtk.ListStore)
132 model = self.get_model()
137 # Fill model with new values