Skip to content

Commit

Permalink
GUI: Add ResultView Prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Udayan12167 committed Jun 27, 2015
1 parent 07921ed commit c8befb3
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 29 deletions.
37 changes: 18 additions & 19 deletions .coafile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
# So all sections are disabled by default
Default.enabled = false
PythonCheck.enabled = true
DOCS.enabled = true

[Default]
[linecounting]
bears = LineCountBear
enabled = true
files = *.py, bears/**/*.py, coalib/**/*.py, ./coala

[PythonCheck]
[default]
enabled = false
files = *.py, bears/**/*.py, coalib/**/*.py, ./coala
[docs]
enabled = true
bears = SpaceConsistencyBear
files = doc/**/*.md
use_spaces = True
[pythoncheck]
enabled = true
bears = SpaceConsistencyBear, LineLengthBear
use_spaces = True
max_line_length = 80

[LineCounting]
bears = LineCountBear

[TODOS]
files = *.py, bears/**/*.py, coalib/**/*.py, ./coala
[todos]
bears = KeywordBear
ci_keywords = \#TODO, \# TODO, \#FIXME, \# FIXME
cs_keywords =
ci_keywords, cs_keywords = TODO, FIXME
enabled = true
files = *.py, bears/**/*.py, coalib/**/*.py, ./coala

[DOCS]
bears = SpaceConsistencyBear
files = doc/**/*.md
use_spaces = True
6 changes: 6 additions & 0 deletions coalib/results/Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def __lt__(self, other):
if self.file != other.file:
return self.file < other.file

if self.line_nr is None and other.line_nr is not None:
return True

if self.line_nr is not None and other.line_nr is None:
return False

# If we have a line result show results with a lesser line number first
if self.line_nr is not None and other.line_nr is not None:
if self.line_nr != other.line_nr:
Expand Down
Binary file modified gui/data/coala.gresource
Binary file not shown.
39 changes: 39 additions & 0 deletions gui/data/ui/coalaWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,45 @@
<property name="visible">true</property>
<property name="shadow_type">4</property>
</object>
<packing>
<property name="pack_type">start</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="border-width">5</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="vexpand">True</property>
<property name="hexpand">True</property>
<property name="border-width">5</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="hexpand">True</property>
<child>
<object class = "GtkGrid" id="sourceview">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
<packing>
Expand Down
2 changes: 1 addition & 1 deletion gui/main_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

if __name__ == '__main__':
app = coalaApp()
app.run(sys.argv)
app.run(sys.argv)
17 changes: 17 additions & 0 deletions gui/src/support/LineRenderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from gi.repository import Gtk
from gi.repository import GtkSource


class LineRenderer(GtkSource.GutterRendererText):
line_offset = 0

def __init__(self, start_line, *args, **kwargs):
self.line_offset = start_line
GtkSource.GutterRendererText.__init__(self, *args, **kwargs)

def do_query_data(self, start, end, flags):
self.props.text = str(start.get_line() + self.line_offset + 1)
label = Gtk.Label()
pango_layout = label.get_layout()
pango_layout.set_text(self.props.text, len(self.props.text))
self.props.size = pango_layout.get_pixel_size()[0]
44 changes: 44 additions & 0 deletions gui/src/support/RunCoala.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from coalib.settings.ConfigurationGathering import gather_configuration
from coalib.processes.Processing import execute_section
from coalib.output.NullInteractor import NullInteractor


def run_coala():
bear_results = {}
yielded_results = None
(sections,
local_bears,
global_bears,
targets,
interactor,
log_printer) = gather_configuration()

interactor = NullInteractor(log_printer)

for section_name in sections:
section = sections[section_name]
if not section.is_enabled(targets):
continue

interactor.begin_section(section)
results = execute_section(section=section,
global_bear_list=global_bears[section_name],
local_bear_list=local_bears[section_name],
print_results=interactor.print_results,
finalize=interactor.finalize,
log_printer=log_printer)
yielded_results = yielded_results or results[0]
for file, result_list in results[1].items():
if file in bear_results:
bear_results[file].extend(result_list)
else:
bear_results[file] = result_list

for bear, result_list in results[2].items():
for result in result_list:
if result.file in bear_results:
bear_results[result.file].append(result)
else:
bear_results[result.file] = [result]
return bear_results

5 changes: 4 additions & 1 deletion gui/src/support/WriteFile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
from coalib.output.ConfWriter import ConfWriter
from gui.src.support.RunCoala import run_coala

def write_to_file(sections_view):

def write_to_file_and_run(sections_view):
sections_dict = {}
confwriter = ConfWriter(".coafile")
for section_name, section_listore in sections_view.items():
Expand All @@ -14,3 +16,4 @@ def write_to_file(sections_view):
print(sections_dict)
confwriter.write_sections(sections_dict)
confwriter.close()
return run_coala()
1 change: 0 additions & 1 deletion gui/src/support/fileTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __init__(self, path):

treeviewcol = Gtk.TreeViewColumn("File")
colcelltext = Gtk.CellRendererText()
colcelltext.set_property("foreground", "red")
colcellimg = Gtk.CellRendererPixbuf()
treeviewcol.pack_start(colcellimg, False)
treeviewcol.pack_start(colcelltext, True)
Expand Down
113 changes: 106 additions & 7 deletions gui/src/workspace/coalaWindow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
from collections import OrderedDict
from gi.repository import Gtk
from gi.repository import GtkSource
from gi.repository import Gdk

from gui.src.support.fileTree import coalaFileTree
from gui.src.support.settingTree import coalaSettingTree
from coalib.settings.ConfigurationGathering import load_config_file
from gui.src.support.WriteFile import write_to_file
from gui.src.support.WriteFile import write_to_file_and_run
from gui.src.support.LineRenderer import LineRenderer


