parameters: (dad, vbox_code_nodes, pref_dialog)
docstring: Preferences Dialog, Plain Text and Code Tab
docstring_summary: Preferences Dialog, Plain Text and Code Tab
docstring_tokens: Preferences Dialog Plain Text and Code Tab
function: def preferences_tab_plain_text_n_code(dad, vbox_code_nodes, pref_dialog):
      """Preferences Dialog, Plain Text and Code Tab"""
      for child in vbox_code_nodes.get_children(): child.destroy()
  
      vbox_syntax = gtk.VBox()
      hbox_style_scheme = gtk.HBox()
      hbox_style_scheme.set_spacing(4)
      label_style_scheme = gtk.Label(_("Style Scheme"))
      combobox_style_scheme = gtk.ComboBox(model=dad.style_scheme_liststore)
      cell = gtk.CellRendererText()
      combobox_style_scheme.pack_start(cell, True)
      combobox_style_scheme.add_attribute(cell, 'text', 0)
      combobox_style_scheme.set_active_iter(dad.get_combobox_iter_from_value(dad.style_scheme_liststore, 0, dad.style_scheme))
      hbox_style_scheme.pack_start(label_style_scheme, expand=False)
      hbox_style_scheme.pack_start(combobox_style_scheme)
      checkbutton_pt_show_white_spaces = gtk.CheckButton(_("Show White Spaces"))
      checkbutton_pt_show_white_spaces.set_active(dad.pt_show_white_spaces)
      checkbutton_pt_highl_curr_line = gtk.CheckButton(_("Highlight Current Line"))
      checkbutton_pt_highl_curr_line.set_active(dad.pt_highl_curr_line)
  
      vbox_syntax.pack_start(hbox_style_scheme, expand=False)
      vbox_syntax.pack_start(checkbutton_pt_show_white_spaces, expand=False)
      vbox_syntax.pack_start(checkbutton_pt_highl_curr_line, expand=False)
  
      frame_syntax = gtk.Frame(label="<b>"+_("Text Editor")+"</b>")
      frame_syntax.get_label_widget().set_use_markup(True)
      frame_syntax.set_shadow_type(gtk.SHADOW_NONE)
      align_syntax = gtk.Alignment()
      align_syntax.set_padding(3, 6, 6, 6)
      align_syntax.add(vbox_syntax)
      frame_syntax.add(align_syntax)
  
      vbox_code_nodes.pack_start(frame_syntax, expand=False)
      def on_combobox_style_scheme_changed(combobox):
          new_iter = combobox_style_scheme.get_active_iter()
          new_style = dad.style_scheme_liststore[new_iter][0]
          if new_style != dad.style_scheme:
              dad.style_scheme = new_style
              support.dialog_info_after_restart(pref_dialog)
      combobox_style_scheme.connect('changed', on_combobox_style_scheme_changed)
      def on_checkbutton_pt_show_white_spaces_toggled(checkbutton):
          dad.pt_show_white_spaces = checkbutton.get_active()
          if dad.syntax_highlighting != cons.RICH_TEXT_ID:
              dad.sourceview.set_draw_spaces(codeboxes.DRAW_SPACES_FLAGS if dad.pt_show_white_spaces else 0)
      checkbutton_pt_show_white_spaces.connect('toggled', on_checkbutton_pt_show_white_spaces_toggled)
      def on_checkbutton_pt_highl_curr_line_toggled(checkbutton):
          dad.pt_highl_curr_line = checkbutton.get_active()
          if dad.syntax_highlighting != cons.RICH_TEXT_ID:
              dad.sourceview.set_highlight_current_line(dad.pt_highl_curr_line)
      checkbutton_pt_highl_curr_line.connect('toggled', on_checkbutton_pt_highl_curr_line_toggled)
  
      liststore = gtk.ListStore(str, str, str)
      treeview = gtk.TreeView(liststore)
      treeview.set_headers_visible(False)
      treeview.set_size_request(300, 200)
      renderer_pixbuf = gtk.CellRendererPixbuf()
      renderer_text_key = gtk.CellRendererText()
      renderer_text_val = gtk.CellRendererText()
      renderer_text_val.set_property('editable', True)
      def on_table_cell_edited(cell, path, new_text):
          if liststore[path][2] != new_text:
              liststore[path][2] = new_text
              key = liststore[path][1]
              dad.custom_codexec_type[key] = new_text
      renderer_text_val.connect('edited', on_table_cell_edited)
      column_key = gtk.TreeViewColumn()
      column_key.pack_start(renderer_pixbuf, False)
      column_key.pack_start(renderer_text_key, True)
      column_key.set_attributes(renderer_pixbuf, stock_id=0)
      column_key.set_attributes(renderer_text_key, text=1)
      column_val = gtk.TreeViewColumn("", renderer_text_val, text=2)
      treeview.append_column(column_key)
      treeview.append_column(column_val)
      treeviewselection = treeview.get_selection()
      scrolledwindow = gtk.ScrolledWindow()
      scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
      scrolledwindow.add(treeview)
  
      button_add = gtk.Button()
      button_add.set_image(gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON))
      button_add.set_tooltip_text(_("Add"))
      button_reset_cmds = gtk.Button()
      button_reset_cmds.set_image(gtk.image_new_from_stock(gtk.STOCK_UNDO, gtk.ICON_SIZE_BUTTON))
      button_reset_cmds.set_tooltip_text(_("Reset to Default"))
      vbox_buttons = gtk.VBox()
      vbox_buttons.pack_start(button_add, expand=False)
      vbox_buttons.pack_start(gtk.Label(), expand=True)
      vbox_buttons.pack_start(button_reset_cmds, expand=False)
  
      vbox_codexec = gtk.VBox()
      hbox_term_run = gtk.HBox()
      entry_term_run = gtk.Entry()
      entry_term_run.set_text(get_code_exec_term_run(dad))
      button_reset_term = gtk.Button()
      button_reset_term.set_image(gtk.image_new_from_stock(gtk.STOCK_UNDO, gtk.ICON_SIZE_BUTTON))
      button_reset_term.set_tooltip_text(_("Reset to Default"))
      hbox_term_run.pack_start(entry_term_run, expand=True)
      hbox_term_run.pack_start(button_reset_term, expand=False)
      hbox_cmd_per_type = gtk.HBox()
      hbox_cmd_per_type.pack_start(scrolledwindow, expand=True)
      hbox_cmd_per_type.pack_start(vbox_buttons, expand=False)
  
      label = gtk.Label("<b>"+_("Command per Node/CodeBox Type")+"</b>")
      label.set_use_markup(True)
      vbox_codexec.pack_start(label, expand=False)
      vbox_codexec.pack_start(hbox_cmd_per_type, expand=True)
      label = gtk.Label("<b>"+_("Terminal Command")+"</b>")
      label.set_use_markup(True)
      vbox_codexec.pack_start(label, expand=False)
      vbox_codexec.pack_start(hbox_term_run, expand=False)
  
      frame_codexec = gtk.Frame(label="<b>"+_("Code Execution")+"</b>")
      frame_codexec.get_label_widget().set_use_markup(True)
      frame_codexec.set_shadow_type(gtk.SHADOW_NONE)
      align_codexec = gtk.Alignment()
      align_codexec.set_padding(3, 6, 6, 6)
      align_codexec.add(vbox_codexec)
      frame_codexec.add(align_codexec)
  
      def liststore_append_element(key, val=None):
          stock_id = get_stock_id_for_code_type(key)
          if not val:
              val = get_code_exec_type_cmd(dad, key)
          liststore.append((stock_id, key, val))
  
      def populate_liststore():
          liststore.clear()
          all_codexec_keys = get_code_exec_type_keys(dad)
          for key in all_codexec_keys:
              liststore_append_element(key)
  
      vbox_code_nodes.pack_start(frame_codexec, expand=True)
      def on_entry_term_run_changed(entry):
          dad.custom_codexec_term = entry.get_text()
      entry_term_run.connect('changed', on_entry_term_run_changed)
      def on_button_add_clicked(button):
          icon_n_key_list = []
          all_codexec_keys = get_code_exec_type_keys(dad)
          for key in dad.available_languages:
              if not key in all_codexec_keys:
                  stock_id = get_stock_id_for_code_type(key)
                  icon_n_key_list.append([key, stock_id, key])
          sel_key = support.dialog_choose_element_in_list(dad.window, _("Select Element to Add"), [], "", icon_n_key_list)
          if sel_key:
              default_type_command = "REPLACE_ME %s" % CODE_EXEC_TMP_SRC
              liststore_append_element(sel_key, default_type_command)
              dad.custom_codexec_type[sel_key] = default_type_command
      button_add.connect('clicked', on_button_add_clicked)
      def on_button_reset_cmds_clicked(button, type_str):
          warning_label = "<b>"+_("Are you sure to Reset to Default?")+"</b>"
          response = support.dialog_question_warning(pref_dialog, warning_label)
          if response == gtk.RESPONSE_ACCEPT:
              if type_str == "cmds":
                  dad.custom_codexec_type.clear()
                  populate_liststore()
              elif type_str == "term":
                  dad.custom_codexec_term = None
                  entry_term_run.set_text(get_code_exec_term_run(dad))
      button_reset_cmds.connect('clicked', on_button_reset_cmds_clicked, "cmds")
      button_reset_term.connect('clicked', on_button_reset_cmds_clicked, "term")
  
      populate_liststore()
