Exemplo n.º 1
0
def create_from_parser(parser, source_path, **kwargs):
    auto_start = kwargs.get('auto_start', False)

    if hasattr(sys, 'frozen'):
        run_cmd = quote(source_path)
    else:
        run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))

    build_spec = {
        'language':
        kwargs.get('language', 'english'),
        'target':
        run_cmd,
        'program_name':
        kwargs.get('program_name')
        or os.path.basename(sys.argv[0]).replace('.py', ''),
        'program_description':
        kwargs.get('program_description', ''),
        'auto_start':
        kwargs.get('auto_start', False),
        'show_advanced':
        kwargs.get('advanced', True),
        'default_size':
        kwargs.get('default_size', (610, 530)),
        'num_required_cols':
        kwargs.get('required_cols', 1),
        'num_optional_cols':
        kwargs.get('optional_cols', 3),
        'manual_start':
        False,
        'layout_type':
        'flat',
        'monospace_display':
        kwargs.get('monospace_display', False),
        'image_dir':
        kwargs.get('image_dir'),
        'language_dir':
        kwargs.get('language_dir'),
        'progress_regex':
        kwargs.get('progress_regex'),
        'progress_expr':
        kwargs.get('progress_expr'),
        'disable_progress_bar_animation':
        kwargs.get('disable_progress_bar_animation'),
        'disable_stop_button':
        kwargs.get('disable_stop_button'),
        'group_by_type':
        kwargs.get('group_by_type', True)
    }

    if not auto_start:
        build_spec['program_description'] = parser.description or build_spec[
            'program_description']

        layout_data = argparse_to_json.convert(
            parser) if build_spec['show_advanced'] else list(
                layouts.basic_config.items())
        build_spec.update(layout_data)

    return build_spec
Exemplo n.º 2
0
    def performTest(self, configPath, assertionFunction):
        """
        Primary test harness.

        Instantiates the WX App, and spawns the threads
        required to make assertions against it
        """
        with open(configPath, 'r') as f:
            build_spec = json.loads(f.read())
            # swaps the absolute path stored by Gooey at write time
            # for a relative one based on our current test location
            target_pyfile = path.split(build_spec['target'].replace('"', ''))[-1]
            file_path = path.join(path.dirname(__file__), target_pyfile)
            run_cmd = '{} -u {}'.format(quote(sys.executable), quote(file_path))
            build_spec['language_dir'] = getResourcePath('languages')
            build_spec['target'] = run_cmd

        app = application.build_app(build_spec=build_spec)
        executor = futures.ThreadPoolExecutor(max_workers=1)
        testResult = executor.submit(assertionFunction, app, build_spec)
        app.MainLoop()
        testResult.result()
        # some extra padding time between starting/stopping the wx App
        app.Destroy()
        time.sleep(1)
Exemplo n.º 3
0
def get_target() -> str:
    """Returns an appropriate `target` argument for :func:`gooey.Gooey`.

    Returns:
       :func:`gooey.Gooey` `target` string.

    """

    import mimetypes
    import os
    from gooey.gui.util.quoting import quote

    run_cmd = sys.argv[0]

    # Run PyInstaller frozen executables as-is
    if hasattr(sys, 'frozen'):
        return quote(run_cmd)

    # Run Windows entry point launchers as-is
    if not os.path.exists(run_cmd) and os.path.exists(run_cmd + '.exe'):
        return quote(run_cmd + '.exe')

    # Run Linux/Unix entry points as-is
    if (not os.path.splitext(run_cmd)[1] and
        os.access(run_cmd, os.X_OK) and
        mimetypes.guess_type(run_cmd).startswith('text')):

        with open(run_cmd) as run_cmd_file:
            if 'sys.exit(load_entry_point' in run_cmd_file.read():
                return quote(run_cmd)

    # Default to Gooey run command
    return '{} -u {}'.format(quote(sys.executable), quote(run_cmd))
Exemplo n.º 4
0
def create_from_parser(parser, source_path, **kwargs):

    run_cmd = kwargs.get('target')
    if run_cmd is None:
        if hasattr(sys, 'frozen'):
            run_cmd = quote(source_path)
        else:
            run_cmd = '{} -u {}'.format(quote(sys.executable),
                                        quote(source_path))

    build_spec = {**kwargs, 'target': run_cmd}

    if build_spec['monospace_display']:
        warnings.warn(
            'Gooey Option `monospace_display` is a legacy option.\n'
            'See the terminal_font_x options for more flexible control '
            'over Gooey\'s text formatting')

    build_spec['program_description'] = build_spec[
        'program_description'] or parser.description or ''

    layout_data = (argparse_to_json.convert(parser, **build_spec)
                   if build_spec['advanced'] else default_layout.items())

    build_spec.update(layout_data)

    if len(build_spec['widgets']) > 1:
        # there are subparsers involved
        build_spec['show_sidebar'] = True

    return build_spec