class coalaWindow(Gtk.ApplicationWindow):
Expand All @@ -19,6 +21,7 @@ def __init__(self, app, src):
os.chdir(self.path)
self.sections = {}
self.sections_view = {}
self.results = None

self._ui = Gtk.Builder()
self._ui.add_from_resource("/coala/coalaWindow.ui")
Expand Down Expand Up @@ -46,6 +49,11 @@ def __init__(self, app, src):
self.filetreecontainer = self._ui.get_object("filetree")
self.filetreecontainer.add(self.filetree.fileTreeView)
self.filetreecontainer.set_size_request(244, -1)
self.select = self.filetree.fileTreeView.get_selection()
self.select.connect("changed", self.on_file_tree_selection_changed)

self.source_view = self._ui.get_object("sourceview")
self.source_view_iter = 0

self.setup_config_file()

Expand All @@ -58,6 +66,7 @@ def setup_config_file(self):
coafile = open(".coafile", "w")
coafile.close()
self.setup_sections()
self.results = write_to_file_and_run(self.sections_view)

def setup_sections(self):
for key in self.sections:
Expand Down Expand Up @@ -109,7 +118,6 @@ def add_section(self, section):
str(self.sections[section][key])])
self.section_stack.add_titled(frame, section, section)
self.section_stack_switcher.queue_draw()
write_to_file(self.sections_view)

def del_setting(self, button):
section = self.section_stack.get_visible_child()
Expand All @@ -119,18 +127,109 @@ def del_setting(self, button):
if result:
model, iter = result
model.remove(iter)
write_to_file(self.sections_view)
self.results = write_to_file_and_run(self.sections_view)

def add_setting(self, button):
section = self.section_stack.get_visible_child()
settings = self.sections_view[section.get_name()]
settings.append(["Entry", "Value"])
write_to_file(self.sections_view)
self.results = write_to_file_and_run(self.sections_view)

def text_edited_column1(self, widget, path, text, liststore):
liststore[path][0] = text
write_to_file(self.sections_view)
self.results = write_to_file_and_run(self.sections_view)

def text_edited_column2(self, widget, path, text, liststore):
liststore[path][1] = text
write_to_file(self.sections_view)
self.results = write_to_file_and_run(self.sections_view)

def on_file_tree_selection_changed(self, selection):
model, treeiter = selection.get_selected()
if treeiter != None:
if os.path.isdir(model[treeiter][2]):
print("You selected", model[treeiter][0], model[treeiter][2])
else:
self.source_view_iter = 0
print("You selected", model[treeiter][0], model[treeiter][2])
if self.source_view:
children = self.source_view.get_children()
for child in children:
child.destroy()
prev = None
if self.results[model[treeiter][2]]:
for result in sorted(self.results[model[treeiter][2]]):
print(result)
if prev:
if prev.line_nr:
self.print_result(result.severity, result.origin, result.message, result.file, result.line_nr, max(result.line_nr-5, prev.line_nr))
else:
self.print_result(result.severity, result.origin, result.message, result.file, result.line_nr, max(result.line_nr-5, 1))
else:
if result.line_nr:
self.print_result(result.severity, result.origin, result.message, result.file, result.line_nr, max(result.line_nr-5, 1))
else:
self.print_result(result.severity, result.origin, result.message, result.file)
prev = result

def print_result(self,
severity,
origin,
message,
filename,
line_nr=None,
start_nr=None):
colored_box = Gtk.Box()
if severity == 0:
colored_box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(0,255,0,.5))
elif severity == 1:
colored_box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(255,255,0,.5))
else:
colored_box.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(255,0,0,.5))
colored_box.set_size_request(21, -1)
colored_box.set_visible(True)
colored_box.set_vexpand(True)
if line_nr is None:
self.source_view.attach(colored_box, 0, self.source_view_iter, 1, 1)
frame = Gtk.Frame()
frame.set_hexpand(True)
frame.set_vexpand(True)
frame.set_label(origin)
label = Gtk.Label()
label.set_text(message)
label.set_visible(True)
frame.add(label)
frame.set_visible(True)
frame.set_border_width(10)
self.source_view.attach(frame, 1, self.source_view_iter, 1,1)
self.source_view_iter += 1

else:
language_manager = GtkSource.LanguageManager.new()
language = language_manager.guess_language(filename, None)
textbuffer = GtkSource.Buffer()
textbuffer.set_highlight_syntax(True)
textbuffer.set_language(language)
textbuffer.set_text(''.join(open(filename).readlines()[start_nr:line_nr])[:-1])
textview = GtkSource.View(visible=True, buffer=textbuffer, monospace=True, editable=False)
textview.set_visible(True)
textview.set_hexpand(True)
self.source_view.attach(textview, 0,self.source_view_iter, 2, 1)
gutter = textview.get_gutter(Gtk.TextWindowType.LEFT)
renderer = LineRenderer(start_nr, xpad=6, xalign=1.0)
gutter.insert(renderer, 0)
self.source_view_iter += 1

self.source_view.attach(colored_box, 0, self.source_view_iter, 1, 1)
frame = Gtk.Frame()
frame.set_hexpand(True)
frame.set_vexpand(True)
frame.set_label(origin)
label = Gtk.Label()
label.set_text(message)
label.set_visible(True)
frame.add(label)
frame.set_visible(True)
frame.set_border_width(10)
self.source_view.attach(frame, 1, self.source_view_iter, 1,1)
self.source_view_iter += 1

0 comments on commit c8befb3

Please sign in to comment.