-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from chaosparrot/feature/debugging
Feature/debugging
- Loading branch information
Showing
36 changed files
with
1,668 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from talon import actions, cron, scope, ui, app, Module | ||
from user.talon_hud.content.poller import Poller | ||
|
||
# Polls the current focused applications to show an indicator of where it is | ||
class FocusPoller(Poller): | ||
move_indicator_job = None | ||
previous_window_x = 0 | ||
previous_window_y = 0 | ||
|
||
def enable(self): | ||
if not self.enabled: | ||
self.enabled = True | ||
self.update_focus_indicator() | ||
ui.register('win_focus', self.update_focus_indicator) | ||
ui.register('win_resize', self.update_focus_indicator) | ||
ui.register('win_move', self.move_focus_indicator) | ||
|
||
def disable(self): | ||
self.enabled = False | ||
ui.unregister('win_focus', self.update_focus_indicator) | ||
ui.unregister('win_resize', self.update_focus_indicator) | ||
ui.unregister('win_move', self.move_focus_indicator) | ||
actions.user.hud_publish_screen_regions('overlay', [], True) | ||
cron.cancel(self.move_indicator_job) | ||
|
||
def update_focus_indicator(self, window = None): | ||
if not window or window.rect.width * window.rect.height > 0: | ||
active_window = ui.active_window() | ||
if active_window: | ||
app = ui.active_app() | ||
theme = actions.user.hud_get_theme() | ||
focus_colour = theme.get_colour('focus_indicator_background', 'DD4500') | ||
focus_text_colour = theme.get_colour('focus_indicator_text_colour', 'FFFFFF') | ||
|
||
self.previous_window_x = active_window.rect.x | ||
self.previous_window_y = active_window.rect.y | ||
regions = [actions.user.hud_create_screen_region('focus', focus_colour, '', '<*' + app.name, -1, active_window.rect.x, active_window.rect.y, active_window.rect.width, active_window.rect.height )] | ||
regions[0].text_colour = focus_text_colour | ||
regions[0].vertical_centered = False | ||
actions.user.hud_publish_screen_regions('overlay', regions, True) | ||
|
||
def move_focus_indicator(self, window): | ||
cron.cancel(self.move_indicator_job) | ||
|
||
active_window = ui.active_window() | ||
if active_window.rect.x != self.previous_window_x and active_window.rect.y != self.previous_window_y: | ||
self.move_indicator_job = cron.after("30ms", self.update_focus_indicator) | ||
|
||
def append_poller(): | ||
actions.user.hud_add_poller('focus', FocusPoller()) | ||
app.register('ready', append_poller) | ||
|
||
mod = Module() | ||
@mod.action_class | ||
class Actions: | ||
|
||
def hud_add_focus_indicator(): | ||
"""Start debugging the focus state in the Talon HUD""" | ||
actions.user.hud_add_poller('focus', FocusPoller()) | ||
actions.user.hud_activate_poller('focus') | ||
|
||
def hud_remove_focus_indicator(): | ||
"""Stop debugging the focus state in the Talon HUD""" | ||
actions.user.hud_deactivate_poller('focus') | ||
actions.user.hud_clear_screen_regions('overlay', 'focus') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from talon import actions, cron, registry, ui, app, Module | ||
from user.talon_hud.content.poller import Poller | ||
|
||
# Polls the current Talon registry lists for debugging purposes | ||
class ListPoller(Poller): | ||
job = None | ||
previous_list_state = '' | ||
list = None | ||
|
||
def enable(self): | ||
if (self.job is None): | ||
self.enabled = True | ||
scope_state = self.get_list_in_text() | ||
actions.user.hud_publish_content(scope_state, 'list', 'List inspection') | ||
|
||
self.job = cron.interval('200ms', self.list_check) | ||
|
||
def disable(self): | ||
cron.cancel(self.job) | ||
self.job = None | ||
self.enabled = False | ||
|
||
def list_check(self): | ||
list_state = self.get_list_in_text() | ||
if (list_state != self.previous_list_state): | ||
self.previous_list_state = list_state | ||
actions.user.hud_publish_content(list_state, 'list', 'List inspection', False) | ||
|
||
def get_list_in_text(self): | ||
content = "" | ||
if self.list in registry.lists: | ||
list_contents = registry.lists[self.list][-1] | ||
|
||
list_description = registry.decls.lists[self.list].desc if self.list in registry.decls.lists else "" | ||
if len(list_contents) == 0: | ||
content = "<*" + self.list + "/>\n" + list_description + "\n\n" | ||
else: | ||
content = "<*" + self.list + "(" + str(len(list_contents)) + ")/>\n" + list_description + "\n\n" | ||
|
||
# Bundle same values together so we have all the synonyms bundled | ||
content_choices = {} | ||
for option in list_contents: | ||
if list_contents[option] not in content_choices: | ||
content_choices[ list_contents[option] ] = [] | ||
|
||
content_choices[list_contents[option]].append( option )\ | ||
|
||
for value in content_choices: | ||
content += "<*" + "/><!! or /><*".join(content_choices[value]) + "/>: " + value + "\n" | ||
elif self.list is not None: | ||
content = "<*" + self.list + "/>\nList no longer exists!" | ||
|
||
return content | ||
|
||
def select_list(data): | ||
list_poller = ListPoller() | ||
list_poller.list = data["text"] | ||
actions.user.hud_add_poller('list', list_poller) | ||
actions.user.hud_activate_poller('list') | ||
|
||
mod = Module() | ||
@mod.action_class | ||
class Actions: | ||
|
||
def hud_toolkit_lists(): | ||
"""Show available lists to view for the Talon HUD""" | ||
lists = registry.lists | ||
choices = [] | ||
for index, key in enumerate(lists): | ||
if lists[key]: | ||
choices.append({"text": key}) | ||
|
||
choices = actions.user.hud_create_choices(choices, select_list) | ||
actions.user.hud_publish_choices(choices, "Toolkit lists", "Select a list to inspect by saying <*option <number>/> or saying the name of the list") | ||
|
Oops, something went wrong.