Skip to content

Commit

Permalink
GUI: Add settings interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Udayan12167 committed Jun 12, 2015
1 parent d42a076 commit e661306
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 19 deletions.
Binary file modified gui/data/coala.gresource
Binary file not shown.
50 changes: 44 additions & 6 deletions gui/data/ui/coalaWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,52 @@
</packing>
</child>
<child>
<object class="GtkStack" id="sections">
<property name="visible">true</property>
<property name="can_focus">True</property>
<property name="transition-type">crossfade</property>
<property name="hexpand">True</property>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="border-width">5</property>
<child>
<object class="GtkGrid" id="maingrid">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child>
<object class="GtkStack" id="sections">
<property name="visible">true</property>
<property name="can_focus">True</property>
<property name="transition-type">crossfade</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="addsetting">
<property name="visible">True</property>
<property name="label">Add Setting</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="delsetting">
<property name="visible">True</property>
<property name="label">Delete Setting</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
<property name="pack_type">end</property>
</packing>
</child>
</object>
Expand Down
12 changes: 12 additions & 0 deletions gui/src/support/settingTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

47 changes: 34 additions & 13 deletions gui/src/workspace/coalaWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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):
Expand All @@ -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"])

0 comments on commit e661306

Please sign in to comment.