Browse Source

File opening

master
Denis Tereshkin 8 years ago
parent
commit
eb9d10c7de
  1. 6
      src/nailab/__main__.py
  2. 0
      src/nailab/data/__init__.py
  3. 2
      src/nailab/data/csvfolderdatasource.py
  4. 20
      src/nailab/data/datasourcemanager.py
  5. 2
      src/nailab/nailab.py
  6. 54
      src/nailab/ui/applicationwindow.py
  7. 8
      src/nailab/ui/sourceviewcontroller.py
  8. 31
      ui/nailab.glade

6
src/nailab/__main__.py

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
from nailab.nailab import main
if __name__ == '__main__':
main()

0
src/nailab/data/__init__.py

2
src/nailab/data/csvfolderdatasource.py

@ -10,8 +10,8 @@ class CsvFolderDataSource(DataSource): @@ -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

20
src/nailab/data/datasourcemanager.py

@ -0,0 +1,20 @@ @@ -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[:]

2
src/nailab/nailab.py

@ -5,7 +5,7 @@ gi.require_version('GtkSource', '3.0') @@ -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)

54
src/nailab/ui/applicationwindow.py

@ -1,10 +1,40 @@ @@ -1,10 +1,40 @@
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'))
@ -12,10 +42,24 @@ class ApplicationWindow: @@ -12,10 +42,24 @@ class ApplicationWindow:
sv.set_buffer(buf)
sv.set_monospace(True)
handlers = {
'on_ApplicationWindow_delete_event' : Gtk.main_quit
}
self.sourceviewcontroller = SourceViewController(sv)
builder.connect_signals(handlers)
self.window.show_all()
def _init_tv_datasource(self, builder):
self.datasourcemanager = DataSourceManager()
self.datasourcemanager.load_sources()
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)

8
src/nailab/ui/sourceviewcontroller.py

@ -0,0 +1,8 @@ @@ -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)

31
src/nailab/ui/nailab.glade → ui/nailab.glade

@ -4,18 +4,6 @@ @@ -4,18 +4,6 @@
<requires lib="gtk+" version="3.0"/>
<requires lib="gtksourceview" version="3.0"/>
<object class="GtkListStore" id="model_dataSources"/>
<object class="GtkTextTagTable" id="texttagtable">
<child type="tag">
<object class="GtkTextTag" id="default">
<property name="font">Normal</property>
<property name="family">monospace</property>
</object>
</child>
</object>
<object class="GtkTextBuffer" id="textbuffer">
<property name="tag_table">texttagtable</property>
<property name="text" translatable="yes">&lt;default&gt;foo&lt;/default&gt;</property>
</object>
<object class="GtkApplicationWindow" id="ApplicationWindow">
<property name="width_request">1024</property>
<property name="height_request">768</property>
@ -34,26 +22,40 @@ @@ -34,26 +22,40 @@
<property name="can_focus">True</property>
<property name="position">200</property>
<property name="position_set">True</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="tv_datasources">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscroll_policy">natural</property>
<property name="vscroll_policy">natural</property>
<property name="model">model_dataSources</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
</object>
</child>
</object>
<packing>
<property name="resize">False</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkSourceView" id="sourceview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="wrap_mode">word-char</property>
<property name="buffer">textbuffer</property>
<property name="monospace">True</property>
<property name="show_line_numbers">True</property>
<property name="show_line_marks">True</property>
@ -63,6 +65,8 @@ @@ -63,6 +65,8 @@
<property name="highlight_current_line">True</property>
<property name="smart_backspace">True</property>
</object>
</child>
</object>
<packing>
<property name="resize">True</property>
<property name="shrink">True</property>
@ -100,6 +104,7 @@ @@ -100,6 +104,7 @@
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_OpenFile" swapped="no"/>
</object>
</child>
<child>
Loading…
Cancel
Save