parameters: (parent, config)
return_statement: return editor
docstring: Give the option to either choose an editor or use the default.
docstring_summary: Give the option to either choose an editor or use the default.
docstring_tokens: Give the option to either choose an editor or use the default .
function: def choose_editor(parent, config):
      """
      Give the option to either choose an editor or use the default.
      """
      if config.editor and find_executable(config.editor):
          return config.editor
  
      buttons = (
          'Choose Editor', Gtk.ResponseType.YES,
          'Use Default', Gtk.ResponseType.NO,
          Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL
      )
      response = MessageDialogWrapper(
          parent, message_type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.NONE,
          title='Choose Editor', markup='Would you like to choose the editor to use?',
          default_response=Gtk.ResponseType.YES, extra_buttons=buttons
      ).run_and_destroy()
  
      # Handle the initial default/choose/cancel response
      # User wants to choose the editor to use
      editor = ''
      if response == Gtk.ResponseType.YES:
          file_dialog = Gtk.FileChooserDialog(
              'Select an Editor...', None,
              Gtk.FileChooserAction.OPEN,
              ('gtk-cancel', Gtk.ResponseType.CANCEL,
               'gtk-open', Gtk.ResponseType.OK),
              transient_for=parent
          )
          file_dialog.set_select_multiple(False)
          file_dialog.set_local_only(True)
          file_dialog.set_current_folder('/usr/bin')
          try:
              if file_dialog.run() == Gtk.ResponseType.OK:
                  editor = file_dialog.get_filename()
          finally:
              file_dialog.hide()
  
      # Go with the default editor
      elif response == Gtk.ResponseType.NO:
          try:
              process = None
              if sys.platform.startswith('linux'):
                  process = find_executable('xdg-open')
              elif sys.platform.startswith('darwin'):
                  process = find_executable('open')
              if process is None:
                  raise ValueError("Can't find default editor executable")
              # Save
              editor = config.editor = process
          except Exception:
              Messages.send(
                  '>>> Unable to load the default editor. Please choose an editor.\n')
  
      if editor == '':
          Messages.send('>>> No editor selected.\n')
      return editor
function_tokens: def choose_editor ( parent , config ) : if config . editor and find_executable ( config . editor ) : return config . editor buttons = ( 'Choose Editor' , Gtk . ResponseType . YES , 'Use Default' , Gtk . ResponseType . NO , Gtk . STOCK_CANCEL , Gtk . ResponseType . CANCEL ) response = MessageDialogWrapper ( parent , message_type = Gtk . MessageType . QUESTION , buttons = Gtk . ButtonsType . NONE , title = 'Choose Editor' , markup = 'Would you like to choose the editor to use?' , default_response = Gtk . ResponseType . YES , extra_buttons = buttons ) . run_and_destroy ( ) # Handle the initial default/choose/cancel response # User wants to choose the editor to use editor = '' if response == Gtk . ResponseType . YES : file_dialog = Gtk . FileChooserDialog ( 'Select an Editor...' , None , Gtk . FileChooserAction . OPEN , ( 'gtk-cancel' , Gtk . ResponseType . CANCEL , 'gtk-open' , Gtk . ResponseType . OK ) , transient_for = parent ) file_dialog . set_select_multiple ( False ) file_dialog . set_local_only ( True ) file_dialog . set_current_folder ( '/usr/bin' ) try : if file_dialog . run ( ) == Gtk . ResponseType . OK : editor = file_dialog . get_filename ( ) finally : file_dialog . hide ( ) # Go with the default editor elif response == Gtk . ResponseType . NO : try : process = None if sys . platform . startswith ( 'linux' ) : process = find_executable ( 'xdg-open' ) elif sys . platform . startswith ( 'darwin' ) : process = find_executable ( 'open' ) if process is None : raise ValueError ( "Can't find default editor executable" ) # Save editor = config . editor = process except Exception : Messages . send ( '>>> Unable to load the default editor. Please choose an editor.\n' ) if editor == '' : Messages . send ( '>>> No editor selected.\n' ) return editor