Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all bool settings #330

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions zxlive/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
def get_data(path: str) -> str:
return os.path.join(os.environ.get("_MEIPASS", _ROOT), path)

def set_settings_value(arg: str, val: T, _type: Type[T], settings: QSettings | None = None) -> None:
_settings = settings or QSettings("zxlive", "zxlive")
if not isinstance(val, _type):
raise ValueError(f"Unexpected type for {arg}: expected {_type}, got {type(val)}")
_settings.setValue(arg, val)

def get_settings_value(arg: str, _type: Type[T], default: T | None = None, settings: QSettings | None = None) -> T:
_settings = settings or QSettings("zxlive", "zxlive")
Expand Down
12 changes: 10 additions & 2 deletions zxlive/graphview.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from dataclasses import dataclass

from . import animations as anims
from .common import GraphT, SCALE, OFFSET_X, OFFSET_Y, MIN_ZOOM, MAX_ZOOM
from .common import (GraphT, SCALE, OFFSET_X, OFFSET_Y, MIN_ZOOM, MAX_ZOOM,
get_settings_value, set_settings_value)
from .graphscene import GraphScene, VItem, EItem, EditGraphScene
from .settings import display_setting
from .vitem import PHASE_ITEM_Z
Expand Down Expand Up @@ -99,10 +100,17 @@ def __init__(self, graph_scene: GraphScene) -> None:

self.centerOn(OFFSET_X,OFFSET_Y)

self.sparkle_mode = False
self.sparkles = Sparkles(self.graph_scene)
QShortcut(QKeySequence("Ctrl+Shift+Alt+S"), self).activated.connect(self._toggle_sparkles)

@property
def sparkle_mode(self) -> bool:
return get_settings_value("sparkle-mode", bool)

@sparkle_mode.setter
def sparkle_mode(self, value: bool) -> None:
set_settings_value("sparkle-mode", value, bool)

def _toggle_sparkles(self) -> None:
self.sparkle_mode = not self.sparkle_mode

Expand Down
9 changes: 8 additions & 1 deletion zxlive/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def __init__(self) -> None:

self.effects = {e: load_sfx(e) for e in SFXEnum}

self.sfx_on = self.settings.value("sound-effects")
QShortcut(QKeySequence("Ctrl+B"), self).activated.connect(self._toggle_sfx)

def open_demo_graph(self) -> None:
Expand Down Expand Up @@ -588,6 +587,14 @@ def update_colors(self) -> None:
if self.active_panel is not None:
self.active_panel.update_colors()

@property
def sfx_on(self) -> bool:
return self.settings.value("sound-effects")

@sfx_on.setter
def sfx_on(self, value: bool) -> None:
self.settings.setValue("sound-effects", value)

def play_sound(self, s: SFXEnum) -> None:
if self.sfx_on:
self.effects[s].play()
Expand Down
2 changes: 1 addition & 1 deletion zxlive/rewrite_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class RewriteAction:

@classmethod
def from_rewrite_data(cls, d: RewriteData) -> RewriteAction:
if display_setting.PREVIEWS_SHOW and ('picture' in d or 'custom_rule' in d):
if display_setting.previews_show and ('picture' in d or 'custom_rule' in d):
if 'custom_rule' in d:
# We will create a custom tooltip picture representing the custom rewrite
graph_scene_left = GraphScene()
Expand Down
11 changes: 8 additions & 3 deletions zxlive/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ColorScheme(TypedDict):
"snap-granularity": '4',
"input-circuit-format": 'openqasm',
"previews-show": True,
"sparkle-mode": True,
'sound-effects': False,
}

Expand Down Expand Up @@ -186,7 +187,6 @@ def _get_synonyms(key: str, default: list[str]) -> list[str]:

class DisplaySettings:
SNAP_DIVISION = 4 # Should be an integer dividing SCALE
PREVIEWS_SHOW = True

def __init__(self) -> None:
self.colors = color_schemes[str(settings.value("color-scheme"))]
Expand All @@ -202,9 +202,14 @@ def update(self) -> None:
get_settings_value("font/size", int)
)
self.SNAP = SCALE / self.SNAP_DIVISION
self.PREVIEWS_SHOW = get_settings_value("previews-show",bool)
self.PREVIEWS_SHOW = True

@property
def previews_show(self) -> bool:
return get_settings_value("previews-show", bool)

@previews_show.setter
def previews_show(self, value: bool) -> None:
settings.setValue("previews-show", value)

# Initialise settings
settings = QSettings("zxlive", "zxlive")
Expand Down
1 change: 1 addition & 0 deletions zxlive/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class SettingsData(TypedDict):
{"id": "snap-granularity", "label": "Snap-to-grid granularity", "type": FormInputType.Combo, "data": snap_to_grid_data},
{"id": "input-circuit-format", "label": "Input Circuit as", "type": FormInputType.Combo, "data": input_circuit_formats},
{"id": "previews-show", "label": "Show rewrite previews","type": FormInputType.Bool},
{"id": "sparkle-mode", "label": "Sparkle Mode", "type": FormInputType.Bool},
{"id": "sound-effects", "label": "Sound Effects", "type": FormInputType.Bool},
]

Expand Down
Loading