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

Prevent setting non-positive media duration #245

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
24 changes: 9 additions & 15 deletions tilia/ui/dialogs/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,19 @@ def ask_for_color(
return color.isValid(), color # returned color is invalid if user cancels


def ask_for_int(
title: str, prompt: str, initial: Optional[int] = 0, **kwargs
) -> tuple[bool, int]:
number, accepted = QInputDialog().getInt(None, title, prompt, initial, **kwargs)
return accepted, number
def ask_for_int(title: str, prompt: str, **kwargs) -> tuple[bool, int]:
number, accepted = QInputDialog().getInt(None, title, prompt, **kwargs)
return bool(accepted) & True, number
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get this one. Why do we need this?



def ask_for_string(
title: str, prompt: str, initial: Optional[str] = ""
) -> tuple[bool, str]:
string, accepted = QInputDialog().getText(None, title, prompt, text=initial)
return accepted, string
def ask_for_string(title: str, prompt: str, **kwargs) -> tuple[bool, str]:
string, accepted = QInputDialog().getText(None, title, prompt, **kwargs)
return bool(accepted) & True, string


def ask_for_float(
title: str, prompt: str, initial: Optional[float] = 0.0
) -> tuple[bool, float]:
number, accepted = QInputDialog().getDouble(None, title, prompt, initial)
return accepted, number
def ask_for_float(title: str, prompt: str, **kwargs) -> tuple[bool, float]:
number, accepted = QInputDialog().getDouble(None, title, prompt, **kwargs)
return bool(accepted) & True, number


def ask_yes_no_or_cancel(title: str, prompt: str) -> tuple[bool, bool]:
Expand Down
17 changes: 11 additions & 6 deletions tilia/ui/timelines/collection/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from tilia.timelines.timeline_kinds import TimelineKind
from tilia.ui.dialogs.add_timeline_without_media import AddTimelineWithoutMedia
from tilia.ui.request_handler import RequestHandler
from tilia.ui.strings import BEAT_TIMELINE_FILL_TITLE, BEAT_TIMELINE_DELETE_EXISTING_BEATS_PROMPT
from tilia.ui.strings import (
BEAT_TIMELINE_FILL_TITLE,
BEAT_TIMELINE_DELETE_EXISTING_BEATS_PROMPT,
)


def _get_media_is_loaded():
Expand Down Expand Up @@ -45,7 +48,11 @@ def _handle_media_not_loaded() -> bool:

if action_to_take == AddTimelineWithoutMedia.Result.SET_DURATION:
success, duration = get(
Get.FROM_USER_FLOAT, "Set duration", "Insert duration"
Get.FROM_USER_FLOAT,
"Set duration",
"Insert duration (s)",
value=60,
min=1,
)
if not success:
return False
Expand Down Expand Up @@ -76,9 +83,7 @@ def on_timeline_add(self, kind: TimelineKind):
return False
kwargs |= additional_args

self.timelines.create_timeline(
kind=kind, components=None, name=name, **kwargs
)
self.timelines.create_timeline(kind=kind, components=None, name=name, **kwargs)

return True

Expand All @@ -100,7 +105,7 @@ def on_beat_timeline_fill():
confirmed = get(
Get.FROM_USER_YES_OR_NO,
BEAT_TIMELINE_FILL_TITLE,
BEAT_TIMELINE_DELETE_EXISTING_BEATS_PROMPT
BEAT_TIMELINE_DELETE_EXISTING_BEATS_PROMPT,
)
if not confirmed:
return False
Expand Down
8 changes: 3 additions & 5 deletions tilia/ui/timelines/collection/requests/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _get_args_for_timeline_name_set(timeline_uis):
Get.FROM_USER_STRING,
"Change timeline name",
"Choose new name",
get(Get.TIMELINE, timeline_ui.id).name,
text=get(Get.TIMELINE, timeline_ui.id).name,
)
if not accepted:
raise UserCancelledDialog
Expand All @@ -31,7 +31,7 @@ def _get_args_for_timeline_height_set(timeline_uis):
Get.FROM_USER_INT,
"Change timeline height",
"Insert new timeline height",
initial=timeline_ui.get_data("height"),
value=timeline_ui.get_data("height"),
min=10,
)
if not accepted:
Expand Down Expand Up @@ -114,9 +114,7 @@ def _get_args_for_timelines_clear(_):

def _get_args_for_beat_set_measure_number(_):
accepted, number = get(
Get.FROM_USER_INT,
"Change measure number",
"Insert measure number",
Get.FROM_USER_INT, "Change measure number", "Insert measure number", min=0
)
if not accepted:
raise UserCancelledDialog
Expand Down
2 changes: 1 addition & 1 deletion tilia/ui/windows/svg_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ def annotation_edit(self) -> None:
return
for item in to_edit:
success, annotation = get(
Get.FROM_USER_STRING, "Score Annotation", "Edit Annotation", item.text()
Get.FROM_USER_STRING, "Score Annotation", "Edit Annotation", text=item.text()
)
if not success:
continue
Expand Down