Exemplo n.º 5
0
    def value(self):
        # TODO: split into stategy or subclass thingie
        if self.type == 'CheckBox':
            return self.commands[0] if self._value else None
        if self.type == 'RadioGroup':
            try:
                return self.commands[self._value.index(True)][0]
            except ValueError:
                return None
        if self.type == 'MultiFileChooser':
            value = ' '.join(
                quote(x) for x in self._value.split(os.pathsep) if x)
            if self.commands and value:
                return u'{} {}'.format(self.commands[0], value)
            return value or None
        # if self.type == 'TextField':
        #   if self.commands and self._value:
        #     return '{} {}'.format(self.commands[0], quote(self._value))
        #   else:
        #     return quote(self._value) if self._value else ''
        if self.type == 'CommandField':
            if self.commands and self._value:
                return u'{} {}'.format(self.commands[0], self._value)
            else:
                return self._value or None

        if self.type == 'Counter':
            '''
      Returns
        str(option_string * DropDown Value)
        e.g.
        -vvvvv
      '''
            if not str(self._value).isdigit():
                return None
            arg = str(self.commands[0]).replace('-', '')
            repeated_args = arg * int(self._value)
            return '-' + repeated_args

        if self.type == 'Dropdown':
            if self._value == 'Select Option':
                return None
            elif self.commands and self._value:
                return u'{} {}'.format(self.commands[0], quote(self._value))
            else:
                return quote(self._value) if self._value else ''
        else:
            if self.commands and self._value:
                if not self.nargs:
                    v = quote(self._value)
                else:
                    v = self._value
                return u'{0} {1}'.format(self.commands[0], v)
            else:
                if not self._value:
                    return None
                elif not self.nargs:
                    return quote(self._value)
                else:
                    return self._value
def dropdown(metadata, value):
    if value == 'Select Option':
        return None
    elif metadata['commands'] and value:
        return u'{} {}'.format(metadata['commands'][0], quote(value))
    else:
        return quote(value) if value else ''
Exemplo n.º 7
0
    def performTest(self, configPath, assertionFunction):
        """
        Primary test harness.

        Instantiates the WX App, and spawns the threads
        required to make assertions against it
        """
        with open(configPath, 'r') as f:
            build_spec = json.loads(f.read())
            # swaps the absolute path stored by Gooey at write time
            # for a relative one based on our current test location
            target_pyfile = path.split(build_spec['target'].replace('"', ''))[-1]
            file_path = path.join(path.dirname(__file__), target_pyfile)
            run_cmd = '{} -u {}'.format(quote(sys.executable), quote(file_path))
            build_spec['language_dir'] = getResourcePath('languages')
            build_spec['target'] = run_cmd

        app = application.build_app(build_spec=build_spec)
        executor = futures.ThreadPoolExecutor(max_workers=1)
        testResult = executor.submit(assertionFunction, app, build_spec)
        app.MainLoop()
        testResult.result()
        # some extra padding time between starting/stopping the wx App
        app.Destroy()
        time.sleep(1)
Exemplo n.º 8
0
def dropdown(metadata, value):
    if value == 'Select Option':
        return None
    elif metadata['commands'] and value:
        return u'{} {}'.format(metadata['commands'][0], quote(value))
    else:
        return quote(value) if value else ''
Exemplo n.º 9
0
  def value(self):
    # TODO: split into stategy or subclass thingie
    if self.type == 'CheckBox':
      return self.commands[0] if self._value else None
    if self.type == 'RadioGroup':
      try:
        return self.commands[self._value.index(True)][0]
      except ValueError:
        return None
    if self.type == 'MultiFileChooser':
      value = ' '.join(quote(x) for x in self._value.split(os.pathsep) if x)
      if self.commands and value:
        return u'{} {}'.format(self.commands[0], value)
      return value or None
    # if self.type == 'TextField':
    #   if self.commands and self._value:
    #     return '{} {}'.format(self.commands[0], quote(self._value))
    #   else:
    #     return quote(self._value) if self._value else ''
    if self.type == 'CommandField':
      if self.commands and self._value:
        return u'{} {}'.format(self.commands[0], self._value)
      else:
        return self._value or None

    if self.type == 'Counter':
      '''
      Returns
        str(option_string * DropDown Value)
        e.g.
        -vvvvv
      '''
      if not str(self._value).isdigit():
        return None
      arg = str(self.commands[0]).replace('-', '')
      repeated_args = arg * int(self._value)
      return '-' + repeated_args

    if self.type == 'Dropdown':
      if self._value == 'Select Option':
        return None
      elif self.commands and self._value:
        return u'{} {}'.format(self.commands[0], quote(self._value))
      else:
        return quote(self._value) if self._value else ''
    else:
      if self.commands and self._value:
        if not self.nargs:
          v = quote(self._value)
        else:
          v = self._value
        return u'{0} {1}'.format(self.commands[0], v)
      else:
        if not self._value:
          return None
        elif not self.nargs:
          return quote(self._value)
        else:
          return self._value
