Skip to content

Commit

Permalink
Do not show "Uncategorized" cardsets list if all cardsets have been c…
Browse files Browse the repository at this point in the history
…ategorized.
  • Loading branch information
joeraz committed Oct 14, 2023
1 parent 05fc7a8 commit 7741fa7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
10 changes: 10 additions & 0 deletions pysollib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,10 @@ def __init__(self):
self.registered_nationalities = {}
self.registered_dates = {}

self.uncategorized_styles = False
self.uncategorized_nationalities = False
self.uncategorized_dates = False

def _check(self, cs):
s = cs.type
if s not in CSI.TYPE:
Expand Down Expand Up @@ -571,12 +575,18 @@ def register(self, cs):
#
keys = cs.styles[:]
cs.si.styles = tuple([s for s in keys if s in CSI.STYLE])
if len(cs.si.styles) == 0:
self.uncategorized_styles = True
for s in cs.si.styles:
self.registered_styles[s] = self.registered_styles.get(s, 0) + 1
cs.si.nationalities = tuple([s for s in keys if s in CSI.NATIONALITY])
if len(cs.si.nationalities) == 0:
self.uncategorized_nationalities = True
for s in cs.si.nationalities:
self.registered_nationalities[s] = \
self.registered_nationalities.get(s, 0) + 1
if cs.year == 0:
self.uncategorized_dates = True
keys = (cs.year // 100,)
cs.si.dates = tuple([s for s in keys if s in CSI.DATE])
for s in cs.si.dates:
Expand Down
23 changes: 13 additions & 10 deletions pysollib/tile/selectcardset.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def __init__(self, manager, key):
SelectCardsetNode(
None, name, lambda cs, key=key: key in cs.si.styles))
if nodes:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.styles))
if manager.uncategorized_styles:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.styles))
select_by_style = SelectCardsetNode(
None, _("by Style"), tuple(nodes))
#
Expand All @@ -110,10 +111,11 @@ def __init__(self, manager, key):
None, name,
lambda cs, key=key: key in cs.si.nationalities))
if nodes:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"),
lambda cs: not cs.si.nationalities))
if manager.uncategorized_nationalities:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"),
lambda cs: not cs.si.nationalities))
select_by_nationality = SelectCardsetNode(
None, _("by Nationality"), tuple(nodes))
#
Expand All @@ -127,9 +129,10 @@ def __init__(self, manager, key):
SelectCardsetNode(
None, name, lambda cs, key=key: key in cs.si.dates))
if nodes:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.dates))
if manager.uncategorized_dates:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.dates))
select_by_date = SelectCardsetNode(
None, _("by Date"), tuple(nodes))
#
Expand Down
23 changes: 13 additions & 10 deletions pysollib/tk/selectcardset.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ def __init__(self, manager, key):
SelectCardsetNode(
None, name, lambda cs, key=key: key in cs.si.styles))
if nodes:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.styles))
if manager.uncategorized_styles:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.styles))
select_by_style = SelectCardsetNode(
None, _("by Style"), tuple(nodes))
#
Expand All @@ -109,10 +110,11 @@ def __init__(self, manager, key):
None, name,
lambda cs, key=key: key in cs.si.nationalities))
if nodes:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"),
lambda cs: not cs.si.nationalities))
if manager.uncategorized_nationalities:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"),
lambda cs: not cs.si.nationalities))
select_by_nationality = SelectCardsetNode(
None, _("by Nationality"), tuple(nodes))
#
Expand All @@ -126,9 +128,10 @@ def __init__(self, manager, key):
SelectCardsetNode(
None, name, lambda cs, key=key: key in cs.si.dates))
if nodes:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.dates))
if manager.uncategorized_dates:
nodes.append(
SelectCardsetNode(
None, _("Uncategorized"), lambda cs: not cs.si.dates))
select_by_date = SelectCardsetNode(
None, _("by Date"), tuple(nodes))
#
Expand Down

0 comments on commit 7741fa7

Please sign in to comment.