Browse Source

New file

master
Denis Tereshkin 8 years ago
parent
commit
09e6aeda11
  1. 0
      src/nailab/templates/__init__.py
  2. 16
      src/nailab/templates/new_strategy.py
  3. 5
      src/nailab/ui/applicationwindow.py
  4. 20
      src/nailab/ui/tabmanager.py
  5. 3
      ui/nailab.glade

0
src/nailab/templates/__init__.py

16
src/nailab/templates/new_strategy.py

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
new_strategy_template = '''
from naiback.strategy import Strategy
class MyStrategy(Strategy):
def __init__(self):
super().__init__()
def execute(self):
for i in self.bars.index[200:]:
if self.last_position_is_active():
pass
else:
pass
'''

5
src/nailab/ui/applicationwindow.py

@ -4,6 +4,7 @@ from gi.repository import Gtk, GtkSource @@ -4,6 +4,7 @@ from gi.repository import Gtk, GtkSource
from nailab.data.datasource import DataSource
from nailab.data.datasourcemanager import DataSourceManager
from nailab.execution.executor import Executor
from nailab.templates.new_strategy import new_strategy_template
from .resultstable import ResultsTableWidget
from .tabmanager import TabManager
@ -18,6 +19,7 @@ class ApplicationWindow: @@ -18,6 +19,7 @@ class ApplicationWindow:
handlers = {
'on_ApplicationWindow_delete_event' : Gtk.main_quit,
'on_menuNew' : self.new_file,
'on_OpenFile' : self.open_file,
'on_menuSave' : self.save_file,
'on_menuSaveAs' : self.save_file_as,
@ -27,6 +29,9 @@ class ApplicationWindow: @@ -27,6 +29,9 @@ class ApplicationWindow:
builder.connect_signals(handlers)
self.window.show_all()
def new_file(self, arg):
self.tab_manager.new_from_template(new_strategy_template)
def open_file(self, arg):
dlg = Gtk.FileChooserDialog('Open file', self.window, Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,

20
src/nailab/ui/tabmanager.py

@ -34,12 +34,23 @@ class TabManager(GObject.Object): @@ -34,12 +34,23 @@ class TabManager(GObject.Object):
index = self.notebook.append_page(widget, header)
self.notebook.set_current_page(index)
def new_tab(self, source_file):
def _read_source_file(self, source_file):
if source_file is not None:
with open(source_file, 'r') as f:
return f.read()
else:
return None
def new_tab(self, source_file):
tab_id = self._next_tab_id()
self.source_paths[tab_id] = source_file
(sv, sv_controller) = self._init_sourceeditor()
source = self._read_source_file(source_file)
if source is not None:
sv_controller.set_source_text(f.read())
self.source_paths[tab_id] = source_file
self.source_controllers[tab_id] = sv_controller
self.widgets[tab_id] = sv
sv.show_all()
@ -59,6 +70,7 @@ class TabManager(GObject.Object): @@ -59,6 +70,7 @@ class TabManager(GObject.Object):
header.show_all()
index = self.notebook.append_page(sv, header)
self.notebook.set_current_page(index)
return tab_id
def close_cb(self, arg, tab_id):
index = self._widget_num_by_tab_id(tab_id)
@ -78,6 +90,10 @@ class TabManager(GObject.Object): @@ -78,6 +90,10 @@ class TabManager(GObject.Object):
return None
def new_from_template(self, template):
tab_id = self.new_tab(None)
self.source_controllers[tab_id].set_source_text(template)
def save_current(self):
index = self.notebook.get_current_page()
w = self.notebook.get_nth_page(index)

3
ui/nailab.glade

@ -96,12 +96,13 @@ @@ -96,12 +96,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="imagemenuitem21">
<object class="GtkImageMenuItem" id="menuNew">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="on_menuNew" swapped="no"/>
</object>
</child>
<child>

Loading…
Cancel
Save