From e661306ae392287da4a560738c3fcffe16b93084 Mon Sep 17 00:00:00 2001 From: Udayan Tandon Date: Fri, 12 Jun 2015 15:21:36 +0530 Subject: [PATCH] GUI: Add settings interface --- gui/data/coala.gresource | Bin 7723 -> 9403 bytes gui/data/ui/coalaWindow.ui | 50 +++++++++++++++++++++++++++---- gui/src/support/settingTree.py | 12 ++++++++ gui/src/workspace/coalaWindow.py | 47 +++++++++++++++++++++-------- 4 files changed, 90 insertions(+), 19 deletions(-) diff --git a/gui/data/coala.gresource b/gui/data/coala.gresource index 158a395445f3e232a5f735ddbe39739f0f0fca63..024eab22e31f0ad9b5be7ed4219f02d906762936 100644 GIT binary patch delta 630 zcmZ2&v)gk*h0#$d28PGV>qQtD7#KioHU=MtGeG(V5YP9`zQGI>2eBm>${0QX>D?+D zSFy1%v5IWo#I}or&8;XgH&to!Mlt!x4vZX=4R}N*8%Rs=C*>EVq!#IxXQq^7DA}1# zPUMiBe3n;T*u5w-MM)tu#a1adF*7e6#G4$zr!;wjBqvla$K*IZk;y&+%9CUG#3r8? zLQoaoYaz3;v5CB9zEzV9W|XV92|fDIk+dU;1->% Vz^}IXy?`(CWNQ({%?To>IRRUT!w&!e delta 155 zcmdn(x!Ptzg^`g61H)tG^&*T63=AMP8-ovn1(0?D;`zSWH<*FqAhrZU8AAe))|T72 zij9q_hP1q78QH}FeNHsF?;#3nSkT~K|pzpTLI3>m@6*98^9YylzV$u>Ya s0dWa1|33%!YCZFXn+Ppc0PkrhBLDyZ diff --git a/gui/data/ui/coalaWindow.ui b/gui/data/ui/coalaWindow.ui index 23f97e1a1c..59ed6e0f0a 100644 --- a/gui/data/ui/coalaWindow.ui +++ b/gui/data/ui/coalaWindow.ui @@ -63,14 +63,52 @@ - - true - True - crossfade - True + + True + 5 + + + True + True + True + + + true + True + crossfade + True + + + 0 + 0 + 2 + + + + + True + Add Setting + + + 0 + 1 + + + + + True + Delete Setting + + + 1 + 1 + + + + - end + end diff --git a/gui/src/support/settingTree.py b/gui/src/support/settingTree.py index 51e553c196..91458d4b6b 100644 --- a/gui/src/support/settingTree.py +++ b/gui/src/support/settingTree.py @@ -8,10 +8,22 @@ def __init__(self): self.treeView = Gtk.TreeView(self) renderer1 = Gtk.CellRendererText() + renderer1.set_property("editable", True) column1 = Gtk.TreeViewColumn("Key", renderer1, text=0) self.treeView.append_column(column1) + renderer1.connect("edited", self.text_edited_column1) renderer2 = Gtk.CellRendererText() + renderer2.set_property("editable", True) column2 = Gtk.TreeViewColumn("Value", renderer2, text=1) self.treeView.append_column(column2) + renderer2.connect("edited", self.text_edited_column2) self.treeView.set_headers_visible(False) + self.treeView.set_visible(True) + self.treeView.set_grid_lines(Gtk.TreeViewGridLines.BOTH) + + def text_edited_column1(self, widget, path, text): + self[path][0] = text + + def text_edited_column2(self, widget, path, text): + self[path][1] = text diff --git a/gui/src/workspace/coalaWindow.py b/gui/src/workspace/coalaWindow.py index 8a123d34b9..eb234652ab 100644 --- a/gui/src/workspace/coalaWindow.py +++ b/gui/src/workspace/coalaWindow.py @@ -4,7 +4,7 @@ from gui.src.support.fileTree import coalaFileTree from gui.src.support.settingTree import coalaSettingTree -from coalib.settings.SectionManager import SectionManager +from coalib.settings.ConfigurationGathering import load_config_file from coalib.settings.Section import Section @@ -17,8 +17,8 @@ def __init__(self, app, src): self.path = src os.chdir(self.path) - self.section_manager = SectionManager() self.sections = {} + self.sections_view = {} self._ui = Gtk.Builder() self._ui.add_from_resource("/coala/coalaWindow.ui") @@ -31,6 +31,10 @@ def __init__(self, app, src): self.add_button = self._ui.get_object("add_section_button") self.add_button.connect("clicked", self.add_section_dialog, "Section name:") + self.add_setting_button = self._ui.get_object("addsetting") + self.add_setting_button.connect("clicked", self.add_setting) + self.delete_setting_button = self._ui.get_object("delsetting") + self.delete_setting_button.connect("clicked", self.del_setting) self.section_stack = self._ui.get_object("sections") self.section_stack_switcher = self._ui.get_object("section_switcher") @@ -49,15 +53,14 @@ def __init__(self, app, src): def setup_config_file(self): if os.path.isfile(self.path+'/.coafile'): - self.section_manager._load_configuration([]) + self.sections = load_config_file(self.path+'/.coafile', None) else: coafile = open(".coafile", "w") coafile.close() - self.section_manager._load_configuration([]) self.setup_sections() def setup_sections(self): - for key in self.section_manager.sections: + for key in self.sections: self.add_section(key) def add_section_dialog(self, button, message): @@ -81,22 +84,40 @@ def add_section_dialog(self, button, message): return None def add_section(self, section): + frame = Gtk.Frame() + frame.set_name(section) + frame.set_vexpand(True) + frame.set_hexpand(True) + frame.set_visible(True) + frame.set_border_width(5) box = Gtk.Box() box.set_visible(True) - box.set_border_width(10) box.set_hexpand(True) sw = Gtk.ScrolledWindow() sw.set_visible(True) sw.set_hexpand(True) settings = coalaSettingTree() - self.sections[section] = settings + self.sections_view[section] = settings sw.add(settings.treeView) box.add(sw) - if section in self.section_manager.sections: - for key in self.section_manager.sections[section]: + frame.add(box) + if section in self.sections: + for key in self.sections[section]: settings.append([key, - str(self.section_manager.sections[section][key])]) - else: - self.section_manager.sections[section] = Section(section) - self.section_stack.add_titled(box, section, section) + str(self.sections[section][key])]) + self.section_stack.add_titled(frame, section, section) self.section_stack_switcher.queue_draw() + + def del_setting(self, button): + section = self.section_stack.get_visible_child() + settings = self.sections_view[section.get_name()] + selection = settings.treeView.get_selection() + result = selection.get_selected() + if result: + model, iter = result + model.remove(iter) + + def add_setting(self, button): + section = self.section_stack.get_visible_child() + settings = self.sections_view[section.get_name()] + settings.append(["Entry", "Value"])