function_tokens: def preferences_tab_plain_text_n_code ( dad , vbox_code_nodes , pref_dialog ) : for child in vbox_code_nodes . get_children ( ) : child . destroy ( ) vbox_syntax = gtk . VBox ( ) hbox_style_scheme = gtk . HBox ( ) hbox_style_scheme . set_spacing ( 4 ) label_style_scheme = gtk . Label ( _ ( "Style Scheme" ) ) combobox_style_scheme = gtk . ComboBox ( model = dad . style_scheme_liststore ) cell = gtk . CellRendererText ( ) combobox_style_scheme . pack_start ( cell , True ) combobox_style_scheme . add_attribute ( cell , 'text' , 0 ) combobox_style_scheme . set_active_iter ( dad . get_combobox_iter_from_value ( dad . style_scheme_liststore , 0 , dad . style_scheme ) ) hbox_style_scheme . pack_start ( label_style_scheme , expand = False ) hbox_style_scheme . pack_start ( combobox_style_scheme ) checkbutton_pt_show_white_spaces = gtk . CheckButton ( _ ( "Show White Spaces" ) ) checkbutton_pt_show_white_spaces . set_active ( dad . pt_show_white_spaces ) checkbutton_pt_highl_curr_line = gtk . CheckButton ( _ ( "Highlight Current Line" ) ) checkbutton_pt_highl_curr_line . set_active ( dad . pt_highl_curr_line ) vbox_syntax . pack_start ( hbox_style_scheme , expand = False ) vbox_syntax . pack_start ( checkbutton_pt_show_white_spaces , expand = False ) vbox_syntax . pack_start ( checkbutton_pt_highl_curr_line , expand = False ) frame_syntax = gtk . Frame ( label = "<b>" + _ ( "Text Editor" ) + "</b>" ) frame_syntax . get_label_widget ( ) . set_use_markup ( True ) frame_syntax . set_shadow_type ( gtk . SHADOW_NONE ) align_syntax = gtk . Alignment ( ) align_syntax . set_padding ( 3 , 6 , 6 , 6 ) align_syntax . add ( vbox_syntax ) frame_syntax . add ( align_syntax ) vbox_code_nodes . pack_start ( frame_syntax , expand = False ) def on_combobox_style_scheme_changed ( combobox ) : new_iter = combobox_style_scheme . get_active_iter ( ) new_style = dad . style_scheme_liststore [ new_iter ] [ 0 ] if new_style != dad . style_scheme : dad . style_scheme = new_style support . dialog_info_after_restart ( pref_dialog ) combobox_style_scheme . connect ( 'changed' , on_combobox_style_scheme_changed ) def on_checkbutton_pt_show_white_spaces_toggled ( checkbutton ) : dad . pt_show_white_spaces = checkbutton . get_active ( ) if dad . syntax_highlighting != cons . RICH_TEXT_ID : dad . sourceview . set_draw_spaces ( codeboxes . DRAW_SPACES_FLAGS if dad . pt_show_white_spaces else 0 ) checkbutton_pt_show_white_spaces . connect ( 'toggled' , on_checkbutton_pt_show_white_spaces_toggled ) def on_checkbutton_pt_highl_curr_line_toggled ( checkbutton ) : dad . pt_highl_curr_line = checkbutton . get_active ( ) if dad . syntax_highlighting != cons . RICH_TEXT_ID : dad . sourceview . set_highlight_current_line ( dad . pt_highl_curr_line ) checkbutton_pt_highl_curr_line . connect ( 'toggled' , on_checkbutton_pt_highl_curr_line_toggled ) liststore = gtk . ListStore ( str , str , str ) treeview = gtk . TreeView ( liststore ) treeview . set_headers_visible ( False ) treeview . set_size_request ( 300 , 200 ) renderer_pixbuf = gtk . CellRendererPixbuf ( ) renderer_text_key = gtk . CellRendererText ( ) renderer_text_val = gtk . CellRendererText ( ) renderer_text_val . set_property ( 'editable' , True ) def on_table_cell_edited ( cell , path , new_text ) : if liststore [ path ] [ 2 ] != new_text : liststore [ path ] [ 2 ] = new_text key = liststore [ path ] [ 1 ] dad . custom_codexec_type [ key ] = new_text renderer_text_val . connect ( 'edited' , on_table_cell_edited ) column_key = gtk . TreeViewColumn ( ) column_key . pack_start ( renderer_pixbuf , False ) column_key . pack_start ( renderer_text_key , True ) column_key . set_attributes ( renderer_pixbuf , stock_id = 0 ) column_key . set_attributes ( renderer_text_key , text = 1 ) column_val = gtk . TreeViewColumn ( "" , renderer_text_val , text = 2 ) treeview . append_column ( column_key ) treeview . append_column ( column_val ) treeviewselection = treeview . get_selection ( ) scrolledwindow = gtk . ScrolledWindow ( ) scrolledwindow . set_policy ( gtk . POLICY_AUTOMATIC , gtk . POLICY_AUTOMATIC ) scrolledwindow . add ( treeview ) button_add = gtk . Button ( ) button_add . set_image ( gtk . image_new_from_stock ( gtk . STOCK_ADD , gtk . ICON_SIZE_BUTTON ) ) button_add . set_tooltip_text ( _ ( "Add" ) ) button_reset_cmds = gtk . Button ( ) button_reset_cmds . set_image ( gtk . image_new_from_stock ( gtk . STOCK_UNDO , gtk . ICON_SIZE_BUTTON ) ) button_reset_cmds . set_tooltip_text ( _ ( "Reset to Default" ) ) vbox_buttons = gtk . VBox ( ) vbox_buttons . pack_start ( button_add , expand = False ) vbox_buttons . pack_start ( gtk . Label ( ) , expand = True ) vbox_buttons . pack_start ( button_reset_cmds , expand = False ) vbox_codexec = gtk . VBox ( ) hbox_term_run = gtk . HBox ( ) entry_term_run = gtk . Entry ( ) entry_term_run . set_text ( get_code_exec_term_run ( dad ) ) button_reset_term = gtk . Button ( ) button_reset_term . set_image ( gtk . image_new_from_stock ( gtk . STOCK_UNDO , gtk . ICON_SIZE_BUTTON ) ) button_reset_term . set_tooltip_text ( _ ( "Reset to Default" ) ) hbox_term_run . pack_start ( entry_term_run , expand = True ) hbox_term_run . pack_start ( button_reset_term , expand = False ) hbox_cmd_per_type = gtk . HBox ( ) hbox_cmd_per_type . pack_start ( scrolledwindow , expand = True ) hbox_cmd_per_type . pack_start ( vbox_buttons , expand = False ) label = gtk . Label ( "<b>" + _ ( "Command per Node/CodeBox Type" ) + "</b>" ) label . set_use_markup ( True ) vbox_codexec . pack_start ( label , expand = False ) vbox_codexec . pack_start ( hbox_cmd_per_type , expand = True ) label = gtk . Label ( "<b>" + _ ( "Terminal Command" ) + "</b>" ) label . set_use_markup ( True ) vbox_codexec . pack_start ( label , expand = False ) vbox_codexec . pack_start ( hbox_term_run , expand = False ) frame_codexec = gtk . Frame ( label = "<b>" + _ ( "Code Execution" ) + "</b>" ) frame_codexec . get_label_widget ( ) . set_use_markup ( True ) frame_codexec . set_shadow_type ( gtk . SHADOW_NONE ) align_codexec = gtk . Alignment ( ) align_codexec . set_padding ( 3 , 6 , 6 , 6 ) align_codexec . add ( vbox_codexec ) frame_codexec . add ( align_codexec ) def liststore_append_element ( key , val = None ) : stock_id = get_stock_id_for_code_type ( key ) if not val : val = get_code_exec_type_cmd ( dad , key ) liststore . append ( ( stock_id , key , val ) ) def populate_liststore ( ) : liststore . clear ( ) all_codexec_keys = get_code_exec_type_keys ( dad ) for key in all_codexec_keys : liststore_append_element ( key ) vbox_code_nodes . pack_start ( frame_codexec , expand = True ) def on_entry_term_run_changed ( entry ) : dad . custom_codexec_term = entry . get_text ( ) entry_term_run . connect ( 'changed' , on_entry_term_run_changed ) def on_button_add_clicked ( button ) : icon_n_key_list = [ ] all_codexec_keys = get_code_exec_type_keys ( dad ) for key in dad . available_languages : if not key in all_codexec_keys : stock_id = get_stock_id_for_code_type ( key ) icon_n_key_list . append ( [ key , stock_id , key ] ) sel_key = support . dialog_choose_element_in_list ( dad . window , _ ( "Select Element to Add" ) , [ ] , "" , icon_n_key_list ) if sel_key : default_type_command = "REPLACE_ME %s" % CODE_EXEC_TMP_SRC liststore_append_element ( sel_key , default_type_command ) dad . custom_codexec_type [ sel_key ] = default_type_command button_add . connect ( 'clicked' , on_button_add_clicked ) def on_button_reset_cmds_clicked ( button , type_str ) : warning_label = "<b>" + _ ( "Are you sure to Reset to Default?" ) + "</b>" response = support . dialog_question_warning ( pref_dialog , warning_label ) if response == gtk . RESPONSE_ACCEPT : if type_str == "cmds" : dad . custom_codexec_type . clear ( ) populate_liststore ( ) elif type_str == "term" : dad . custom_codexec_term = None entry_term_run . set_text ( get_code_exec_term_run ( dad ) ) button_reset_cmds . connect ( 'clicked' , on_button_reset_cmds_clicked , "cmds" ) button_reset_term . connect ( 'clicked' , on_button_reset_cmds_clicked , "term" ) populate_liststore ( )