diff --git a/src/nailab/__main__.py b/src/nailab/__main__.py new file mode 100644 index 0000000..b240d09 --- /dev/null +++ b/src/nailab/__main__.py @@ -0,0 +1,6 @@ + +from nailab.nailab import main + +if __name__ == '__main__': + main() + diff --git a/src/nailab/data/__init__.py b/src/nailab/data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/nailab/data/csvfolderdatasource.py b/src/nailab/data/csvfolderdatasource.py index 75ef13b..5361f71 100644 --- a/src/nailab/data/csvfolderdatasource.py +++ b/src/nailab/data/csvfolderdatasource.py @@ -10,8 +10,8 @@ class CsvFolderDataSource(DataSource): super().__init__(name) self.path = path - self._discover_feeds() self.feeds = [] + self._discover_feeds() def available_feeds(self): return self.feeds diff --git a/src/nailab/data/datasourcemanager.py b/src/nailab/data/datasourcemanager.py new file mode 100644 index 0000000..788e153 --- /dev/null +++ b/src/nailab/data/datasourcemanager.py @@ -0,0 +1,20 @@ + +from nailab.data.csvfolderdatasource import CsvFolderDataSource + +class DataSourceManager: + + def __init__(self): + self.sources = [] + + def save_sources(self): + pass + + def load_sources(self): + self.add_source(CsvFolderDataSource('default', '/tmp')) + + def add_source(self, source): + self.sources.append(source) + + def all_sources(self): + return self.sources[:] + diff --git a/src/nailab/nailab.py b/src/nailab/nailab.py index 06e2446..9bd4248 100644 --- a/src/nailab/nailab.py +++ b/src/nailab/nailab.py @@ -5,7 +5,7 @@ gi.require_version('GtkSource', '3.0') from gi.repository import Gtk, GObject from gi.repository import GtkSource -from ui.applicationwindow import ApplicationWindow +from nailab.ui.applicationwindow import ApplicationWindow def main(): GObject.type_register(GtkSource.View) diff --git a/src/nailab/ui/applicationwindow.py b/src/nailab/ui/applicationwindow.py index 7a6485f..6bbfbe8 100644 --- a/src/nailab/ui/applicationwindow.py +++ b/src/nailab/ui/applicationwindow.py @@ -1,21 +1,65 @@ from gi.repository import Gtk, GtkSource +from nailab.data.datasourcemanager import DataSourceManager +from .sourceviewcontroller import SourceViewController + class ApplicationWindow: def __init__(self, builder): self.window = builder.get_object('ApplicationWindow') + self._init_sourceeditor(builder) + + self._init_tv_datasource(builder) + + handlers = { + 'on_ApplicationWindow_delete_event' : Gtk.main_quit, + 'on_OpenFile' : self.open_file + } + + builder.connect_signals(handlers) + self.window.show_all() + + def open_file(self, arg): + dlg = Gtk.FileChooserDialog('Open file', self.window, Gtk.FileChooserAction.OPEN, + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, + Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) + result = dlg.run() + + if result == Gtk.ResponseType.OK: + with open(dlg.get_filename(), 'r') as f: + self.sourceviewcontroller.set_source_text(f.read()) + + + dlg.destroy() + + + def _init_sourceeditor(self, builder): manager = GtkSource.LanguageManager() buf = GtkSource.Buffer() buf.set_language(manager.get_language('python')) sv = builder.get_object('sourceview') sv.set_buffer(buf) sv.set_monospace(True) + + self.sourceviewcontroller = SourceViewController(sv) - handlers = { - 'on_ApplicationWindow_delete_event' : Gtk.main_quit - } + def _init_tv_datasource(self, builder): + self.datasourcemanager = DataSourceManager() + self.datasourcemanager.load_sources() - builder.connect_signals(handlers) - self.window.show_all() + tv_datasources = builder.get_object('tv_datasources') + + self.datasources_store = Gtk.TreeStore(str) + for source in self.datasourcemanager.all_sources(): + treeiter = self.datasources_store.append(None, (source.name,)) + for feed in source.available_feeds(): + self.datasources_store.append(treeiter, (feed,)) + + + rendererText = Gtk.CellRendererText() + column = Gtk.TreeViewColumn('Datasources', rendererText, text=0) + tv_datasources.append_column(column) + + tv_datasources.set_model(self.datasources_store) diff --git a/src/nailab/ui/sourceviewcontroller.py b/src/nailab/ui/sourceviewcontroller.py new file mode 100644 index 0000000..0364b71 --- /dev/null +++ b/src/nailab/ui/sourceviewcontroller.py @@ -0,0 +1,8 @@ + +class SourceViewController: + + def __init__(self, sourceview): + self.sourceview = sourceview + + def set_source_text(self, text): + self.sourceview.get_buffer().set_text(text) diff --git a/src/nailab/ui/nailab.glade b/ui/nailab.glade similarity index 81% rename from src/nailab/ui/nailab.glade rename to ui/nailab.glade index b4c3af8..8f6b474 100644 --- a/src/nailab/ui/nailab.glade +++ b/ui/nailab.glade @@ -4,18 +4,6 @@ - - - - Normal - monospace - - - - - texttagtable - <default>foo</default> - 1024 768 @@ -35,12 +23,22 @@ 200 True - + True True - model_dataSources - - + in + + + True + True + natural + natural + model_dataSources + both + + + + @@ -49,19 +47,25 @@ - + True True - word-char - textbuffer - True - True - True - 4 - True - True - True - True + in + + + True + True + word-char + True + True + True + 4 + True + True + True + True + + True @@ -100,6 +104,7 @@ False True True +