Skip to content

Commit

Permalink
format code with yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
justbuchanan committed Dec 3, 2021
1 parent fe70c44 commit e00d710
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
29 changes: 14 additions & 15 deletions autoname_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def icon_for_window(window):
cls = cls.lower() # case-insensitive matching
if cls in WINDOW_ICONS:
return WINDOW_ICONS[cls]
logging.info(
'No icon available for window with classes: %s' % str(classes))
logging.info('No icon available for window with classes: %s' %
str(classes))
return DEFAULT_ICON


Expand Down Expand Up @@ -166,26 +166,27 @@ def rename_workspaces(i3, icon_list_format='default'):
n += 1

new_name = construct_workspace_name(
NameParts(
num=new_num, shortname=name_parts.shortname, icons=new_icons))
NameParts(num=new_num,
shortname=name_parts.shortname,
icons=new_icons))
if workspace.name == new_name:
continue
i3.command(
'rename workspace "%s" to "%s"' % (workspace.name, new_name))
i3.command('rename workspace "%s" to "%s"' %
(workspace.name, new_name))


# Rename workspaces to just numbers and shortnames, removing the icons.
def on_exit(i3):
for workspace in i3.get_tree().workspaces():
name_parts = parse_workspace_name(workspace.name)
new_name = construct_workspace_name(
NameParts(
num=name_parts.num, shortname=name_parts.shortname,
icons=None))
NameParts(num=name_parts.num,
shortname=name_parts.shortname,
icons=None))
if workspace.name == new_name:
continue
i3.command(
'rename workspace "%s" to "%s"' % (workspace.name, new_name))
i3.command('rename workspace "%s" to "%s"' %
(workspace.name, new_name))
i3.main_quit()
sys.exit(0)

Expand All @@ -205,13 +206,11 @@ def on_exit(i3):
'--icon_list_format',
type=str,
default='default',
help=
"The formatting of the list of icons."
help="The formatting of the list of icons."
"Accepted values:"
" - default: no formatting,"
" - mathematician: factorize with superscripts (e.g. aababa -> a⁴b²),"
" - chemist: factorize with subscripts (e.g. aababa -> a₄b₂)."
)
" - chemist: factorize with subscripts (e.g. aababa -> a₄b₂).")
args = parser.parse_args()

RENUMBER_WORKSPACES = not args.norenumber_workspaces
Expand Down
11 changes: 5 additions & 6 deletions rename_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ def rename_workspace(new_shortname=None):

# get the current workspace and rename it
new_name = construct_workspace_name(
NameParts(
num=name_parts.num,
shortname=new_shortname,
icons=name_parts.icons))
NameParts(num=name_parts.num,
shortname=new_shortname,
icons=name_parts.icons))
workspace = focused_workspace(i3)
res = i3.command(
'rename workspace "%s" to "%s"' % (workspace.name, new_name))
res = i3.command('rename workspace "%s" to "%s"' %
(workspace.name, new_name))
assert res[0]['success'], "Failed to rename workspace"


Expand Down
11 changes: 7 additions & 4 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def xprop(win_id, property):
_superscript = "⁰¹²³⁴⁵⁶⁷⁸⁹"
_subscript = "₀₁₂₃₄₅₆₇₈₉"


def _encode_base_10_number(n: int, symbols: str) -> str:
"""Write a number in base 10 using symbols from a given string.
Expand All @@ -82,7 +83,8 @@ def format_icon_list(icon_list, icon_list_format='default'):
new_list = []
for icon, count in Counter(icon_list).items():
if count > 1:
new_list.append(icon + _encode_base_10_number(count, _superscript))
new_list.append(icon +
_encode_base_10_number(count, _superscript))
else:
new_list.append(icon)
return ' '.join(new_list)
Expand All @@ -93,11 +95,12 @@ def format_icon_list(icon_list, icon_list_format='default'):
new_list = []
for icon, count in Counter(icon_list).items():
if count > 1:
new_list.append(icon + _encode_base_10_number(count, _subscript))
new_list.append(icon +
_encode_base_10_number(count, _subscript))
else:
new_list.append(icon)
return ' '.join(new_list)

else:
raise ValueError("Unknown format name for the list of icons: ", icon_list_format)

raise ValueError("Unknown format name for the list of icons: ",
icon_list_format)

0 comments on commit e00d710

Please sign in to comment.