From c1aeaafaab9c09201dab84394eda0aaa3fc6cd08 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Sat, 16 Sep 2017 02:15:00 -0600 Subject: [PATCH 1/9] command chaining functionality in config --- quicktile/commands.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index 1b8163c..2a247c4 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -167,9 +167,8 @@ def decorate(func): return func return decorate - def call(self, command, winman, *args, **kwargs): + def checkCommand(self, command,winman,*args,**kwargs): # type: (str, WindowManager, *Any, **Any) -> bool - """Resolve a textual positioning command and execute it.""" cmd = self.commands.get(command, None) if cmd: @@ -183,6 +182,20 @@ def call(self, command, winman, *args, **kwargs): logging.error("Unrecognized command: %s", command) return False + def call(self, command, winman, *args, **kwargs): + # type: (str, WindowManager, *Any, **Any) -> bool + """Resolve a textual positioning command and execute it.""" + cmds = [] + success = True + if ',' in command: + cmds = [i.strip() for i in command.split(',')] + for cmd in cmds: + success = self.checkCommand(cmd, winman, *args, **kwargs) + else: + return self.checkCommand(command,winman,*args,**kwargs) + + return success + #: The instance of L{CommandRegistry} to be used in 99.9% of use cases. commands = CommandRegistry() @@ -341,6 +354,20 @@ def move_to_position(winman, # type: WindowManager winman.reposition(win, result, use_rect, gravity=gravity, geometry_mask=gravity_mask) +@commands.add('WithBorder') +def add_decoration(winman, win, state): # pylint: disable=unused-argument + # type: (WindowManager, wnck.Window, Any) -> None + """Add window decoration on the active window.""" + win = gtk.gdk.window_foreign_new(win.get_xid()) + win.set_decorations(True) + +@commands.add('borderless') +def remove_decoration(winman, win, state): # pylint: disable=unused-argument + # type: (WindowManager, wnck.Window, Any) -> None + """Remove window decoration on the active window.""" + win = gtk.gdk.window_foreign_new(win.get_xid()) + win.set_decorations(False) + @commands.add('bordered') def toggle_decorated(winman, win, state): # pylint: disable=unused-argument # type: (WindowManager, wnck.Window, Any) -> None From f4064c3e4af8cd0ecbfccd62f99c6ecb9387b31f Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Sat, 16 Sep 2017 02:45:49 -0600 Subject: [PATCH 2/9] Housekeeping --- quicktile/commands.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index 2a247c4..cb063ef 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -167,7 +167,8 @@ def decorate(func): return func return decorate - def checkCommand(self, command,winman,*args,**kwargs): + def check_command(self, command, winman, *args, **kwargs): + """ check if the command is valid and execute it""" # type: (str, WindowManager, *Any, **Any) -> bool cmd = self.commands.get(command, None) @@ -190,11 +191,11 @@ def call(self, command, winman, *args, **kwargs): if ',' in command: cmds = [i.strip() for i in command.split(',')] for cmd in cmds: - success = self.checkCommand(cmd, winman, *args, **kwargs) + success = self.check_command(cmd, winman, *args, **kwargs) else: - return self.checkCommand(command,winman,*args,**kwargs) + return self.check_command(command, winman, *args, **kwargs) - return success + return success #: The instance of L{CommandRegistry} to be used in 99.9% of use cases. @@ -354,26 +355,17 @@ def move_to_position(winman, # type: WindowManager winman.reposition(win, result, use_rect, gravity=gravity, geometry_mask=gravity_mask) -@commands.add('WithBorder') -def add_decoration(winman, win, state): # pylint: disable=unused-argument - # type: (WindowManager, wnck.Window, Any) -> None - """Add window decoration on the active window.""" - win = gtk.gdk.window_foreign_new(win.get_xid()) - win.set_decorations(True) - -@commands.add('borderless') -def remove_decoration(winman, win, state): # pylint: disable=unused-argument - # type: (WindowManager, wnck.Window, Any) -> None - """Remove window decoration on the active window.""" - win = gtk.gdk.window_foreign_new(win.get_xid()) - win.set_decorations(False) - +@commands.add('WithBorder', True) +@commands.add('borderless', False) @commands.add('bordered') -def toggle_decorated(winman, win, state): # pylint: disable=unused-argument +def toggle_decorated(winman, win, state, decoration=None): # pylint: disable=unused-argument # type: (WindowManager, wnck.Window, Any) -> None """Toggle window decoration state on the active window.""" win = gtk.gdk.window_foreign_new(win.get_xid()) - win.set_decorations(not win.get_decorations()) + if decoration is not None: + win.set_decorations(decoration) + else: + win.set_decorations(not win.get_decorations()) @commands.add('show-desktop', windowless=True) def toggle_desktop(winman, win, state): # pylint: disable=unused-argument From 8d0d0e925ea0095b5438ffc7322fa25e1e4d27e2 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Mon, 25 Sep 2017 15:17:34 -0600 Subject: [PATCH 3/9] naming convensions and docstring update --- quicktile/__main__.py | 2 +- quicktile/commands.py | 9 +++++---- quicktile/dbus_api.py | 4 ++-- quicktile/keybinder.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/quicktile/__main__.py b/quicktile/__main__.py index 09d2385..5ec27bd 100644 --- a/quicktile/__main__.py +++ b/quicktile/__main__.py @@ -311,7 +311,7 @@ def main(): # type: () -> None winman.screen.force_update() for arg in args: - commands.commands.call(arg, winman) + commands.commands.call_multiple(arg, winman) while gtk.events_pending(): # pylint: disable=no-member gtk.main_iteration() # pylint: disable=no-member elif not opts.show_args and not opts.show_binds: diff --git a/quicktile/commands.py b/quicktile/commands.py index cb063ef..553a20a 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -183,9 +183,10 @@ def check_command(self, command, winman, *args, **kwargs): logging.error("Unrecognized command: %s", command) return False - def call(self, command, winman, *args, **kwargs): + def call_multiple(self, command, winman, *args, **kwargs): # type: (str, WindowManager, *Any, **Any) -> bool - """Resolve a textual positioning command and execute it.""" + """Resolve a textual positioning command and execute it. + Accepts a comma seperated list as the command.""" cmds = [] success = True if ',' in command: @@ -355,8 +356,8 @@ def move_to_position(winman, # type: WindowManager winman.reposition(win, result, use_rect, gravity=gravity, geometry_mask=gravity_mask) -@commands.add('WithBorder', True) -@commands.add('borderless', False) +@commands.add('bordered-set', True) +@commands.add('bordered-unset', False) @commands.add('bordered') def toggle_decorated(winman, win, state, decoration=None): # pylint: disable=unused-argument # type: (WindowManager, wnck.Window, Any) -> None diff --git a/quicktile/dbus_api.py b/quicktile/dbus_api.py index fa4580b..f4b0130 100644 --- a/quicktile/dbus_api.py +++ b/quicktile/dbus_api.py @@ -39,8 +39,8 @@ def doCommand(self, command): # type: (str) -> bool """Execute a QuickTile tiling command @todo 1.0.0: Expose a proper, introspectable D-Bus API""" - return self.commands.call(command, self.winman) - # FIXME: self.commands.call always returns None + return self.commands.call_multiple(command, self.winman) + # FIXME: self.commands.call_multiple always returns None def init(commands, # type: CommandRegistry winman # type: WindowManager diff --git a/quicktile/keybinder.py b/quicktile/keybinder.py index 6670ca6..3f08fb3 100644 --- a/quicktile/keybinder.py +++ b/quicktile/keybinder.py @@ -222,7 +222,7 @@ def init(modmask, # type: Optional[str] def call(func=func): """Closure to resolve `func` and call it on a `WindowManager` instance""" - commands.call(func, winman) + commands.call_multiple(func, winman) keybinder.bind(modmask + key, call) return keybinder From 76e97dcf9c768f08f3d29260dcd744dd16407d83 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Mon, 25 Sep 2017 15:23:11 -0600 Subject: [PATCH 4/9] changine check_command back into call --- quicktile/commands.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index 553a20a..aa689eb 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -167,8 +167,8 @@ def decorate(func): return func return decorate - def check_command(self, command, winman, *args, **kwargs): - """ check if the command is valid and execute it""" + def call(self, command, winman, *args, **kwargs): + """Check if the command is valid and execute it.""" # type: (str, WindowManager, *Any, **Any) -> bool cmd = self.commands.get(command, None) @@ -192,9 +192,9 @@ def call_multiple(self, command, winman, *args, **kwargs): if ',' in command: cmds = [i.strip() for i in command.split(',')] for cmd in cmds: - success = self.check_command(cmd, winman, *args, **kwargs) + success = self.call(cmd, winman, *args, **kwargs) else: - return self.check_command(command, winman, *args, **kwargs) + return self.call(command, winman, *args, **kwargs) return success From cdf7ea0ac272443e53ed8e23c48039459e14f755 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Sun, 22 Oct 2017 23:01:07 -0600 Subject: [PATCH 5/9] Resolving type issue --- quicktile/commands.py | 126 +++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index aa689eb..6b6ad4c 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -57,9 +57,9 @@ def get_window_meta(window, state, winman): # FIXME: Make calls to win.get_* lazy in case --debug # wasn't passed. logging.debug("Operating on window %r with title \"%s\" " - "and geometry %r", - window, window.get_name(), - window.get_geometry()) + "and geometry %r", + window, window.get_name(), + window.get_geometry()) monitor_id, monitor_geom = winman.get_monitor(window) use_area, use_rect = winman.workarea.get(monitor_geom) @@ -68,8 +68,8 @@ def get_window_meta(window, state, winman): # comprehensive exception catcher. if not use_rect: logging.debug("Received a worthless value for largest " - "rectangular subset of desktop (%r). Doing " - "nothing.", use_rect) + "rectangular subset of desktop (%r). Doing " + "nothing.", use_rect) return False state.update({ @@ -77,7 +77,7 @@ def get_window_meta(window, state, winman): "monitor_geom": monitor_geom, "usable_region": use_area, "usable_rect": use_rect, - }) + }) return True def add(self, name, *p_args, **p_kwargs): @@ -103,10 +103,10 @@ def decorate(func): # type: (CommandCB) -> CommandCB @wraps(func) # pylint: disable=missing-docstring def wrapper(winman, # type: WindowManager - window=None, # type: wnck.Window - *args, - **kwargs - ): # type: (...) -> None + window=None, # type: wnck.Window + *args, + **kwargs + ): # type: (...) -> None window = window or winman.screen.get_active_window() @@ -121,7 +121,7 @@ def wrapper(winman, # type: WindowManager # Bail out early on None or things like the desktop window if not (windowless or self.get_window_meta( - window, state, winman)): + window, state, winman)): logging.debug("No window and windowless=False") return None @@ -140,8 +140,8 @@ def wrapper(winman, # type: WindowManager if not func.__doc__: raise AssertionError("All commands must have a docstring: " - "%r" % func) - help_str = func.__doc__.strip().split('\n')[0].split('. ')[0] + "%r" % func) + help_str = func.__doc__.strip().split('\n')[0].split('. ')[0] self.help[name] = help_str.strip('.') # Return the unwrapped function so decorators can be stacked @@ -174,7 +174,7 @@ def call(self, command, winman, *args, **kwargs): if cmd: logging.debug("Executing command '%s' with arguments %r, %r", - command, args, kwargs) + command, args, kwargs) cmd(winman, *args, **kwargs) # TODO: Allow commands to report success or failure @@ -184,7 +184,7 @@ def call(self, command, winman, *args, **kwargs): return False def call_multiple(self, command, winman, *args, **kwargs): - # type: (str, WindowManager, *Any, **Any) -> bool + # type: (List[str], WindowManager, *Any, **Any) -> bool """Resolve a textual positioning command and execute it. Accepts a comma seperated list as the command.""" cmds = [] @@ -203,10 +203,10 @@ def call_multiple(self, command, winman, *args, **kwargs): commands = CommandRegistry() def cycle_dimensions(winman, # type: WindowManager - win, # type: Any # TODO: Consistent Window type - state, # type: Dict[str, Any] - *dimensions # type: Any - ): # type: (...) -> Optional[gtk.gdk.Rectangle] + win, # type: Any # TODO: Consistent Window type + state, # type: Dict[str, Any] + *dimensions # type: Any + ): # type: (...) -> Optional[gtk.gdk.Rectangle] # type: (WindowManager, Any, Dict[str, Any], *Tuple[...]) -> # TODO: Standardize on what kind of window object to pass around """Cycle the active window through a list of positions and shapes. @@ -238,7 +238,7 @@ def cycle_dimensions(winman, # type: WindowManager return None logging.debug("Selected preset sequence resolves to these monitor-relative" - " pixel dimensions:\n\t%r", dims) + " pixel dimensions:\n\t%r", dims) try: cmd_idx, pos = winman.get_property('_QUICKTILE_CYCLE_POS', win)[2] @@ -251,11 +251,11 @@ def cycle_dimensions(winman, # type: WindowManager pos = 0 winman.set_property('_QUICKTILE_CYCLE_POS', - (state.get('cmd_idx', 0), pos), win) + (state.get('cmd_idx', 0), pos), win) result = gtk.gdk.Rectangle(*dims[pos]) logging.debug("Target preset is %s relative to monitor %s", - result, clip_box) + result, clip_box) result.x += clip_box.x result.y += clip_box.y @@ -265,25 +265,25 @@ def cycle_dimensions(winman, # type: WindowManager if not usable_region.rect_in(result) == gtk.gdk.OVERLAP_RECTANGLE_IN: result = result.intersect(state['usable_rect']) logging.debug("Result exceeds usable (non-rectangular) region of " - "desktop. (overlapped a non-fullwidth panel?) Reducing " - "to within largest usable rectangle: %s", - state['usable_rect']) + "desktop. (overlapped a non-fullwidth panel?) Reducing " + "to within largest usable rectangle: %s", + state['usable_rect']) - logging.debug("Calling reposition() with default gravity and dimensions " - "%r", tuple(result)) - winman.reposition(win, result) + logging.debug("Calling reposition() with default gravity and dimensions " + "%r", tuple(result)) + winman.reposition(win, result) return result @commands.add('monitor-switch', force_wrap=True) @commands.add('monitor-next', 1) @commands.add('monitor-prev', -1) def cycle_monitors(winman, # type: WindowManager - win, # type: wnck.Window - state, # type: Dict[str, Any] - step=1, # type: int - force_wrap=False, # type: bool - n_monitors=None # type: Optional[int] - ): # type: (...) -> None + win, # type: wnck.Window + state, # type: Dict[str, Any] + step=1, # type: int + force_wrap=False, # type: bool + n_monitors=None # type: Optional[int] + ): # type: (...) -> None """Cycle the active window between monitors while preserving position. @todo 1.0.0: Remove C{monitor-switch} in favor of C{monitor-next} @@ -293,12 +293,12 @@ def cycle_monitors(winman, # type: WindowManager n_monitors = n_monitors or winman.gdk_screen.get_n_monitors() new_mon_id = clamp_idx(mon_id + step, n_monitors, - state['config'].getboolean('general', 'MovementsWrap') or - force_wrap) + state['config'].getboolean('general', 'MovementsWrap') or + force_wrap) new_mon_geom = winman.gdk_screen.get_monitor_geometry(new_mon_id) logging.debug("Moving window to monitor %s, which has geometry %s", - new_mon_id, new_mon_geom) + new_mon_id, new_mon_geom) winman.reposition(win, None, new_mon_geom, keep_maximize=True) @@ -320,29 +320,29 @@ def cycle_monitors_all(winman, win, state, step=1, force_wrap=False): # pylint: disable=no-member MOVE_TO_COMMANDS = { - 'move-to-top-left': [wnck.WINDOW_GRAVITY_NORTHWEST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-top': [wnck.WINDOW_GRAVITY_NORTH, wnck.WINDOW_CHANGE_Y], - 'move-to-top-right': [wnck.WINDOW_GRAVITY_NORTHEAST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-left': [wnck.WINDOW_GRAVITY_WEST, wnck.WINDOW_CHANGE_X], - 'move-to-center': [wnck.WINDOW_GRAVITY_CENTER, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-right': [wnck.WINDOW_GRAVITY_EAST, wnck.WINDOW_CHANGE_X], - 'move-to-bottom-left': [wnck.WINDOW_GRAVITY_SOUTHWEST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-bottom': [wnck.WINDOW_GRAVITY_SOUTH, wnck.WINDOW_CHANGE_Y], - 'move-to-bottom-right': [wnck.WINDOW_GRAVITY_SOUTHEAST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], -} + 'move-to-top-left': [wnck.WINDOW_GRAVITY_NORTHWEST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-top': [wnck.WINDOW_GRAVITY_NORTH, wnck.WINDOW_CHANGE_Y], + 'move-to-top-right': [wnck.WINDOW_GRAVITY_NORTHEAST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-left': [wnck.WINDOW_GRAVITY_WEST, wnck.WINDOW_CHANGE_X], + 'move-to-center': [wnck.WINDOW_GRAVITY_CENTER, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-right': [wnck.WINDOW_GRAVITY_EAST, wnck.WINDOW_CHANGE_X], + 'move-to-bottom-left': [wnck.WINDOW_GRAVITY_SOUTHWEST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-bottom': [wnck.WINDOW_GRAVITY_SOUTH, wnck.WINDOW_CHANGE_Y], + 'move-to-bottom-right': [wnck.WINDOW_GRAVITY_SOUTHEAST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + } @commands.add_many(MOVE_TO_COMMANDS) def move_to_position(winman, # type: WindowManager - win, # type: Any # TODO: Make this specific - state, # type: Dict[str, Any] - gravity, # type: Any # TODO: Make this specific - gravity_mask # type: wnck.WindowMoveResizeMask - ): # type: (...) -> None # TODO: Decide on a return type + win, # type: Any # TODO: Make this specific + state, # type: Dict[str, Any] + gravity, # type: Any # TODO: Make this specific + gravity_mask # type: wnck.WindowMoveResizeMask + ): # type: (...) -> None # TODO: Decide on a return type """Move window to a position on the screen, preserving its dimensions.""" use_rect = state['usable_rect'] @@ -350,13 +350,13 @@ def move_to_position(winman, # type: WindowManager dims = (int(use_rect.width * grav_x), int(use_rect.height * grav_y), 0, 0) result = gtk.gdk.Rectangle(*dims) logging.debug("Calling reposition() with %r gravity and dimensions %r", - gravity, tuple(result)) + gravity, tuple(result)) # pylint: disable=no-member winman.reposition(win, result, use_rect, gravity=gravity, geometry_mask=gravity_mask) -@commands.add('bordered-set', True) + @commands.add('bordered-set', True) @commands.add('bordered-unset', False) @commands.add('bordered') def toggle_decorated(winman, win, state, decoration=None): # pylint: disable=unused-argument @@ -378,9 +378,9 @@ def toggle_desktop(winman, win, state): # pylint: disable=unused-argument @commands.add('all-desktops', 'pin', 'is_pinned') @commands.add('fullscreen', 'set_fullscreen', 'is_fullscreen', True) @commands.add('vertical-maximize', 'maximize_vertically', - 'is_maximized_vertically') + 'is_maximized_vertically') @commands.add('horizontal-maximize', 'maximize_horizontally', - 'is_maximized_horizontally') + 'is_maximized_horizontally') @commands.add('maximize', 'maximize', 'is_maximized') @commands.add('minimize', 'minimize', 'is_minimized') @commands.add('always-above', 'make_above', 'is_above') @@ -431,7 +431,7 @@ def workspace_go(winman, win, state, motion): # pylint: disable=W0613 # type: (WindowManager, wnck.Window, Any, wnck.MotionDirection) -> None """Switch the active workspace (next/prev wrap around)""" target = winman.get_workspace(None, motion, - wrap_around=state['config'].getboolean('general', 'MovementsWrap')) + wrap_around=state['config'].getboolean('general', 'MovementsWrap')) if not target: logging.debug("Couldn't get the active workspace.") return @@ -450,7 +450,7 @@ def workspace_send_window(winman, win, state, motion): # type: (WindowManager, wnck.Window, Any, wnck.MotionDirection) -> None """Move the active window to another workspace (next/prev wrap around)""" target = winman.get_workspace(win, motion, - wrap_around=state['config'].getboolean('general', 'MovementsWrap')) + wrap_around=state['config'].getboolean('general', 'MovementsWrap')) if not target: return # It's either pinned, on no workspaces, or there is no match From f4894f262eb984cad9add54602c4f3c71c0dbc82 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Sun, 22 Oct 2017 23:07:30 -0600 Subject: [PATCH 6/9] Resolving misplaced type annotation --- quicktile/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index 6b6ad4c..81850a3 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -184,9 +184,9 @@ def call(self, command, winman, *args, **kwargs): return False def call_multiple(self, command, winman, *args, **kwargs): - # type: (List[str], WindowManager, *Any, **Any) -> bool """Resolve a textual positioning command and execute it. Accepts a comma seperated list as the command.""" + # type: (str, WindowManager, *Any, **Any) -> bool cmds = [] success = True if ',' in command: From 7d4400a34ff94c3da8f1916d6cb7d3c4b79491e3 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Thu, 21 Dec 2017 16:19:09 -0700 Subject: [PATCH 7/9] Correcting type annotations. --- quicktile/commands.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index aa689eb..c4b0501 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -168,8 +168,8 @@ def decorate(func): return decorate def call(self, command, winman, *args, **kwargs): - """Check if the command is valid and execute it.""" # type: (str, WindowManager, *Any, **Any) -> bool + """Check if the command is valid and execute it.""" cmd = self.commands.get(command, None) if cmd: @@ -186,8 +186,8 @@ def call(self, command, winman, *args, **kwargs): def call_multiple(self, command, winman, *args, **kwargs): # type: (str, WindowManager, *Any, **Any) -> bool """Resolve a textual positioning command and execute it. - Accepts a comma seperated list as the command.""" - cmds = [] + Accepts a comma seperated string as the command.""" + cmds = [] #type: List[str] success = True if ',' in command: cmds = [i.strip() for i in command.split(',')] @@ -360,7 +360,7 @@ def move_to_position(winman, # type: WindowManager @commands.add('bordered-unset', False) @commands.add('bordered') def toggle_decorated(winman, win, state, decoration=None): # pylint: disable=unused-argument - # type: (WindowManager, wnck.Window, Any) -> None + # type: (WindowManager, wnck.Window, Any, Optional[bool]) -> None """Toggle window decoration state on the active window.""" win = gtk.gdk.window_foreign_new(win.get_xid()) if decoration is not None: From f90de3d052c41cc40b70468394bffebd5bc1f385 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Thu, 21 Dec 2017 16:31:31 -0700 Subject: [PATCH 8/9] Revert "Resolving misplaced type annotation" This reverts commit f4892f262eb984cad9add54602c4f3c71c0dbc82. --- quicktile/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index 81850a3..6b6ad4c 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -184,9 +184,9 @@ def call(self, command, winman, *args, **kwargs): return False def call_multiple(self, command, winman, *args, **kwargs): + # type: (List[str], WindowManager, *Any, **Any) -> bool """Resolve a textual positioning command and execute it. Accepts a comma seperated list as the command.""" - # type: (str, WindowManager, *Any, **Any) -> bool cmds = [] success = True if ',' in command: From 4d4797589554c12d58ea1908dfe4463203b7c684 Mon Sep 17 00:00:00 2001 From: Harindu Dilshan Date: Thu, 21 Dec 2017 16:32:09 -0700 Subject: [PATCH 9/9] Revert "Resolving type issue" This reverts commit cdf6ea0ac272443e53ed8e23c48039459e14f755. --- quicktile/commands.py | 126 +++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/quicktile/commands.py b/quicktile/commands.py index 6b6ad4c..aa689eb 100644 --- a/quicktile/commands.py +++ b/quicktile/commands.py @@ -57,9 +57,9 @@ def get_window_meta(window, state, winman): # FIXME: Make calls to win.get_* lazy in case --debug # wasn't passed. logging.debug("Operating on window %r with title \"%s\" " - "and geometry %r", - window, window.get_name(), - window.get_geometry()) + "and geometry %r", + window, window.get_name(), + window.get_geometry()) monitor_id, monitor_geom = winman.get_monitor(window) use_area, use_rect = winman.workarea.get(monitor_geom) @@ -68,8 +68,8 @@ def get_window_meta(window, state, winman): # comprehensive exception catcher. if not use_rect: logging.debug("Received a worthless value for largest " - "rectangular subset of desktop (%r). Doing " - "nothing.", use_rect) + "rectangular subset of desktop (%r). Doing " + "nothing.", use_rect) return False state.update({ @@ -77,7 +77,7 @@ def get_window_meta(window, state, winman): "monitor_geom": monitor_geom, "usable_region": use_area, "usable_rect": use_rect, - }) + }) return True def add(self, name, *p_args, **p_kwargs): @@ -103,10 +103,10 @@ def decorate(func): # type: (CommandCB) -> CommandCB @wraps(func) # pylint: disable=missing-docstring def wrapper(winman, # type: WindowManager - window=None, # type: wnck.Window - *args, - **kwargs - ): # type: (...) -> None + window=None, # type: wnck.Window + *args, + **kwargs + ): # type: (...) -> None window = window or winman.screen.get_active_window() @@ -121,7 +121,7 @@ def wrapper(winman, # type: WindowManager # Bail out early on None or things like the desktop window if not (windowless or self.get_window_meta( - window, state, winman)): + window, state, winman)): logging.debug("No window and windowless=False") return None @@ -140,8 +140,8 @@ def wrapper(winman, # type: WindowManager if not func.__doc__: raise AssertionError("All commands must have a docstring: " - "%r" % func) - help_str = func.__doc__.strip().split('\n')[0].split('. ')[0] + "%r" % func) + help_str = func.__doc__.strip().split('\n')[0].split('. ')[0] self.help[name] = help_str.strip('.') # Return the unwrapped function so decorators can be stacked @@ -174,7 +174,7 @@ def call(self, command, winman, *args, **kwargs): if cmd: logging.debug("Executing command '%s' with arguments %r, %r", - command, args, kwargs) + command, args, kwargs) cmd(winman, *args, **kwargs) # TODO: Allow commands to report success or failure @@ -184,7 +184,7 @@ def call(self, command, winman, *args, **kwargs): return False def call_multiple(self, command, winman, *args, **kwargs): - # type: (List[str], WindowManager, *Any, **Any) -> bool + # type: (str, WindowManager, *Any, **Any) -> bool """Resolve a textual positioning command and execute it. Accepts a comma seperated list as the command.""" cmds = [] @@ -203,10 +203,10 @@ def call_multiple(self, command, winman, *args, **kwargs): commands = CommandRegistry() def cycle_dimensions(winman, # type: WindowManager - win, # type: Any # TODO: Consistent Window type - state, # type: Dict[str, Any] - *dimensions # type: Any - ): # type: (...) -> Optional[gtk.gdk.Rectangle] + win, # type: Any # TODO: Consistent Window type + state, # type: Dict[str, Any] + *dimensions # type: Any + ): # type: (...) -> Optional[gtk.gdk.Rectangle] # type: (WindowManager, Any, Dict[str, Any], *Tuple[...]) -> # TODO: Standardize on what kind of window object to pass around """Cycle the active window through a list of positions and shapes. @@ -238,7 +238,7 @@ def cycle_dimensions(winman, # type: WindowManager return None logging.debug("Selected preset sequence resolves to these monitor-relative" - " pixel dimensions:\n\t%r", dims) + " pixel dimensions:\n\t%r", dims) try: cmd_idx, pos = winman.get_property('_QUICKTILE_CYCLE_POS', win)[2] @@ -251,11 +251,11 @@ def cycle_dimensions(winman, # type: WindowManager pos = 0 winman.set_property('_QUICKTILE_CYCLE_POS', - (state.get('cmd_idx', 0), pos), win) + (state.get('cmd_idx', 0), pos), win) result = gtk.gdk.Rectangle(*dims[pos]) logging.debug("Target preset is %s relative to monitor %s", - result, clip_box) + result, clip_box) result.x += clip_box.x result.y += clip_box.y @@ -265,25 +265,25 @@ def cycle_dimensions(winman, # type: WindowManager if not usable_region.rect_in(result) == gtk.gdk.OVERLAP_RECTANGLE_IN: result = result.intersect(state['usable_rect']) logging.debug("Result exceeds usable (non-rectangular) region of " - "desktop. (overlapped a non-fullwidth panel?) Reducing " - "to within largest usable rectangle: %s", - state['usable_rect']) + "desktop. (overlapped a non-fullwidth panel?) Reducing " + "to within largest usable rectangle: %s", + state['usable_rect']) - logging.debug("Calling reposition() with default gravity and dimensions " - "%r", tuple(result)) - winman.reposition(win, result) + logging.debug("Calling reposition() with default gravity and dimensions " + "%r", tuple(result)) + winman.reposition(win, result) return result @commands.add('monitor-switch', force_wrap=True) @commands.add('monitor-next', 1) @commands.add('monitor-prev', -1) def cycle_monitors(winman, # type: WindowManager - win, # type: wnck.Window - state, # type: Dict[str, Any] - step=1, # type: int - force_wrap=False, # type: bool - n_monitors=None # type: Optional[int] - ): # type: (...) -> None + win, # type: wnck.Window + state, # type: Dict[str, Any] + step=1, # type: int + force_wrap=False, # type: bool + n_monitors=None # type: Optional[int] + ): # type: (...) -> None """Cycle the active window between monitors while preserving position. @todo 1.0.0: Remove C{monitor-switch} in favor of C{monitor-next} @@ -293,12 +293,12 @@ def cycle_monitors(winman, # type: WindowManager n_monitors = n_monitors or winman.gdk_screen.get_n_monitors() new_mon_id = clamp_idx(mon_id + step, n_monitors, - state['config'].getboolean('general', 'MovementsWrap') or - force_wrap) + state['config'].getboolean('general', 'MovementsWrap') or + force_wrap) new_mon_geom = winman.gdk_screen.get_monitor_geometry(new_mon_id) logging.debug("Moving window to monitor %s, which has geometry %s", - new_mon_id, new_mon_geom) + new_mon_id, new_mon_geom) winman.reposition(win, None, new_mon_geom, keep_maximize=True) @@ -320,29 +320,29 @@ def cycle_monitors_all(winman, win, state, step=1, force_wrap=False): # pylint: disable=no-member MOVE_TO_COMMANDS = { - 'move-to-top-left': [wnck.WINDOW_GRAVITY_NORTHWEST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-top': [wnck.WINDOW_GRAVITY_NORTH, wnck.WINDOW_CHANGE_Y], - 'move-to-top-right': [wnck.WINDOW_GRAVITY_NORTHEAST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-left': [wnck.WINDOW_GRAVITY_WEST, wnck.WINDOW_CHANGE_X], - 'move-to-center': [wnck.WINDOW_GRAVITY_CENTER, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-right': [wnck.WINDOW_GRAVITY_EAST, wnck.WINDOW_CHANGE_X], - 'move-to-bottom-left': [wnck.WINDOW_GRAVITY_SOUTHWEST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - 'move-to-bottom': [wnck.WINDOW_GRAVITY_SOUTH, wnck.WINDOW_CHANGE_Y], - 'move-to-bottom-right': [wnck.WINDOW_GRAVITY_SOUTHEAST, - wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], - } + 'move-to-top-left': [wnck.WINDOW_GRAVITY_NORTHWEST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-top': [wnck.WINDOW_GRAVITY_NORTH, wnck.WINDOW_CHANGE_Y], + 'move-to-top-right': [wnck.WINDOW_GRAVITY_NORTHEAST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-left': [wnck.WINDOW_GRAVITY_WEST, wnck.WINDOW_CHANGE_X], + 'move-to-center': [wnck.WINDOW_GRAVITY_CENTER, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-right': [wnck.WINDOW_GRAVITY_EAST, wnck.WINDOW_CHANGE_X], + 'move-to-bottom-left': [wnck.WINDOW_GRAVITY_SOUTHWEST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], + 'move-to-bottom': [wnck.WINDOW_GRAVITY_SOUTH, wnck.WINDOW_CHANGE_Y], + 'move-to-bottom-right': [wnck.WINDOW_GRAVITY_SOUTHEAST, + wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y], +} @commands.add_many(MOVE_TO_COMMANDS) def move_to_position(winman, # type: WindowManager - win, # type: Any # TODO: Make this specific - state, # type: Dict[str, Any] - gravity, # type: Any # TODO: Make this specific - gravity_mask # type: wnck.WindowMoveResizeMask - ): # type: (...) -> None # TODO: Decide on a return type + win, # type: Any # TODO: Make this specific + state, # type: Dict[str, Any] + gravity, # type: Any # TODO: Make this specific + gravity_mask # type: wnck.WindowMoveResizeMask + ): # type: (...) -> None # TODO: Decide on a return type """Move window to a position on the screen, preserving its dimensions.""" use_rect = state['usable_rect'] @@ -350,13 +350,13 @@ def move_to_position(winman, # type: WindowManager dims = (int(use_rect.width * grav_x), int(use_rect.height * grav_y), 0, 0) result = gtk.gdk.Rectangle(*dims) logging.debug("Calling reposition() with %r gravity and dimensions %r", - gravity, tuple(result)) + gravity, tuple(result)) # pylint: disable=no-member winman.reposition(win, result, use_rect, gravity=gravity, geometry_mask=gravity_mask) - @commands.add('bordered-set', True) +@commands.add('bordered-set', True) @commands.add('bordered-unset', False) @commands.add('bordered') def toggle_decorated(winman, win, state, decoration=None): # pylint: disable=unused-argument @@ -378,9 +378,9 @@ def toggle_desktop(winman, win, state): # pylint: disable=unused-argument @commands.add('all-desktops', 'pin', 'is_pinned') @commands.add('fullscreen', 'set_fullscreen', 'is_fullscreen', True) @commands.add('vertical-maximize', 'maximize_vertically', - 'is_maximized_vertically') + 'is_maximized_vertically') @commands.add('horizontal-maximize', 'maximize_horizontally', - 'is_maximized_horizontally') + 'is_maximized_horizontally') @commands.add('maximize', 'maximize', 'is_maximized') @commands.add('minimize', 'minimize', 'is_minimized') @commands.add('always-above', 'make_above', 'is_above') @@ -431,7 +431,7 @@ def workspace_go(winman, win, state, motion): # pylint: disable=W0613 # type: (WindowManager, wnck.Window, Any, wnck.MotionDirection) -> None """Switch the active workspace (next/prev wrap around)""" target = winman.get_workspace(None, motion, - wrap_around=state['config'].getboolean('general', 'MovementsWrap')) + wrap_around=state['config'].getboolean('general', 'MovementsWrap')) if not target: logging.debug("Couldn't get the active workspace.") return @@ -450,7 +450,7 @@ def workspace_send_window(winman, win, state, motion): # type: (WindowManager, wnck.Window, Any, wnck.MotionDirection) -> None """Move the active window to another workspace (next/prev wrap around)""" target = winman.get_workspace(win, motion, - wrap_around=state['config'].getboolean('general', 'MovementsWrap')) + wrap_around=state['config'].getboolean('general', 'MovementsWrap')) if not target: return # It's either pinned, on no workspaces, or there is no match