def general(metadata, value):
    if metadata.get('commands') and value:
        if not metadata.get('nargs'):
            v = quote(value)
        else:
            v = value
        return u'{0} {1}'.format(metadata['commands'][0], v)
    else:
        if not value:
            return None
        elif not metadata.get('nargs'):
            return quote(value)
        else:
            return value
Exemplo n.º 11
0
def general(metadata, value):
    if metadata.get('commands') and value:
        if not metadata.get('nargs'):
            v = quote(value)
        else:
            v = value
        return u'{0} {1}'.format(metadata['commands'][0], v)
    else:
        if not value:
            return None
        elif not metadata.get('nargs'):
            return quote(value)
        else:
            return value
Exemplo n.º 12
0
def create_from_parser(parser, source_path, **kwargs):
  show_config = kwargs.get('show_config', False)

  if hasattr(sys, 'frozen'):
    run_cmd = quote(source_path)
  else:
    run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))

  build_spec = {
    'language':             kwargs.get('language', 'english'),
    'target':               run_cmd,
    'program_name':         kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
    'program_description':  kwargs.get('program_description', ''),
    'show_config':          show_config,
    'show_advanced':        kwargs.get('advanced', True),
    'default_size':         kwargs.get('default_size', (610, 530)),
    'num_required_cols':    kwargs.get('required_cols', 1),
    'num_optional_cols':    kwargs.get('optional_cols', 3),
    'manual_start':         False,
    'layout_type':          'flat',
    'monospace_display':    kwargs.get('monospace_display', False),
    'image_dir':            kwargs.get('image_dir'),
    'language_dir':         kwargs.get('language_dir'),
    'progress_regex':       kwargs.get('progress_regex'),
    'progress_expr':        kwargs.get('progress_expr'),
    'progress_consume_line': kwargs.get('progress_consume_line'),
    'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
    'disable_stop_button':  kwargs.get('disable_stop_button'),
  }

  if show_config:
    build_spec['program_description'] = parser.description or build_spec['program_description']

    layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items()
    build_spec.update(layout_data)

  else:
    build_spec['manual_start'] = True

  return build_spec
Exemplo n.º 13
0
 def GetOptions(self):
     return '{} {}'.format(
         quote(self.active_panel),
         self.config_panels[self.active_panel].GetOptions())
