new syntax highlighter, abortable sleep function
Joachim Beerwerth from the group of Prof. Roland Böhmer (TU Dortmund) provided a patch with follwing enhancements: * new syntax highlighter: * improves performance with longer scripts * search function (ctrl+f) * auto indent * undo/redo * abortable sleep function in experiment scripts
This commit is contained in:
parent
9f4a3d6b53
commit
dfd5961ba6
2
debian/control
vendored
2
debian/control
vendored
@ -10,7 +10,7 @@ Package: python-damaris
|
|||||||
Architecture: all
|
Architecture: all
|
||||||
XB-Python-Version: ${python:Versions}
|
XB-Python-Version: ${python:Versions}
|
||||||
Provides: ${python:Provides}, damaris-frontend
|
Provides: ${python:Provides}, damaris-frontend
|
||||||
Depends: ${python:Depends}, python-numpy (>=1.0), python-scipy, python-gtk2 (>=2.8.0), python-glade2, python-matplotlib (>=0.90), python-tables (>=1.3.2), lzop, python-xdg
|
Depends: ${python:Depends}, python-numpy (>=1.0), python-scipy, python-gtk2 (>=2.8.0), python-glade2, python-matplotlib (>=0.90), python-tables (>=1.3.2), lzop, python-xdg, python-gtksourceview2
|
||||||
Recommends: damaris-backends, python-numpy-ext
|
Recommends: damaris-backends, python-numpy-ext
|
||||||
Suggests: python-doc, python-tables-doc, python-numpy-doc
|
Suggests: python-doc, python-tables-doc, python-numpy-doc
|
||||||
Description: python frontend for DAMARIS project
|
Description: python frontend for DAMARIS project
|
||||||
|
@ -34,6 +34,8 @@ import gtk.gdk
|
|||||||
gtk.gdk.threads_init( )
|
gtk.gdk.threads_init( )
|
||||||
import gtk.glade
|
import gtk.glade
|
||||||
|
|
||||||
|
import gtksourceview2
|
||||||
|
|
||||||
import pango
|
import pango
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
@ -72,7 +74,7 @@ if hasattr( gtk, "PrintOperation" ):
|
|||||||
from damaris.gui import ExperimentWriter, ExperimentHandling
|
from damaris.gui import ExperimentWriter, ExperimentHandling
|
||||||
from damaris.gui import ResultReader, ResultHandling
|
from damaris.gui import ResultReader, ResultHandling
|
||||||
from damaris.gui import BackendDriver
|
from damaris.gui import BackendDriver
|
||||||
from damaris.gui.gtkcodebuffer import CodeBuffer, SyntaxLoader
|
#from damaris.gui.gtkcodebuffer import CodeBuffer, SyntaxLoader
|
||||||
#from damaris.data import Drawable # this is a base class, it should be used...
|
#from damaris.data import Drawable # this is a base class, it should be used...
|
||||||
from damaris.data import DataPool, Accumulation, ADC_Result, MeasurementResult
|
from damaris.data import DataPool, Accumulation, ADC_Result, MeasurementResult
|
||||||
|
|
||||||
@ -243,7 +245,57 @@ class DamarisGUI:
|
|||||||
if self.state in [ DamarisGUI.Edit_State, DamarisGUI.Quit_State ]:
|
if self.state in [ DamarisGUI.Edit_State, DamarisGUI.Quit_State ]:
|
||||||
self.state = DamarisGUI.Quit_State
|
self.state = DamarisGUI.Quit_State
|
||||||
# do a cleanup...
|
# do a cleanup...
|
||||||
print "ToDo: Cleanup, Save Dialogs ..."
|
|
||||||
|
if self.sw.experiment_script_textbuffer.get_modified( ):
|
||||||
|
question = gtk.MessageDialog(parent=self.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=gtk.BUTTONS_NONE)
|
||||||
|
question.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
||||||
|
question.add_button(gtk.STOCK_NO, gtk.RESPONSE_NO)
|
||||||
|
question.add_button(gtk.STOCK_YES, gtk.RESPONSE_YES)
|
||||||
|
question.set_markup("The Experiment Script has been changed. Save changes?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response == gtk.RESPONSE_CANCEL:
|
||||||
|
return True
|
||||||
|
elif response == gtk.RESPONSE_YES:
|
||||||
|
current_page = self.main_notebook.get_current_page( )
|
||||||
|
self.main_notebook.set_current_page(0)
|
||||||
|
if self.sw.exp_script_filename is None:
|
||||||
|
self.sw.save_file_as()
|
||||||
|
else:
|
||||||
|
self.sw.save_file()
|
||||||
|
self.main_notebook.set_current_page(current_page)
|
||||||
|
|
||||||
|
if self.sw.data_handling_textbuffer.get_modified( ):
|
||||||
|
question = gtk.MessageDialog(parent=self.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=gtk.BUTTONS_NONE)
|
||||||
|
question.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
||||||
|
question.add_button(gtk.STOCK_NO, gtk.RESPONSE_NO)
|
||||||
|
question.add_button(gtk.STOCK_YES, gtk.RESPONSE_YES)
|
||||||
|
question.set_markup("The Result Script has been changed. Save changes?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response == gtk.RESPONSE_CANCEL:
|
||||||
|
return True
|
||||||
|
elif response == gtk.RESPONSE_YES:
|
||||||
|
current_page = self.main_notebook.get_current_page( )
|
||||||
|
self.main_notebook.set_current_page(1)
|
||||||
|
if self.sw.res_script_filename is None:
|
||||||
|
self.sw.save_file_as()
|
||||||
|
else:
|
||||||
|
self.sw.save_file()
|
||||||
|
self.main_notebook.set_current_page(current_page)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.config = None
|
self.config = None
|
||||||
self.sw = None
|
self.sw = None
|
||||||
self.monitor = None
|
self.monitor = None
|
||||||
@ -252,7 +304,14 @@ class DamarisGUI:
|
|||||||
gtk.main_quit( )
|
gtk.main_quit( )
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print "Stop Experiment please! (ToDo: Dialog)"
|
question = gtk.MessageDialog(parent=self.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_ERROR,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=gtk.BUTTONS_OK)
|
||||||
|
question.set_markup("Experiment still running, can not close DAMARIS!")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# toolbar related events:
|
# toolbar related events:
|
||||||
@ -988,16 +1047,58 @@ class ScriptWidgets:
|
|||||||
self.res_script_filename = None
|
self.res_script_filename = None
|
||||||
|
|
||||||
# load syntax description for syntax highlighting (defined in python.xml)
|
# load syntax description for syntax highlighting (defined in python.xml)
|
||||||
sl = SyntaxLoader( "python" )
|
#sl = SyntaxLoader( "python" )
|
||||||
# script buffers:
|
# script buffers:
|
||||||
self.experiment_script_textview = self.xml_gui.get_widget( "experiment_script_textview" )
|
self.experiment_script_textview = self.xml_gui.get_widget( "experiment_script_textview" )
|
||||||
self.data_handling_textview = self.xml_gui.get_widget( "data_handling_textview" )
|
self.data_handling_textview = self.xml_gui.get_widget( "data_handling_textview" )
|
||||||
|
|
||||||
# create and set syntax-highlighting text-buffers as textview backends
|
# create and set syntax-highlighting text-buffers as textview backends
|
||||||
self.experiment_script_textbuffer = CodeBuffer( lang=sl )
|
self.experiment_script_textbuffer = gtksourceview2.Buffer()
|
||||||
self.data_handling_textbuffer = CodeBuffer( lang=sl )
|
self.data_handling_textbuffer = gtksourceview2.Buffer()
|
||||||
|
|
||||||
|
lm = gtksourceview2.LanguageManager()
|
||||||
|
langpython = lm.get_language("python")
|
||||||
|
|
||||||
|
self.experiment_script_textbuffer.set_language(langpython)
|
||||||
|
self.experiment_script_textbuffer.set_highlight_syntax(True)
|
||||||
|
self.data_handling_textbuffer.set_language(langpython)
|
||||||
|
self.data_handling_textbuffer.set_highlight_syntax(True)
|
||||||
|
|
||||||
|
|
||||||
self.experiment_script_textview.set_buffer( self.experiment_script_textbuffer )
|
self.experiment_script_textview.set_buffer( self.experiment_script_textbuffer )
|
||||||
|
self.experiment_script_textview.set_show_line_numbers(True)
|
||||||
|
self.experiment_script_textview.set_auto_indent(True)
|
||||||
self.data_handling_textview.set_buffer( self.data_handling_textbuffer )
|
self.data_handling_textview.set_buffer( self.data_handling_textbuffer )
|
||||||
|
self.data_handling_textview.set_show_line_numbers(True)
|
||||||
|
self.data_handling_textview.set_auto_indent(True)
|
||||||
|
|
||||||
|
keywords = """for if else elif in print try finally except global lambda not or pass def
|
||||||
|
class import from as return yield while continue break assert None True False AccumulatedValue
|
||||||
|
Accumulation MeasurementResult ADC_Result Experiment synchronize sleep result data isinstance
|
||||||
|
issubclass min max abs pow range xrange log_range lin_range staggered_range int float zip file
|
||||||
|
combine_ranges interleaved_range get_sampling_rate uses_statistics write_to_csv write_to_hdf
|
||||||
|
get_job_id get_description set_description get_xdata get_ydata set_xdate set_ydata"""
|
||||||
|
|
||||||
|
keywordsbuffer = gtksourceview2.Buffer()
|
||||||
|
keywordsbuffer.set_text(keywords)
|
||||||
|
|
||||||
|
compexp = self.experiment_script_textview.get_completion()
|
||||||
|
compres = self.data_handling_textview.get_completion()
|
||||||
|
|
||||||
|
compwgen = gtksourceview2.CompletionWords('Keywords')
|
||||||
|
compwgen.register(keywordsbuffer)
|
||||||
|
|
||||||
|
compwexp = gtksourceview2.CompletionWords('Experimentscript')
|
||||||
|
compwexp.register(self.experiment_script_textbuffer)
|
||||||
|
|
||||||
|
compwres = gtksourceview2.CompletionWords('Resultscript')
|
||||||
|
compwres.register(self.data_handling_textbuffer)
|
||||||
|
|
||||||
|
compexp.add_provider(compwgen)
|
||||||
|
compres.add_provider(compwgen)
|
||||||
|
|
||||||
|
compexp.add_provider(compwexp)
|
||||||
|
compres.add_provider(compwres)
|
||||||
|
|
||||||
# script fonts are atlered by configuration
|
# script fonts are atlered by configuration
|
||||||
# clipboard
|
# clipboard
|
||||||
@ -1040,6 +1141,9 @@ class ScriptWidgets:
|
|||||||
self.toolbar_save_as_button = self.xml_gui.get_widget( "toolbar_save_as_button" )
|
self.toolbar_save_as_button = self.xml_gui.get_widget( "toolbar_save_as_button" )
|
||||||
self.toolbar_save_all_button = self.xml_gui.get_widget( "toolbar_save_all_button" )
|
self.toolbar_save_all_button = self.xml_gui.get_widget( "toolbar_save_all_button" )
|
||||||
self.toolbar_check_scripts_button = self.xml_gui.get_widget( "toolbar_check_scripts_button" )
|
self.toolbar_check_scripts_button = self.xml_gui.get_widget( "toolbar_check_scripts_button" )
|
||||||
|
self.toolbar_undo_button = self.xml_gui.get_widget( "toolbar_undo_button" )
|
||||||
|
self.toolbar_redo_button = self.xml_gui.get_widget( "toolbar_redo_button" )
|
||||||
|
self.toolbar_search_button = self.xml_gui.get_widget("toolbar_search_button")
|
||||||
# events
|
# events
|
||||||
self.xml_gui.signal_connect( "on_toolbar_open_file_button_clicked", self.open_file )
|
self.xml_gui.signal_connect( "on_toolbar_open_file_button_clicked", self.open_file )
|
||||||
self.xml_gui.signal_connect( "on_toolbar_new_button_clicked", self.new_file )
|
self.xml_gui.signal_connect( "on_toolbar_new_button_clicked", self.new_file )
|
||||||
@ -1047,6 +1151,9 @@ class ScriptWidgets:
|
|||||||
self.xml_gui.signal_connect( "on_toolbar_save_file_button_clicked", self.save_file )
|
self.xml_gui.signal_connect( "on_toolbar_save_file_button_clicked", self.save_file )
|
||||||
self.xml_gui.signal_connect( "on_toolbar_save_all_button_clicked", self.save_all_files )
|
self.xml_gui.signal_connect( "on_toolbar_save_all_button_clicked", self.save_all_files )
|
||||||
self.xml_gui.signal_connect( "on_toolbar_check_scripts_button_clicked", self.check_script )
|
self.xml_gui.signal_connect( "on_toolbar_check_scripts_button_clicked", self.check_script )
|
||||||
|
self.xml_gui.signal_connect( "on_toolbar_undo_button_clicked", self.undo )
|
||||||
|
self.xml_gui.signal_connect( "on_toolbar_redo_button_clicked", self.redo )
|
||||||
|
self.xml_gui.signal_connect( "on_toolbar_search_button_clicked", self.search )
|
||||||
|
|
||||||
# my notebook
|
# my notebook
|
||||||
self.main_notebook = self.xml_gui.get_widget( "main_notebook" )
|
self.main_notebook = self.xml_gui.get_widget( "main_notebook" )
|
||||||
@ -1062,14 +1169,18 @@ class ScriptWidgets:
|
|||||||
def set_scripts( self, exp_script=None, res_script=None ):
|
def set_scripts( self, exp_script=None, res_script=None ):
|
||||||
# load buffers and set cursor to front
|
# load buffers and set cursor to front
|
||||||
if exp_script is not None:
|
if exp_script is not None:
|
||||||
|
self.experiment_script_textbuffer.begin_not_undoable_action()
|
||||||
self.experiment_script_textbuffer.set_text( unicode( exp_script ) )
|
self.experiment_script_textbuffer.set_text( unicode( exp_script ) )
|
||||||
self.experiment_script_textbuffer.place_cursor( self.experiment_script_textbuffer.get_start_iter( ) )
|
self.experiment_script_textbuffer.place_cursor( self.experiment_script_textbuffer.get_start_iter( ) )
|
||||||
self.experiment_script_textbuffer.set_modified( False )
|
self.experiment_script_textbuffer.set_modified( False )
|
||||||
|
self.experiment_script_textbuffer.end_not_undoable_action()
|
||||||
self.textviews_moved( self.experiment_script_textview )
|
self.textviews_moved( self.experiment_script_textview )
|
||||||
if res_script is not None:
|
if res_script is not None:
|
||||||
|
self.data_handling_textbuffer.begin_not_undoable_action()
|
||||||
self.data_handling_textbuffer.set_text( unicode( res_script ) )
|
self.data_handling_textbuffer.set_text( unicode( res_script ) )
|
||||||
self.data_handling_textbuffer.place_cursor( self.data_handling_textbuffer.get_start_iter( ) )
|
self.data_handling_textbuffer.place_cursor( self.data_handling_textbuffer.get_start_iter( ) )
|
||||||
self.data_handling_textbuffer.set_modified( False )
|
self.data_handling_textbuffer.set_modified( False )
|
||||||
|
self.data_handling_textbuffer.end_not_undoable_action()
|
||||||
self.textviews_moved( self.data_handling_textview )
|
self.textviews_moved( self.data_handling_textview )
|
||||||
self.set_toolbuttons_status( )
|
self.set_toolbuttons_status( )
|
||||||
|
|
||||||
@ -1117,14 +1228,23 @@ class ScriptWidgets:
|
|||||||
exp_modified = self.experiment_script_textbuffer.get_modified( )
|
exp_modified = self.experiment_script_textbuffer.get_modified( )
|
||||||
res_modified = self.data_handling_textbuffer.get_modified( )
|
res_modified = self.data_handling_textbuffer.get_modified( )
|
||||||
enable_save = True
|
enable_save = True
|
||||||
|
canundo = False
|
||||||
|
canredo = False
|
||||||
if current_page == 0:
|
if current_page == 0:
|
||||||
enable_save = exp_modified and self.exp_script_filename is not None
|
enable_save = exp_modified and self.exp_script_filename is not None
|
||||||
|
canundo = self.experiment_script_textbuffer.can_undo()
|
||||||
|
canredo = self.experiment_script_textbuffer.can_redo()
|
||||||
elif current_page == 1:
|
elif current_page == 1:
|
||||||
enable_save = res_modified and self.res_script_filename is not None
|
enable_save = res_modified and self.res_script_filename is not None
|
||||||
|
canundo = self.data_handling_textbuffer.can_undo()
|
||||||
|
canredo = self.data_handling_textbuffer.can_redo()
|
||||||
self.toolbar_save_button.set_sensitive( enable_save )
|
self.toolbar_save_button.set_sensitive( enable_save )
|
||||||
self.toolbar_save_as_button.set_sensitive( True )
|
self.toolbar_save_as_button.set_sensitive( True )
|
||||||
self.toolbar_save_all_button.set_sensitive( exp_modified or res_modified )
|
self.toolbar_save_all_button.set_sensitive( exp_modified or res_modified )
|
||||||
self.toolbar_check_scripts_button.set_sensitive( True )
|
self.toolbar_check_scripts_button.set_sensitive( True )
|
||||||
|
self.toolbar_undo_button.set_sensitive(canundo)
|
||||||
|
self.toolbar_redo_button.set_sensitive(canredo)
|
||||||
|
self.toolbar_search_button.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
# disable toolbar
|
# disable toolbar
|
||||||
self.toolbar_new_button.set_sensitive( False )
|
self.toolbar_new_button.set_sensitive( False )
|
||||||
@ -1133,6 +1253,9 @@ class ScriptWidgets:
|
|||||||
self.toolbar_save_as_button.set_sensitive( False )
|
self.toolbar_save_as_button.set_sensitive( False )
|
||||||
self.toolbar_save_all_button.set_sensitive( False )
|
self.toolbar_save_all_button.set_sensitive( False )
|
||||||
self.toolbar_check_scripts_button.set_sensitive( False )
|
self.toolbar_check_scripts_button.set_sensitive( False )
|
||||||
|
self.toolbar_undo_button.set_sensitive(False)
|
||||||
|
self.toolbar_redo_button.set_sensitive(False)
|
||||||
|
self.toolbar_search_button.set_sensitive(current_page == 3)
|
||||||
|
|
||||||
if self.exp_script_filename:
|
if self.exp_script_filename:
|
||||||
exp_titlename = unicode( os.path.splitext( os.path.basename( self.exp_script_filename ) )[ 0 ] )
|
exp_titlename = unicode( os.path.splitext( os.path.basename( self.exp_script_filename ) )[ 0 ] )
|
||||||
@ -1256,27 +1379,7 @@ class ScriptWidgets:
|
|||||||
"""
|
"""
|
||||||
#print "keypress", event.state, event.keyval
|
#print "keypress", event.state, event.keyval
|
||||||
if event.state & gtk.gdk.CONTROL_MASK != 0:
|
if event.state & gtk.gdk.CONTROL_MASK != 0:
|
||||||
if event.keyval == gtk.gdk.keyval_from_name( "c" ):
|
if event.keyval == gtk.gdk.keyval_from_name( "s" ):
|
||||||
if self.main_notebook.get_current_page( ) == 0:
|
|
||||||
self.experiment_script_textbuffer.copy_clipboard( self.main_clipboard )
|
|
||||||
elif self.main_notebook.get_current_page( ) == 1:
|
|
||||||
self.data_handling_textbuffer.copy_clipboard( self.main_clipboard )
|
|
||||||
return True
|
|
||||||
elif event.keyval == gtk.gdk.keyval_from_name( "x" ):
|
|
||||||
# cut_clipboard(clipboard, textview editable?)
|
|
||||||
if self.main_notebook.get_current_page( ) == 0:
|
|
||||||
self.experiment_script_textbuffer.cut_clipboard( self.main_clipboard, True )
|
|
||||||
elif self.main_notebook.get_current_page( ) == 1:
|
|
||||||
self.data_handling_textbuffer.cut_clipboard( self.main_clipboard, True )
|
|
||||||
return True
|
|
||||||
elif event.keyval == gtk.gdk.keyval_from_name( "v" ):
|
|
||||||
# paste_clipboard(clipboard, textpos (None = Cursor), textview editable?)
|
|
||||||
if self.main_notebook.get_current_page( ) == 0:
|
|
||||||
self.experiment_script_textbuffer.paste_clipboard( self.main_clipboard, None, True )
|
|
||||||
elif self.main_notebook.get_current_page( ) == 1:
|
|
||||||
self.data_handling_textbuffer.paste_clipboard( self.main_clipboard, None, True )
|
|
||||||
return True
|
|
||||||
elif event.keyval == gtk.gdk.keyval_from_name( "s" ):
|
|
||||||
# save buffer
|
# save buffer
|
||||||
page = self.main_notebook.get_current_page( )
|
page = self.main_notebook.get_current_page( )
|
||||||
if (self.exp_script_filename, self.res_script_filename)[ page ] is None:
|
if (self.exp_script_filename, self.res_script_filename)[ page ] is None:
|
||||||
@ -1286,88 +1389,13 @@ class ScriptWidgets:
|
|||||||
return True
|
return True
|
||||||
elif event.keyval == gtk.gdk.keyval_from_name( "S" ):
|
elif event.keyval == gtk.gdk.keyval_from_name( "S" ):
|
||||||
# save both buffers
|
# save both buffers
|
||||||
print "ToDo: save both buffers"
|
|
||||||
self.save_all_files( None, None )
|
self.save_all_files( None, None )
|
||||||
return True
|
return True
|
||||||
|
elif event.keyval == gtk.gdk.keyval_from_name("f"):
|
||||||
|
self.search(None, None)
|
||||||
|
return True
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# indent helpers
|
|
||||||
# tab keyval 0xff09
|
|
||||||
# backspace keyval 0xff08
|
|
||||||
# to do check if modified event is called after all
|
|
||||||
if (event.keyval == 0xFF09 or event.keyval == 0xFF08):
|
|
||||||
textbuffer = widget.get_buffer( )
|
|
||||||
# do not do things during selection
|
|
||||||
if (textbuffer.get_selection_bounds( )):
|
|
||||||
return 0
|
|
||||||
cursor_mark = textbuffer.get_insert( )
|
|
||||||
cursor_iter = textbuffer.get_iter_at_mark( cursor_mark )
|
|
||||||
if (cursor_iter.starts_line( )):
|
|
||||||
# backspace with normal function at line start
|
|
||||||
if (event.keyval == 0xFF08):
|
|
||||||
self.textviews_moved( widget )
|
|
||||||
return 0
|
|
||||||
# now get iterator at line start
|
|
||||||
linestart_iter = cursor_iter.copy( )
|
|
||||||
linestart_iter.set_line_offset( 0 )
|
|
||||||
linebegin = textbuffer.get_text( linestart_iter, cursor_iter ).expandtabs( )
|
|
||||||
if (len( linebegin ) != 0 and not linebegin.isspace( )):
|
|
||||||
# just make the spaces go away
|
|
||||||
textbuffer.delete( linestart_iter, cursor_iter )
|
|
||||||
textbuffer.insert( linestart_iter, linebegin )
|
|
||||||
self.textviews_moved( widget )
|
|
||||||
return 0
|
|
||||||
# find all space at the begin
|
|
||||||
while (not cursor_iter.ends_line( )
|
|
||||||
and not cursor_iter.is_end( )
|
|
||||||
and cursor_iter.get_char( ).isspace( )):
|
|
||||||
cursor_iter.forward_char( )
|
|
||||||
linebegin = textbuffer.get_text( linestart_iter, cursor_iter )
|
|
||||||
if (event.keyval == 0xFF08):
|
|
||||||
# backspace shortens space
|
|
||||||
linebegin = u' ' * ((len( linebegin ) - 1) / 4) * 4
|
|
||||||
elif (event.keyval == 0xFF09):
|
|
||||||
# tab widens space
|
|
||||||
linebegin = u' ' * ((len( linebegin ) + 4) / 4) * 4
|
|
||||||
|
|
||||||
textbuffer.delete( linestart_iter, cursor_iter )
|
|
||||||
textbuffer.insert( linestart_iter, linebegin )
|
|
||||||
self.textviews_moved( widget )
|
|
||||||
return 1
|
|
||||||
# implement convenience function for enter key
|
|
||||||
elif (event.keyval == 0xFF0D):
|
|
||||||
textbuffer = widget.get_buffer( )
|
|
||||||
# do not do things during selection
|
|
||||||
if (textbuffer.get_selection_bounds( )):
|
|
||||||
return 0
|
|
||||||
cursor_mark = textbuffer.get_insert( )
|
|
||||||
cursor_iter = textbuffer.get_iter_at_mark( cursor_mark )
|
|
||||||
# determine this line's indent count
|
|
||||||
linestart_iter = cursor_iter.copy( )
|
|
||||||
linestart_iter.set_line_offset( 0 )
|
|
||||||
spaceend_iter = linestart_iter.copy( )
|
|
||||||
while (not spaceend_iter.ends_line( )
|
|
||||||
and not spaceend_iter.is_end( )
|
|
||||||
and spaceend_iter.get_char( ).isspace( )):
|
|
||||||
spaceend_iter.forward_char( )
|
|
||||||
linebegin = textbuffer.get_text( linestart_iter, spaceend_iter ).expandtabs( )
|
|
||||||
indent_length = len( linebegin )
|
|
||||||
textbuffer.delete( linestart_iter, spaceend_iter )
|
|
||||||
textbuffer.insert( linestart_iter, u' ' * indent_length )
|
|
||||||
# start with the real work
|
|
||||||
cursor_iter = textbuffer.get_iter_at_mark( cursor_mark )
|
|
||||||
if (not cursor_iter.starts_line( )):
|
|
||||||
# find last char before cursor
|
|
||||||
lastchar_iter = cursor_iter.copy( )
|
|
||||||
lastchar_iter.backward_char( )
|
|
||||||
if (lastchar_iter.get_char( ) == u":"):
|
|
||||||
indent_length += 4
|
|
||||||
# now find indent of next line...
|
|
||||||
textbuffer.insert( cursor_iter, u'\n' + (u' ' * indent_length) )
|
|
||||||
widget.scroll_to_mark( cursor_mark, 0.0, 0 )
|
|
||||||
self.textviews_moved( widget )
|
|
||||||
return 1
|
|
||||||
|
|
||||||
#self.textviews_moved(widget)
|
#self.textviews_moved(widget)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -1399,7 +1427,22 @@ class ScriptWidgets:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
if modified:
|
if modified:
|
||||||
print "ToDo: Save First Dialog"
|
question = gtk.MessageDialog(parent=self.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=gtk.BUTTONS_NONE)
|
||||||
|
question.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
||||||
|
question.add_button(gtk.STOCK_NO, gtk.RESPONSE_NO)
|
||||||
|
question.add_button(gtk.STOCK_YES, gtk.RESPONSE_YES)
|
||||||
|
question.set_markup("The file has been changed. Save changes?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response == gtk.RESPONSE_YES:
|
||||||
|
self.save_file()
|
||||||
|
elif response == gtk.RESPONSE_CANCEL:
|
||||||
|
return 0
|
||||||
|
|
||||||
def response( self, response_id, script_widget ):
|
def response( self, response_id, script_widget ):
|
||||||
if response_id == gtk.RESPONSE_OK:
|
if response_id == gtk.RESPONSE_OK:
|
||||||
@ -1491,7 +1534,17 @@ class ScriptWidgets:
|
|||||||
|
|
||||||
absfilename = os.path.abspath( file_name )
|
absfilename = os.path.abspath( file_name )
|
||||||
if os.access( file_name, os.F_OK ):
|
if os.access( file_name, os.F_OK ):
|
||||||
print "ToDo: Overwrite file question"
|
question = gtk.MessageDialog(parent=script_widget.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=(gtk.BUTTONS_YES_NO))
|
||||||
|
question.set_markup("The file already exists. Do you want to overwrite the existing file and delete its contents?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response != gtk.RESPONSE_YES:
|
||||||
|
return True
|
||||||
|
|
||||||
current_page = script_widget.main_notebook.get_current_page( )
|
current_page = script_widget.main_notebook.get_current_page( )
|
||||||
if current_page == 0:
|
if current_page == 0:
|
||||||
@ -1549,6 +1602,147 @@ class ScriptWidgets:
|
|||||||
|
|
||||||
self.main_notebook.set_current_page( current_page )
|
self.main_notebook.set_current_page( current_page )
|
||||||
|
|
||||||
|
def undo(self, widget=None, Data=None ):
|
||||||
|
if not self.editing_state:
|
||||||
|
return 0
|
||||||
|
current_page = self.main_notebook.get_current_page( )
|
||||||
|
if current_page == 0:
|
||||||
|
self.experiment_script_textview.do_undo(self.experiment_script_textview)
|
||||||
|
elif current_page == 1:
|
||||||
|
self.data_handling_textview.do_undo(self.data_handling_textview)
|
||||||
|
self.set_toolbuttons_status()
|
||||||
|
|
||||||
|
def redo(self, widget=None, Data=None ):
|
||||||
|
if not self.editing_state:
|
||||||
|
return 0
|
||||||
|
current_page = self.main_notebook.get_current_page( )
|
||||||
|
if current_page == 0:
|
||||||
|
self.experiment_script_textview.do_redo(self.experiment_script_textview)
|
||||||
|
elif current_page == 1:
|
||||||
|
self.data_handling_textview.do_redo(self.data_handling_textview)
|
||||||
|
self.set_toolbuttons_status()
|
||||||
|
|
||||||
|
def search(self, widget=None, Data=None):
|
||||||
|
def response(script_widget, response_id, damsw, tb ):
|
||||||
|
if response_id != -1 and response_id != 1:
|
||||||
|
script_widget.destroy()
|
||||||
|
return True
|
||||||
|
|
||||||
|
current_page = damsw.main_notebook.get_current_page( )
|
||||||
|
|
||||||
|
startiter = None
|
||||||
|
enditer = None
|
||||||
|
logview = None
|
||||||
|
logbuffer = None
|
||||||
|
|
||||||
|
if current_page == 0:
|
||||||
|
if damsw.experiment_script_textbuffer.get_has_selection():
|
||||||
|
startiter, enditer = damsw.experiment_script_textbuffer.get_selection_bounds()
|
||||||
|
else:
|
||||||
|
mark = damsw.experiment_script_textbuffer.get_insert()
|
||||||
|
startiter = damsw.experiment_script_textbuffer.get_iter_at_mark(mark)
|
||||||
|
enditer = startiter
|
||||||
|
elif current_page == 1:
|
||||||
|
if damsw.data_handling_textbuffer.get_has_selection():
|
||||||
|
startiter, enditer = damsw.data_handling_textbuffer.get_selection_bounds()
|
||||||
|
else:
|
||||||
|
mark = damsw.data_handling_textbuffer.get_insert()
|
||||||
|
startiter = damsw.data_handling_textbuffer.get_iter_at_mark(mark)
|
||||||
|
enditer = startiter
|
||||||
|
elif current_page == 3:
|
||||||
|
logview = damsw.xml_gui.get_widget( "messages_textview" )
|
||||||
|
logbuffer = logview.get_buffer()
|
||||||
|
if logbuffer.get_has_selection():
|
||||||
|
startiter, enditer = logbuffer.get_selection_bounds()
|
||||||
|
else:
|
||||||
|
mark = logbuffer.get_insert()
|
||||||
|
startiter = logbuffer.get_iter_at_mark(mark)
|
||||||
|
enditer = startiter
|
||||||
|
else:
|
||||||
|
script_widget.destroy()
|
||||||
|
return True
|
||||||
|
|
||||||
|
searchstring = tb.get_text()
|
||||||
|
|
||||||
|
if len(searchstring) > 0:
|
||||||
|
|
||||||
|
match_start = None
|
||||||
|
match_end = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
if response_id == -1:
|
||||||
|
match_start, match_end = startiter.backward_search(searchstring, gtk.TEXT_SEARCH_TEXT_ONLY)
|
||||||
|
elif response_id == 1:
|
||||||
|
match_start, match_end = enditer.forward_search(searchstring, gtk.TEXT_SEARCH_TEXT_ONLY)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if match_start is not None and match_end is not None:
|
||||||
|
if current_page == 0:
|
||||||
|
damsw.experiment_script_textbuffer.select_range(match_start, match_end)
|
||||||
|
damsw.experiment_script_textview.scroll_to_iter(match_start, 0.2)
|
||||||
|
damsw.textviews_moved(damsw.experiment_script_textview)
|
||||||
|
elif current_page == 1:
|
||||||
|
damsw.data_handling_textbuffer.select_range(match_start, match_end)
|
||||||
|
damsw.data_handling_textview.scroll_to_iter(match_start, 0.2)
|
||||||
|
damsw.textviews_moved(damsw.data_handling_textview)
|
||||||
|
elif current_page == 3:
|
||||||
|
logbuffer.select_range(match_start, match_end)
|
||||||
|
logview.scroll_to_iter(match_start, 0.2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
dialog = gtk.Dialog(title="Search", parent=self.xml_gui.get_widget("main_window"), flags=gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE, "Find last", -1, "Find next", 1))
|
||||||
|
cont = dialog.get_content_area()
|
||||||
|
|
||||||
|
markedstring = ""
|
||||||
|
current_page = self.main_notebook.get_current_page( )
|
||||||
|
|
||||||
|
startit = None
|
||||||
|
endit = None
|
||||||
|
logbuffer = None
|
||||||
|
|
||||||
|
if current_page == 0:
|
||||||
|
if self.experiment_script_textbuffer.get_has_selection():
|
||||||
|
startit, endit = self.experiment_script_textbuffer.get_selection_bounds()
|
||||||
|
markedstring = self.experiment_script_textbuffer.get_text(startit, endit)
|
||||||
|
elif current_page == 1:
|
||||||
|
if self.data_handling_textbuffer.get_has_selection():
|
||||||
|
startit, endit = self.data_handling_textbuffer.get_selection_bounds()
|
||||||
|
markedstring = self.data_handling_textbuffer.get_text(startit, endit)
|
||||||
|
elif current_page == 3:
|
||||||
|
logview = self.xml_gui.get_widget( "messages_textview" )
|
||||||
|
logbuffer = logview.get_buffer()
|
||||||
|
if logbuffer.get_has_selection():
|
||||||
|
startit, endit = logbuffer.get_selection_bounds()
|
||||||
|
markedstring = logbuffer.get_text(startit, endit)
|
||||||
|
|
||||||
|
markedstring = markedstring.strip()
|
||||||
|
|
||||||
|
textbox = gtk.Entry()
|
||||||
|
textbox.set_text(markedstring)
|
||||||
|
|
||||||
|
cont.add(textbox)
|
||||||
|
|
||||||
|
dialog.set_default_response(1)
|
||||||
|
dialog.connect("response", response, self, textbox)
|
||||||
|
dialog.set_resizable(False)
|
||||||
|
|
||||||
|
dialog.show_all()
|
||||||
|
|
||||||
|
if startit is not None and endit is not None:
|
||||||
|
if current_page == 0:
|
||||||
|
self.experiment_script_textbuffer.select_range(startit, endit)
|
||||||
|
elif current_page == 1:
|
||||||
|
self.data_handling_textbuffer.select_range(startit, endit)
|
||||||
|
elif current_page == 3:
|
||||||
|
logbuffer.select_range(startit, endit)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def new_file( self, widget, Data=None ):
|
def new_file( self, widget, Data=None ):
|
||||||
|
|
||||||
if not self.editing_state:
|
if not self.editing_state:
|
||||||
@ -1556,12 +1750,44 @@ class ScriptWidgets:
|
|||||||
current_page = self.main_notebook.get_current_page( )
|
current_page = self.main_notebook.get_current_page( )
|
||||||
if current_page == 0:
|
if current_page == 0:
|
||||||
if self.experiment_script_textbuffer.get_modified( ):
|
if self.experiment_script_textbuffer.get_modified( ):
|
||||||
print "ToDo: Save before Clear Dialog"
|
question = gtk.MessageDialog(parent=self.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=gtk.BUTTONS_NONE)
|
||||||
|
question.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
||||||
|
question.add_button(gtk.STOCK_NO, gtk.RESPONSE_NO)
|
||||||
|
question.add_button(gtk.STOCK_YES, gtk.RESPONSE_YES)
|
||||||
|
question.set_markup("The file has been changed. Save changes?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response == gtk.RESPONSE_YES:
|
||||||
|
self.save_file()
|
||||||
|
elif response == gtk.RESPONSE_CANCEL:
|
||||||
|
return 0
|
||||||
|
|
||||||
self.set_scripts( "", None )
|
self.set_scripts( "", None )
|
||||||
self.exp_script_filename = None
|
self.exp_script_filename = None
|
||||||
elif current_page == 1:
|
elif current_page == 1:
|
||||||
if self.data_handling_textbuffer.get_modified( ):
|
if self.data_handling_textbuffer.get_modified( ):
|
||||||
print "ToDo: Save before Clear Dialog"
|
question = gtk.MessageDialog(parent=self.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=gtk.BUTTONS_NONE)
|
||||||
|
question.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
||||||
|
question.add_button(gtk.STOCK_NO, gtk.RESPONSE_NO)
|
||||||
|
question.add_button(gtk.STOCK_YES, gtk.RESPONSE_YES)
|
||||||
|
question.set_markup("The file has been changed. Save changes?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response == gtk.RESPONSE_YES:
|
||||||
|
self.save_file()
|
||||||
|
elif response == gtk.RESPONSE_CANCEL:
|
||||||
|
return 0
|
||||||
|
|
||||||
self.set_scripts( None, "" )
|
self.set_scripts( None, "" )
|
||||||
self.res_script_filename = None
|
self.res_script_filename = None
|
||||||
self.set_toolbuttons_status( )
|
self.set_toolbuttons_status( )
|
||||||
@ -2440,7 +2666,17 @@ class MonitorWidgets:
|
|||||||
|
|
||||||
absfilename = os.path.abspath( file_name )
|
absfilename = os.path.abspath( file_name )
|
||||||
if os.access( file_name, os.F_OK ):
|
if os.access( file_name, os.F_OK ):
|
||||||
log( "ToDo: Overwrite file question" )
|
question = gtk.MessageDialog(parent=script_widget.xml_gui.get_widget( "main_window"),
|
||||||
|
type=gtk.MESSAGE_WARNING,
|
||||||
|
flags=gtk.DIALOG_MODAL,
|
||||||
|
buttons=(gtk.BUTTONS_YES_NO))
|
||||||
|
question.set_markup("The file already exists. Do you want to overwrite the existing file and delete its contents?")
|
||||||
|
|
||||||
|
response = question.run()
|
||||||
|
question.destroy()
|
||||||
|
|
||||||
|
if response != gtk.RESPONSE_YES:
|
||||||
|
return True
|
||||||
|
|
||||||
textfile = file( absfilename, "w" )
|
textfile = file( absfilename, "w" )
|
||||||
tmpfile.seek( 0 )
|
tmpfile.seek( 0 )
|
||||||
|
@ -26,6 +26,11 @@ class ExperimentHandling(threading.Thread):
|
|||||||
if self.quit_flag.isSet():
|
if self.quit_flag.isSet():
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
|
def sleep(self, seconds):
|
||||||
|
self.quit_flag.wait(seconds)
|
||||||
|
if self.quit_flag.isSet():
|
||||||
|
raise StopIteration
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
dataspace={}
|
dataspace={}
|
||||||
exp_classes = __import__('damaris.experiments', dataspace, dataspace, ['Experiment'])
|
exp_classes = __import__('damaris.experiments', dataspace, dataspace, ['Experiment'])
|
||||||
@ -36,6 +41,7 @@ class ExperimentHandling(threading.Thread):
|
|||||||
|
|
||||||
dataspace["data"]=self.data
|
dataspace["data"]=self.data
|
||||||
dataspace["synchronize"]=self.synchronize
|
dataspace["synchronize"]=self.synchronize
|
||||||
|
dataspace["sleep"]=self.sleep
|
||||||
self.raised_exception = None
|
self.raised_exception = None
|
||||||
self.location = None
|
self.location = None
|
||||||
exp_iterator=None
|
exp_iterator=None
|
||||||
@ -84,7 +90,7 @@ class ExperimentHandling(threading.Thread):
|
|||||||
if "__resultsinadvance" in self.data and self.data["__resultsinadvance"]+100<job.job_id:
|
if "__resultsinadvance" in self.data and self.data["__resultsinadvance"]+100<job.job_id:
|
||||||
self.quit_flag.wait(0.05)
|
self.quit_flag.wait(0.05)
|
||||||
if self.quit_flag.isSet():
|
if self.quit_flag.isSet():
|
||||||
data_sapce=None
|
dataspace=None
|
||||||
exp_iterator=None
|
exp_iterator=None
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -99,6 +99,44 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkToolButton" id="toolbar_undo_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="tooltip" translatable="yes">Undo</property>
|
||||||
|
<property name="stock_id">gtk-undo</property>
|
||||||
|
<signal name="clicked" handler="on_toolbar_undo_button_clicked"/>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="homogeneous">True</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkToolButton" id="toolbar_redo_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="tooltip" translatable="yes">Redo</property>
|
||||||
|
<property name="stock_id">gtk-redo</property>
|
||||||
|
<signal name="clicked" handler="on_toolbar_redo_button_clicked"/>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="homogeneous">True</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkToolButton" id="toolbar_search_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="tooltip" translatable="yes">Search</property>
|
||||||
|
<property name="stock_id">gtk-find</property>
|
||||||
|
<signal name="clicked" handler="on_toolbar_search_button_clicked"/>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="homogeneous">True</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkSeparatorToolItem" id="separatortoolitem3">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
</widget>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkToolButton" id="toolbar_print_button">
|
<widget class="GtkToolButton" id="toolbar_print_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -259,7 +297,7 @@
|
|||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkTextView" id="experiment_script_textview">
|
<widget class="GtkSourceView" id="experiment_script_textview">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -361,7 +399,7 @@
|
|||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkTextView" id="data_handling_textview">
|
<widget class="GtkSourceView" id="data_handling_textview">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<signal name="event" handler="on_data_handling_textview_event"/>
|
<signal name="event" handler="on_data_handling_textview_event"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user