Skip to content

Commit

Permalink
IMPROVE: Rename orderings
Browse files Browse the repository at this point in the history
| Current           | New                     |
| :---              | :---                    |
| name              | alphabetical            |
| name-desc         | alphabetical-desc       |
| name-natural      | natural                 |
| name-natural-desc | natural-desc            |
| modify            | recently-modified-first |
| modify-desc       | recently-modified-last  |
| size              | smallest-first          |
| size-desc         | largest-first           |
  • Loading branch information
jcjgraf committed May 20, 2021
1 parent dc47d58 commit b2ac50d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
10 changes: 5 additions & 5 deletions tests/unit/api/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,18 @@ def ask_question(*args, **kwargs):


def test_set_order_setting():
o = settings.ImageOrderSetting("imageorder", "name")
o.value = "name-desc"
assert o.value == "name-desc"
o = settings.ImageOrderSetting("imageorder", "alphabetical")
o.value = "alphabetical-desc"
assert o.value == "alphabetical-desc"


def test_set_order_setting_non_str():
o = settings.OrderSetting("order", "name")
o = settings.OrderSetting("order", "alphabetical")
with pytest.raises(ValueError, match="must be one of"):
o.value = 1


def test_set_order_setting_non_valid():
o = settings.OrderSetting("order", "name")
o = settings.OrderSetting("order", "alphabetical")
with pytest.raises(ValueError, match="must be one of"):
o.value = "invalid"
38 changes: 20 additions & 18 deletions vimiv/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ class ImageOrderSetting(OrderSetting):
"""Stores an image ordering setting."""

ORDER_TYPES = {
"name": (os.path.basename, False),
"name-desc": (os.path.basename, True),
"name-natural": (OrderSetting._natural_sort, False),
"name-natural-desc": (OrderSetting._natural_sort, True),
"modify": (os.path.getmtime, False),
"modify-desc": (os.path.getmtime, True),
"size": (os.path.getsize, False),
"size-desc": (os.path.getsize, True),
"alphabetical": (os.path.basename, False),
"alphabetical-desc": (os.path.basename, True),
"natural": (OrderSetting._natural_sort, False),
"natural-desc": (OrderSetting._natural_sort, True),
"recently-modify-first": (os.path.getmtime, False),
"recently-modify-last": (os.path.getmtime, True),
"smallest-first": (os.path.getsize, False),
"largest-first": (os.path.getsize, True),
}

def __str__(self) -> str:
Expand All @@ -377,14 +377,14 @@ class DirectoryOrderSetting(OrderSetting):
"""Stores an directory ordering setting."""

ORDER_TYPES = {
"name": (os.path.basename, False),
"name-desc": (os.path.basename, True),
"name-natural": (OrderSetting._natural_sort, False),
"name-natural-desc": (OrderSetting._natural_sort, True),
"modify": (os.path.getmtime, False),
"modify-desc": (os.path.getmtime, True),
"size": (lambda e: len(os.listdir(e)), True),
"size-desc": (lambda e: len(os.listdir(e)), False),
"alphabetical": (os.path.basename, False),
"alphabetical-desc": (os.path.basename, True),
"natural": (OrderSetting._natural_sort, False),
"natural-desc": (OrderSetting._natural_sort, True),
"recently-modify-first": (os.path.getmtime, False),
"recently-modify-last": (os.path.getmtime, True),
"smallest-first": (lambda e: len(os.listdir(e)), True),
"largest-first": (lambda e: len(os.listdir(e)), False),
}

def __str__(self) -> str:
Expand All @@ -409,9 +409,11 @@ def __str__(self) -> str:
read_only = BoolSetting(
"read_only", False, desc="Disable any commands that are able to edit files on disk"
)
image_order = ImageOrderSetting("image_order", "name", desc="Set image ordering.",)
image_order = ImageOrderSetting(
"image_order", "alphabetical", desc="Set image ordering.",
)
directory_order = DirectoryOrderSetting(
"directory_order", "name", desc="Set directory ordering.",
"directory_order", "alphabetical", desc="Set directory ordering.",
)


Expand Down

0 comments on commit b2ac50d

Please sign in to comment.