Exemplo n.º 14
0
def create_from_parser(parser, source_path, **kwargs):

  run_cmd = kwargs.get('target')
  if run_cmd is None:
    if hasattr(sys, 'frozen'):
      run_cmd = quote(source_path)
    else:
      run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))

  build_spec = {
      'language':             kwargs.get('language', 'english'),
      'target':               run_cmd,
      'program_name':         kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
      'program_description':  kwargs.get('program_description') or '',
      'sidebar_title':        kwargs.get('sidebar_title', 'Actions'),
      'default_size':         kwargs.get('default_size', (610, 530)),
      'auto_start':           kwargs.get('auto_start', False),
      'show_advanced':        kwargs.get('advanced', True),
      'run_validators':       kwargs.get('run_validators', True),
      'encoding':             kwargs.get('encoding', 'utf-8'),
      'show_stop_warning':    kwargs.get('show_stop_warning', True),
      'show_success_modal':   kwargs.get('show_success_modal', True),
      'force_stop_is_error':  kwargs.get('force_stop_is_error', True),
      'poll_external_updates':kwargs.get('poll_external_updates', False),
      'return_to_config':     kwargs.get('return_to_config', False),

      # Legacy/Backward compatibility interop
      'use_legacy_titles':    kwargs.get('use_legacy_titles', True),
      'num_required_cols':    kwargs.get('required_cols', 1),
      'num_optional_cols':    kwargs.get('optional_cols', 3),
      'manual_start':         False,
      'monospace_display':    kwargs.get('monospace_display', False),

      'image_dir':            kwargs.get('image_dir'),
      'language_dir':         kwargs.get('language_dir'),
      'progress_regex':       kwargs.get('progress_regex'),
      'progress_expr':        kwargs.get('progress_expr'),
      'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
      'disable_stop_button':  kwargs.get('disable_stop_button'),

      # Layouts
      'navigation':           kwargs.get('navigation', constants.SIDEBAR),
      'show_sidebar':         kwargs.get('show_sidebar', False),
      'tabbed_groups':        kwargs.get('tabbed_groups', False),
      'group_by_type':        kwargs.get('group_by_type', True),

      # styles
      'body_bg_color':        kwargs.get('body_bg_color', '#f0f0f0'),
      'header_bg_color':      kwargs.get('header_bg_color', '#ffffff'),
      'header_height':        kwargs.get('header_height', 90),
      'header_show_title':    kwargs.get('header_show_title', True),
      'header_show_subtitle': kwargs.get('header_show_subtitle', True),
      'header_image_center':  kwargs.get('header_image_center', False),
      'footer_bg_color':      kwargs.get('footer_bg_color', '#f0f0f0'),
      'sidebar_bg_color':     kwargs.get('sidebar_bg_color', '#f2f2f2'),
      # font family, weight, and size are determined at runtime
      'terminal_panel_color': kwargs.get('terminal_panel_color', '#F0F0F0'),
      'terminal_font_color':  kwargs.get('terminal_font_color', '#000000'),
      'terminal_font_family': kwargs.get('terminal_font_family', None),
      'terminal_font_weight': kwargs.get('terminal_font_weight', None),
      'terminal_font_size':   kwargs.get('terminal_font_size', None),
      'error_color':          kwargs.get('error_color', '#ea7878')
  }

  if build_spec['monospace_display']:
      warnings.warn('Gooey Option `monospace_display` is a legacy option.\n'
                    'See the terminal_font_x options for more flexible control '
                    'over Gooey\'s text formatting')


  build_spec['program_description'] = parser.description or build_spec['program_description']

  layout_data = (argparse_to_json.convert(parser, **build_spec)
                   if build_spec['show_advanced']
                   else default_layout.items())

  build_spec.update(layout_data)

  if len(build_spec['widgets']) > 1:
    # there are subparsers involved
    build_spec['show_sidebar'] = True

  return build_spec
Exemplo n.º 15
0
 def getValue(self):
   value = self.text_box.GetValue()
   if self.option_string and value:
     return '{0} {1}'.format(self.option_string, quote(value))
   else:
     return quote(value) if value else ''
Exemplo n.º 16
0
 def GetOptions(self):
   return '{} {}'.format(quote(self.active_panel), self.config_panels[self.active_panel].GetOptions())
Exemplo n.º 17
0
def textArea(metadata, value):
    if metadata['commands'] and value:
        return '{} {}'.format(metadata['commands'][0], quote(value.encode('unicode_escape')))
    else:
        return quote(value.encode('unicode_escape')) if value else ''
Exemplo n.º 18
0
def multiFileChooser(metadata, value):
    paths = ' '.join(quote(x) for x in value.split(os.pathsep) if x)
    if metadata['commands'] and paths:
        return u'{} {}'.format(metadata['commands'][0], paths)
    return paths or None
Exemplo n.º 19
0
 def getValue(self):
   value = ' '.join(quote(x) for x in self.text_box.GetValue().split(os.pathsep) if x)
   if self.option_string and value:
     return '{} {}'.format(self.option_string, value)
   return value or ''
def multiFileChooser(metadata, value):
    paths = ' '.join(quote(x) for x in value.split(os.pathsep) if x)
    if metadata['commands'] and paths:
        return u'{} {}'.format(metadata['commands'][0], paths)
    return paths or None
