Merge changes regarding Tab/ space management in editor (use 4 spaces instead of tab like before).

This commit is contained in:
Joachim Beerwerth 2018-03-29 15:07:18 +02:00
parent cc812f58c9
commit 591cf8bdea

View File

@ -53,9 +53,11 @@ matplotlib.rcParams[ "axes.formatter.limits" ] = "-3,3"
if matplotlib.rcParams[ "backend" ] == "GTK": if matplotlib.rcParams[ "backend" ] == "GTK":
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
max_points_to_display = 0 # no limit max_points_to_display = 0 # no limit
elif matplotlib.rcParams[ "backend" ] == "GTKCairo": elif matplotlib.rcParams[ "backend" ] == "GTKCairo":
from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
max_points_to_display = 1 << 14 # cairo cannot render longer paths than 18??? max_points_to_display = 1 << 14 # cairo cannot render longer paths than 18???
else: else:
# default # default
@ -181,7 +183,7 @@ class DamarisGUI:
# my notebook # my notebook
self.main_notebook = self.xml_gui.get_widget( "main_notebook" ) self.main_notebook = self.xml_gui.get_widget( "main_notebook" )
self.log = LogWindow( self.xml_gui ) self.log = LogWindow( self.xml_gui , self)
self.sw = ScriptWidgets( self.xml_gui ) self.sw = ScriptWidgets( self.xml_gui )
@ -277,11 +279,14 @@ class DamarisGUI:
self.toolbar_run_button.emit("clicked") self.toolbar_run_button.emit("clicked")
gtk.main( ) gtk.main( )
gtk.gdk.threads_leave( ) gtk.gdk.threads_leave( )
self.si = None self.si = None
self.sw = None self.sw = None
self.config = None self.config = None
self.xml_gui = None self.xml_gui = None
# event handling: the real acitons in gui programming
# first global events # first global events
def quit_event( self, widget, data=None ): def quit_event( self, widget, data=None ):
@ -684,7 +689,7 @@ class DamarisGUI:
# keep data to display but throw away everything else # keep data to display but throw away everything else
self.si = None self.si = None
# delete locak file so that other experiment can start # delete lock file so that other experiment can start
self.lockfile.del_experiment(self.id) self.lockfile.del_experiment(self.id)
return False return False
@ -1017,7 +1022,7 @@ class DamarisGUI:
# check generic debian location # check generic debian location
self.doc_urls[ "Python DAMARIS" ] = "file:///usr/share/doc/python-damaris/html/index.html" self.doc_urls[ "Python DAMARIS" ] = "file:///usr/share/doc/python-damaris/html/index.html"
else: else:
self.doc_urls[ "Python DAMARIS" ] = "http://damaris.berlios.de/wiki/index.php/Tutorial" self.doc_urls[ "Python DAMARIS" ] = "https://element.fkp.physik.tu-darmstadt.de/damaris_cms/index.php?id=documentation"
self.doc_browser = None self.doc_browser = None
@ -1087,10 +1092,12 @@ class LogWindow:
writes messages to the log window writes messages to the log window
""" """
def __init__( self, xml_gui ): def __init__( self, xml_gui, damaris_gui ):
self.xml_gui = xml_gui self.xml_gui = xml_gui
self.damaris_gui = damaris_gui
self.textview = self.xml_gui.get_widget( "messages_textview" ) self.textview = self.xml_gui.get_widget( "messages_textview" )
self.textview.connect( "key-press-event", self.textview_keypress)
self.textbuffer = self.textview.get_buffer( ) self.textbuffer = self.textview.get_buffer( )
self.logstream = log self.logstream = log
self.logstream.gui_log = self self.logstream.gui_log = self
@ -1113,6 +1120,14 @@ class LogWindow:
self.textbuffer.insert_at_cursor( date_tag + unicode( message ) ) self.textbuffer.insert_at_cursor( date_tag + unicode( message ) )
self.textview.scroll_to_mark( self.textbuffer.get_insert( ), 0.1 ) self.textview.scroll_to_mark( self.textbuffer.get_insert( ), 0.1 )
gtk.gdk.threads_leave( ) gtk.gdk.threads_leave( )
def textview_keypress( self, widget, event, data=None ):
if event.state & gtk.gdk.CONTROL_MASK != 0:
if event.keyval == gtk.gdk.keyval_from_name("f"):
self.damaris_gui.sw.search(None, None)
return True
return False
def __del__( self ): def __del__( self ):
self.logstream.gui_log = None self.logstream.gui_log = None
@ -1152,13 +1167,22 @@ class ScriptWidgets:
self.data_handling_textbuffer.set_language(langpython) self.data_handling_textbuffer.set_language(langpython)
self.data_handling_textbuffer.set_highlight_syntax(True) self.data_handling_textbuffer.set_highlight_syntax(True)
fontdesc = pango.FontDescription("monospace")
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_show_line_numbers(True)
self.experiment_script_textview.set_auto_indent(True) self.experiment_script_textview.set_auto_indent(True)
self.experiment_script_textview.set_insert_spaces_instead_of_tabs(True)
self.experiment_script_textview.set_tab_width(4)
self.experiment_script_textview.set_smart_home_end(True)
self.experiment_script_textview.modify_font(fontdesc)
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_show_line_numbers(True)
self.data_handling_textview.set_auto_indent(True) self.data_handling_textview.set_auto_indent(True)
self.data_handling_textview.set_insert_spaces_instead_of_tabs(True)
self.data_handling_textview.set_tab_width(4)
self.data_handling_textview.set_smart_home_end(True)
self.data_handling_textview.modify_font(fontdesc)
keywords = """for if else elif in print try finally except global lambda not or pass def 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 class import from as return yield while continue break assert None True False AccumulatedValue
@ -1482,10 +1506,62 @@ get_job_id get_description set_description get_xdata get_ydata set_xdate set_yda
elif event.keyval == gtk.gdk.keyval_from_name("f"): elif event.keyval == gtk.gdk.keyval_from_name("f"):
self.search(None, None) self.search(None, None)
return True return True
return 0 return False
#Handle Backspace (delete more than one space on line beginning)
if event.keyval == 0xFF08:
textbuffer = widget.get_buffer( )
if textbuffer.get_has_selection():
return False
cursor_mark = textbuffer.get_insert( )
cursor_iter = textbuffer.get_iter_at_mark( cursor_mark )
linestart_iter = cursor_iter.copy( )
linestart_iter.set_line_offset( 0 )
linebegin = textbuffer.get_text( linestart_iter, cursor_iter ).expandtabs(4)
if linebegin.isspace() and len(linebegin) > 0:
linebegin = u' ' * int((len( linebegin ) - 1) / 4) * 4
textbuffer.delete( linestart_iter, cursor_iter )
textbuffer.insert( linestart_iter, linebegin )
return True
elif event.keyval == 0xFF0D:
textbuffer = widget.get_buffer( )
if textbuffer.get_has_selection():
return False
cursor_mark = textbuffer.get_insert( )
cursor_iter = textbuffer.get_iter_at_mark( cursor_mark )
lastchar_iter = cursor_iter.copy()
lastchar = lastchar_iter.backward_char( )
if not lastchar_iter.get_char( ) == u":":
return False
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(4)
indent_length = int((int(len(linebegin)/4)+1)*4)
intext = u"\n" + (u" " * indent_length)
textbuffer.insert(cursor_iter, intext)
widget.scroll_to_mark( cursor_mark, 0.0, 0 )
return True
#self.textviews_moved(widget) #self.textviews_moved(widget)
return 0 return False
def load_file_as_unicode( self, script_filename ): def load_file_as_unicode( self, script_filename ):
script_file = file( script_filename, "rU" ) script_file = file( script_filename, "rU" )
@ -3216,7 +3292,7 @@ class ScriptInterface:
self.exp_writer = self.res_reader = self.back_driver = None self.exp_writer = self.res_reader = self.back_driver = None
if self.backend_executable is not None and self.backend_executable != "": if self.backend_executable is not None and self.backend_executable != "":
self.back_driver = BackendDriver.BackendDriver( self.backend_executable, spool_dir, clear_jobs, self.back_driver = BackendDriver.BackendDriver( self.backend_executable, spool_dir, clear_jobs,
clear_results) clear_results )
if self.exp_script: if self.exp_script:
self.exp_writer = self.back_driver.get_exp_writer( ) self.exp_writer = self.back_driver.get_exp_writer( )
if self.res_script: if self.res_script:
@ -3236,6 +3312,7 @@ class ScriptInterface:
self.data = DataPool( ) self.data = DataPool( )
def runScripts( self ): def runScripts( self ):
try: try:
# get script engines # get script engines
self.exp_handling = self.res_handling = None self.exp_handling = self.res_handling = None