Beispiel #1
0
    def __init__(self,
                 manager: TabManager,
                 content: str = '',
                 path: Optional[pathlib.Path] = None,
                 filetype: Optional[Dict[str, Any]] = None) -> None:
        super().__init__(manager)

        self._save_hash: Optional[str] = None
        if path is None:
            self._path = None
        else:
            self._path = path.resolve()

        self.settings = settings.Settings(self, '<<TabSettingChanged:{}>>')
        self.settings.add_option('pygments_lexer',
                                 pygments.lexers.TextLexer,
                                 type=pygments.lexer.LexerMeta,
                                 converter=_import_lexer_class)
        self.settings.add_option('tabs2spaces', True)
        self.settings.add_option('indent_size', 4)
        self.settings.add_option('encoding', 'utf-8')
        self.settings.add_option('line_ending',
                                 settings.get('default_line_ending',
                                              settings.LineEnding),
                                 converter=settings.LineEnding.__getitem__)

        # we need to set width and height to 1 to make sure it's never too
        # large for seeing other widgets
        self.textwidget = textwidget.MainText(self,
                                              width=1,
                                              height=1,
                                              wrap='none',
                                              undo=True)
        self.textwidget.pack(side='left', fill='both', expand=True)
        self.textwidget.bind('<<ContentChanged>>',
                             self._update_title,
                             add=True)

        if content:
            self.textwidget.insert('1.0', content)
            self.textwidget.edit_reset()  # reset undo/redo

        self.bind('<<PathChanged>>', self._update_status, add=True)
        self.textwidget.bind('<<CursorMoved>>', self._update_status, add=True)

        self.scrollbar = ttk.Scrollbar(self.right_frame)
        self.scrollbar.pack(side='right', fill='y')
        self.textwidget.config(yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.textwidget.yview)

        self.mark_saved()
        self._update_title()
        self._update_status()
Beispiel #2
0
def test_debug_dump(porcusession, capsys):
    settings_obj = settings.Settings(None, '<<Foo:{}>>')
    settings_obj.add_option('foo', None, type=Optional[str])
    settings_obj.set('bar', ['a', 'b', 'c'], from_config=True)
    settings_obj.debug_dump()
    assert capsys.readouterr() == ('''\
1 known options (add_option called)
  foo = None    (type: typing.Union[str, NoneType])

1 unknown options (add_option not called)
  bar = ['a', 'b', 'c']

''', '')
Beispiel #3
0
def test_dataclass(porcusession):
    settings_obj = settings.Settings(None, '<<Foo:{}>>')

    settings_obj.add_option('foo', None, type=Optional[Foo])
    settings_obj.set('foo', {
        'how_many': 123,
        'message': 'hello'
    },
                     from_config=True)
    settings_obj.set('bar', {
        'how_many': 456,
        'message': 'hi'
    },
                     from_config=True)
    settings_obj.add_option('bar', None, type=Optional[Foo])

    assert settings_obj.get('foo', Foo) == Foo(123, 'hello')
    assert settings_obj.get('bar', Foo) == Foo(456, 'hi')
Beispiel #4
0
def test_dataclass():
    settings_obj = settings.Settings(None, "<<Foo:{}>>")

    settings_obj.add_option("foo", None, Optional[Foo])
    settings_obj.set("foo", {
        "how_many": 123,
        "message": "hello"
    },
                     from_config=True)
    settings_obj.set("bar", {
        "how_many": 456,
        "message": "hi"
    },
                     from_config=True)
    settings_obj.add_option("bar", None, Optional[Foo])

    assert settings_obj.get("foo", Foo) == Foo(123, "hello")
    assert settings_obj.get("bar", Foo) == Foo(456, "hi")
Beispiel #5
0
def test_debug_dump(capsys):
    settings_obj = settings.Settings(None, "<<Foo:{}>>")
    settings_obj.add_option("foo", None, Optional[str])
    settings_obj.set("bar", ["a", "b", "c"], from_config=True)
    settings_obj.debug_dump()

    output, errors = capsys.readouterr()
    assert not errors
    if sys.version_info < (3, 9):
        output = output.replace("typing.Union[str, NoneType]",
                                "typing.Optional[str]")
    assert (output == """\
1 known options (add_option called)
  foo = None    (type: typing.Optional[str])

1 unknown options (add_option not called)
  bar = ['a', 'b', 'c']

""")