Skip to content

Commit

Permalink
Switch from QCombobox to QCheckbox (bool) for FixFirstWordsCapitaliza…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
bohning committed Oct 19, 2024
1 parent 542d781 commit 480974c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/usdb_syncer/download_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TxtOptions:
encoding: settings.Encoding
newline: settings.Newline
fix_linebreaks: settings.FixLinebreaks
fix_first_words_capitalization: settings.FixFirstWordsCapitalization
fix_first_words_capitalization: bool
fix_spaces: settings.FixSpaces


Expand Down
6 changes: 3 additions & 3 deletions src/usdb_syncer/gui/forms/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboBox_fix_first_words_capitalization">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this setting is enabled, the first word of each line is capitalized.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<widget class="QCheckBox" name="checkBox_fix_first_words_capitalization">
<property name="text">
<string/>
</property>
</widget>
</item>
Expand Down
12 changes: 3 additions & 9 deletions src/usdb_syncer/gui/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def _populate_comboboxes(self) -> None:
(self.comboBox_encoding, settings.Encoding),
(self.comboBox_line_endings, settings.Newline),
(self.comboBox_fix_linebreaks, settings.FixLinebreaks),
(
self.comboBox_fix_first_words_capitalization,
settings.FixFirstWordsCapitalization,
),
(self.comboBox_fix_spaces, settings.FixSpaces),
(self.comboBox_cover_max_size, settings.CoverMaxSize),
(self.comboBox_audio_format, settings.AudioFormat),
Expand Down Expand Up @@ -85,10 +81,8 @@ def _load_settings(self) -> None:
self.comboBox_fix_linebreaks.setCurrentIndex(
self.comboBox_fix_linebreaks.findData(settings.get_fix_linebreaks())
)
self.comboBox_fix_first_words_capitalization.setCurrentIndex(
self.comboBox_fix_first_words_capitalization.findData(
settings.get_fix_first_words_capitalization()
)
self.checkBox_fix_first_words_capitalization.setChecked(
settings.get_fix_first_words_capitalization()
)
self.comboBox_fix_spaces.setCurrentIndex(
self.comboBox_fix_spaces.findData(settings.get_fix_spaces())
Expand Down Expand Up @@ -161,7 +155,7 @@ def _save_settings(self) -> bool:
settings.set_newline(self.comboBox_line_endings.currentData())
settings.set_fix_linebreaks(self.comboBox_fix_linebreaks.currentData())
settings.set_fix_first_words_capitalization(
self.comboBox_fix_first_words_capitalization.currentData()
self.checkBox_fix_first_words_capitalization.isChecked()
)
settings.set_fix_spaces(self.comboBox_fix_spaces.currentData())
settings.set_audio(self.groupBox_audio.isChecked())
Expand Down
24 changes: 3 additions & 21 deletions src/usdb_syncer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,6 @@ def __str__(self) -> str:
assert_never(unreachable)


class FixFirstWordsCapitalization(Enum):
"""Supported variants for fixing first words capitalization."""

DISABLE = 0
ENABLE = 1

def __str__(self) -> str:
match self:
case FixFirstWordsCapitalization.ENABLE:
return "enable"
case FixFirstWordsCapitalization.DISABLE:
return "disable"
case _ as unreachable:
assert_never(unreachable)


class FixSpaces(Enum):
"""Supported variants for fixing spaces."""

Expand Down Expand Up @@ -599,13 +583,11 @@ def set_fix_linebreaks(value: FixLinebreaks) -> None:
set_setting(SettingKey.FIX_LINEBREAKS, value)


def get_fix_first_words_capitalization() -> FixFirstWordsCapitalization:
return get_setting(
SettingKey.FIX_FIRSTWORDSCAPITALIZATION, FixFirstWordsCapitalization.ENABLE
)
def get_fix_first_words_capitalization() -> bool:
return get_setting(SettingKey.FIX_FIRSTWORDSCAPITALIZATION, True)


def set_fix_first_words_capitalization(value: FixFirstWordsCapitalization) -> None:
def set_fix_first_words_capitalization(value: bool) -> None:
set_setting(SettingKey.FIX_FIRSTWORDSCAPITALIZATION, value)


Expand Down
7 changes: 2 additions & 5 deletions src/usdb_syncer/song_txt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from usdb_syncer import download_options, errors
from usdb_syncer.logger import Log
from usdb_syncer.meta_tags import MetaTags
from usdb_syncer.settings import FixFirstWordsCapitalization, FixLinebreaks, FixSpaces
from usdb_syncer.settings import FixLinebreaks, FixSpaces
from usdb_syncer.song_txt.headers import Headers
from usdb_syncer.song_txt.tracks import Tracks

Expand Down Expand Up @@ -112,10 +112,7 @@ def fix(self, txt_options: download_options.TxtOptions) -> None:
self.notes.fix_linebreaks_yass_style(self.headers.bpm, self.logger)
case _ as unreachable:
assert_never(unreachable)
if (
txt_options.fix_first_words_capitalization
!= FixFirstWordsCapitalization.DISABLE
):
if txt_options.fix_first_words_capitalization:
self.notes.fix_first_words_capitalization(self.logger)
if txt_options.fix_spaces != FixSpaces.DISABLE:
self.notes.fix_spaces(txt_options.fix_spaces, self.logger)
Expand Down
10 changes: 2 additions & 8 deletions tests/unit/song_txt/test_notes_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@

from usdb_syncer.download_options import TxtOptions
from usdb_syncer.logger import get_logger
from usdb_syncer.settings import (
Encoding,
FixFirstWordsCapitalization,
FixLinebreaks,
FixSpaces,
Newline,
)
from usdb_syncer.settings import Encoding, FixLinebreaks, FixSpaces, Newline
from usdb_syncer.song_txt import SongTxt

_logger = get_logger(__file__)
Expand Down Expand Up @@ -50,7 +44,7 @@ def test_notes_parser_fixes(resource_dir: str) -> None:
encoding=Encoding.UTF_8,
newline=Newline.CRLF,
fix_linebreaks=FixLinebreaks.USDX_STYLE,
fix_first_words_capitalization=FixFirstWordsCapitalization.ENABLE,
fix_first_words_capitalization=True,
fix_spaces=FixSpaces.AFTER,
)
)
Expand Down

0 comments on commit 480974c

Please sign in to comment.