Exemplo n.º 21
0
def create_from_parser(parser, source_path, **kwargs):

    run_cmd = kwargs.get('target')
    if run_cmd is None:
        if hasattr(sys, 'frozen'):
            run_cmd = quote(source_path)
        else:
            run_cmd = '{} -u {}'.format(quote(sys.executable),
                                        quote(source_path))

    build_spec = {
        'language':
        kwargs.get('language', 'english'),
        'target':
        run_cmd,
        # when running with a custom target, there is no need to inject
        # --ignore-gooey into the CLI args
        'suppress_gooey_flag':
        kwargs.get('suppress_gooey_flag') or False,
        'program_name':
        kwargs.get('program_name')
        or os.path.basename(sys.argv[0]).replace('.py', ''),
        'program_description':
        kwargs.get('program_description') or '',
        'sidebar_title':
        kwargs.get('sidebar_title', 'Actions'),
        'default_size':
        kwargs.get('default_size', (610, 530)),
        'auto_start':
        kwargs.get('auto_start', False),
        'show_advanced':
        kwargs.get('advanced', True),
        'run_validators':
        kwargs.get('run_validators', True),
        'encoding':
        kwargs.get('encoding', 'utf-8'),
        'show_stop_warning':
        kwargs.get('show_stop_warning', True),
        'show_success_modal':
        kwargs.get('show_success_modal', True),
        'show_failure_modal':
        kwargs.get('show_failure_modal', True),
        'force_stop_is_error':
        kwargs.get('force_stop_is_error', True),
        'poll_external_updates':
        kwargs.get('poll_external_updates', False),
        'return_to_config':
        kwargs.get('return_to_config', False),
        'show_restart_button':
        kwargs.get('show_restart_button', True),
        'requires_shell':
        kwargs.get('requires_shell', True),
        'menu':
        kwargs.get('menu', []),
        'clear_before_run':
        kwargs.get('clear_before_run', False),
        'fullscreen':
        kwargs.get('fullscreen', False),

        # Legacy/Backward compatibility interop
        'use_legacy_titles':
        kwargs.get('use_legacy_titles', True),
        'num_required_cols':
        kwargs.get('required_cols', 1),
        'num_optional_cols':
        kwargs.get('optional_cols', 3),
        'manual_start':
        False,
        'monospace_display':
        kwargs.get('monospace_display', False),
        'image_dir':
        kwargs.get('image_dir'),
        'language_dir':
        kwargs.get('language_dir'),
        'progress_regex':
        kwargs.get('progress_regex'),
        'progress_expr':
        kwargs.get('progress_expr'),
        'hide_progress_msg':
        kwargs.get('hide_progress_msg', False),
        'disable_progress_bar_animation':
        kwargs.get('disable_progress_bar_animation'),
        'disable_stop_button':
        kwargs.get('disable_stop_button'),

        # Layouts
        'navigation':
        kwargs.get('navigation', constants.SIDEBAR),
        'show_sidebar':
        kwargs.get('show_sidebar', False),
        'tabbed_groups':
        kwargs.get('tabbed_groups', False),
        'group_by_type':
        kwargs.get('group_by_type', True),

        # styles
        'body_bg_color':
        kwargs.get('body_bg_color', '#f0f0f0'),
        'header_bg_color':
        kwargs.get('header_bg_color', '#ffffff'),
        'header_height':
        kwargs.get('header_height', 90),
        'header_show_title':
        kwargs.get('header_show_title', True),
        'header_show_subtitle':
        kwargs.get('header_show_subtitle', True),
        'header_image_center':
        kwargs.get('header_image_center', False),
        'footer_bg_color':
        kwargs.get('footer_bg_color', '#f0f0f0'),
        'sidebar_bg_color':
        kwargs.get('sidebar_bg_color', '#f2f2f2'),

        # font family, weight, and size are determined at runtime
        'terminal_panel_color':
        kwargs.get('terminal_panel_color', '#F0F0F0'),
        'terminal_font_color':
        kwargs.get('terminal_font_color', '#000000'),
        'terminal_font_family':
        kwargs.get('terminal_font_family', None),
        'terminal_font_weight':
        kwargs.get('terminal_font_weight', None),
        'terminal_font_size':
        kwargs.get('terminal_font_size', None),
        'richtext_controls':
        kwargs.get('richtext_controls', False),
        'error_color':
        kwargs.get('error_color', '#ea7878')
    }

    if build_spec['monospace_display']:
        warnings.warn(
            'Gooey Option `monospace_display` is a legacy option.\n'
            'See the terminal_font_x options for more flexible control '
            'over Gooey\'s text formatting')

    build_spec['program_description'] = build_spec[
        'program_description'] or parser.description or ''

    layout_data = (argparse_to_json.convert(parser, **build_spec)
                   if build_spec['show_advanced'] else default_layout.items())

    build_spec.update(layout_data)

    if len(build_spec['widgets']) > 1:
        # there are subparsers involved
        build_spec['show_sidebar'] = True

    return build_spec
def textArea(metadata, value):
    if metadata['commands'] and value:
        return '{} {}'.format(metadata['commands'][0],
                              quote(value.encode('unicode_escape')))
    else:
        return quote(value.encode('unicode_escape')) if value else ''