コード例 #1
0
def test_font_gets_updated(porcusession):
    fixedfont = tkinter.font.Font(name='TkFixedFont', exists=True)

    settings.set('font_family', 'Helvetica')
    assert fixedfont.cget('family') == 'Helvetica'
    settings.set('font_size', 123)
    assert fixedfont.cget('size') == 123
コード例 #2
0
def test_add_option_and_get_and_set(cleared_global_settings):
    settings.add_option('how_many_foos', 123)
    settings.add_option('bar_message', 'hello')

    assert settings.get('how_many_foos', int) == 123
    assert settings.get('bar_message', str) == 'hello'
    settings.set('how_many_foos', 456)
    settings.set('bar_message', 'bla')
    assert settings.get('how_many_foos', int) == 456
    assert settings.get('bar_message', str) == 'bla'
コード例 #3
0
def test_no_json_file(cleared_global_settings):
    assert not settings._get_json_path().exists()
    settings._load_from_file()

    settings.add_option('foo', 'default')
    settings.set('foo', 'custom')

    assert not settings._get_json_path().exists()
    settings.reset_all()
    assert settings.get('foo', str) == 'default'
コード例 #4
0
def test_wrong_type(cleared_global_settings):
    settings.add_option('magic_message', 'bla')

    with pytest.raises(
            dacite.exceptions.WrongTypeError,
            match=r'wrong value type .* should be "int" instead of .* "str"'):
        settings.get('magic_message', int)
    with pytest.raises(
            dacite.exceptions.WrongTypeError,
            match=r'wrong value type .* should be "str" instead of .* "int"'):
        settings.set('magic_message', 123)
コード例 #5
0
def test_unknown_option_in_settings_file(cleared_global_settings):
    load_from_json_string('{"foo": "custom", "unknown": "hello"}')
    with pytest.raises(KeyError):
        settings.get('foo', str)

    settings.add_option('foo', 'default')
    assert settings.get('foo', str) == 'custom'
    settings.set('foo', 'default')
    assert settings.get('foo', str) == 'default'

    assert save_and_read_file() == {'unknown': 'hello'}
コード例 #6
0
def test_save(cleared_global_settings):
    load_from_json_string('{"bar": "custom bar"}')

    settings.add_option('foo', 'default')
    settings.add_option('bar', 'default')
    settings.add_option('baz', 'default')
    settings.set('foo', 'custom foo')

    settings.save()
    with settings._get_json_path().open('r') as file:
        assert json.load(file) == {'foo': 'custom foo', 'bar': 'custom bar'}
コード例 #7
0
ファイル: pluginmanager.py プロジェクト: bvadebruna/porcupine
    def _toggle_enabled(self) -> None:
        [plugin_name] = self._treeview.selection()
        [info] = [
            info for info in pluginloader.plugin_infos
            if info.name == plugin_name
        ]

        disabled = set(settings.get('disabled_plugins', List[str]))
        disabled ^= {plugin_name}
        settings.set('disabled_plugins', list(disabled))
        self._update_row(info)
        self._on_select()
        self._update_plz_restart_label()
コード例 #8
0
    def change_font_size(how: Literal['bigger', 'smaller', 'reset']) -> None:
        if how == 'reset':
            settings.reset('font_size')
            return

        size = settings.get('font_size', int)
        if how == 'bigger':
            size += 1
        else:
            size -= 1
            if size < 3:
                return

        settings.set('font_size', size)
コード例 #9
0
ファイル: autocomplete.py プロジェクト: bvadebruna/porcupine
    def stop_completing(self,
                        *,
                        withdraw: bool = True) -> Optional[Completion]:
        # putting this here avoids some bugs
        if self.is_showing():
            settings.set('autocomplete_popup_width',
                         self.toplevel.winfo_width())
            settings.set('autocomplete_popup_height',
                         self.toplevel.winfo_height())
            settings.set('autocomplete_divider_pos',
                         self._panedwindow.sashpos(0))

        selected = self._get_selected_completion()

        if withdraw:
            self.toplevel.withdraw()
        self.treeview.delete(*self.treeview.get_children())
        self._completion_list = None

        return selected
コード例 #10
0
def on_theme_changed(style: ttkthemes.ThemedStyle, var: tkinter.StringVar, *junk: object) -> None:
    theme_name = var.get()
    style.set_theme(theme_name)
    settings.set('ttk_theme', theme_name)
コード例 #11
0
 def var2settings(*junk: str) -> None:
     settings.set('pygments_style', var.get())
コード例 #12
0
def save_geometry(event: 'tkinter.Event[tkinter.Misc]') -> None:
    assert isinstance(event.widget, (tkinter.Tk, tkinter.Toplevel))
    settings.set('default_geometry', event.widget.geometry())