Skip to content

Commit

Permalink
Code and WF reorder and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Claude Jung committed Feb 4, 2023
1 parent d2052f9 commit 50c9a59
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 623 deletions.
Binary file modified Window Manager.alfredworkflow
Binary file not shown.
56 changes: 56 additions & 0 deletions src/WindowManager.py
Expand Up @@ -111,18 +111,58 @@ def __init__(self, dim: str()) -> None:
self.dimension = json.loads(dim)

def x_pos(self) -> int:
"""
Get x position of the window from a str represenation of a dimension
Returns:
int: x postition
"""
return int(self.dimension.get('x', None))

def y_pos(self) -> int:
"""
Get y position of the window from a str represenation of a dimension
Returns:
int: y postition
"""
return int(self.dimension.get('y', None))

def width(self) -> int:
"""
Get width of the window from a str represenation of a dimension
Returns:
int: window width
"""
return int(self.dimension.get('width', None))

def height(self) -> int:
"""
Get height of the window from a str represenation of a dimension
Returns:
int: window height
"""
return int(self.dimension.get('height', None))

def get_dimensions(self) -> dict:
"""
Get dimension from dimension provided as string
Returns:
int: dimension
"""
return self.dimension


Expand All @@ -132,9 +172,25 @@ def __init__(self) -> None:
self.screen_res = self._sys_profiler()

def screen_width(self) -> int:
"""
Get screen width
Returns:
int: screen width
"""
return self.screen_res[0]

def screen_height(self) -> int:
"""
Get Screen height
Returns:
int: screen height
"""
return self.screen_res[1]

def _sys_profiler(self) -> tuple:
Expand Down
5 changes: 3 additions & 2 deletions src/get_dimensions.py
Expand Up @@ -10,14 +10,15 @@
cache_file = os.path.join(cache_dir, "dimensions.json")

app_id = Tools.getEnv('app_id') # get app id from previous wf step
post_action = Tools.getArgv(1) # get post action e.g 'delete' from prev step
post_action = Tools.getArgv(1) # post action e.g 'delete' from prev step
delete_entry = True if post_action == 'delete' else False

Dim = Dimensions(cache_file)
# read dimensionsn and deltet the entry when post action == delete
vars = Dim.get_dimension(app_id, delete=delete_entry)

if vars == None or vars == {}:
vars = json.loads('{"x":521,"y":404,"width":1073,"height":565}') # fallback
vars = json.loads('{"x":521,"y":404,"width":1073,"height":565}') # fallback dimensions

aj = AlfJson()
aj.add_variables(vars)
Expand Down

0 comments on commit 50c9a59

Please sign in to comment.