Skip to content

Commit

Permalink
sped up (un)learn as open commands
Browse files Browse the repository at this point in the history
fixed web search commands
fixed delayed Shift key state
  • Loading branch information
GChristensen committed Jul 13, 2022
1 parent 1efb15f commit cb3f9dd
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 264 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
##### 14.07.2022 (v.0.9.1)

* Sped up `learn as open` and `unlearn as open` commands.
* Fixed delayed Shift key state when localized input is enabled.
* Fixed web-search commands.

##### 24.12.2021 (v.0.9.0)
* Added experimental support of internationalized command input. Non-latin characters such as спасибо are allowed when
the current input language is not English. Set LOCALIZED_INPUT = False in the settings configuration block to disable
Expand Down
193 changes: 0 additions & 193 deletions commands.md

This file was deleted.

2 changes: 1 addition & 1 deletion enso/commands/idgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cmd_guid(ensoapi, format = "lowercase"):

random.seed()

boundsParser = re.compile(r"(?:from ?(\d+))? ?(?:to ?(\d+))?")
boundsParser = re.compile(r"(?:\s*from\s+?(\d+))?\s+?(?:to\s+?(\d+))?")

def cmd_random(ensoapi, from_num_to_num = ""):
"""Replaces selected text with a random number"""
Expand Down
23 changes: 15 additions & 8 deletions enso/commands/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,24 @@ def cmd_learn_as_open(ensoapi, name):
if is_url(file):
shortcut = PyInternetShortcut()

file_path = file_path + ".url"
shortcut.SetURL(file)
shortcut.QueryInterface( pythoncom.IID_IPersistFile ).Save(
file_path + ".url", 0 )
file_path, 0 )
else:
shortcut = PyShellLink()

shortcut.SetPath(file)
shortcut.SetWorkingDirectory(os.path.dirname(file))
shortcut.SetIconLocation(file, 0)

file_path = file_path + ".lnk"
shortcut.QueryInterface( pythoncom.IID_IPersistFile ).Save(
file_path + ".lnk", 0 )
file_path, 0 )

#time.sleep(0.5)
global shortcuts_map
shortcuts_map = Shortcuts.get().refreshShortcuts()
Shortcuts.get().add_shortcut(file_path)
cmd_open.valid_args = [s[1] for s in list(shortcuts_map.values())]
cmd_open_with.valid_args = [s[1] for s in list(shortcuts_map.values()) if s[0] == SHORTCUT_TYPE_EXECUTABLE]
cmd_unlearn_open.valid_args = [s[1] for s in list(shortcuts_map.values())]
Expand All @@ -186,17 +188,22 @@ def cmd_unlearn_open(ensoapi, name):
file_path = os.path.join(LEARN_AS_DIR, name)
if os.path.isfile(file_path + ".lnk"):
sl = PyShellLink()
sl.load(file_path + ".lnk")

file_path = file_path + ".lnk"
sl.load(file_path)
unlearn_open_undo.append([name, sl])
os.remove(file_path + ".lnk")
os.remove(file_path)
elif os.path.isfile(file_path + ".url"):
sl = PyInternetShortcut()
sl.load(file_path + ".url")

file_path = file_path + ".url"
sl.load(file_path)
unlearn_open_undo.append([name, sl])
os.remove(file_path + ".url")
os.remove(file_path)

global shortcuts_map
shortcuts_map = Shortcuts.get().refreshShortcuts()

Shortcuts.get().remove_shortcut(name.lower())
cmd_open.valid_args = [s[1] for s in list(shortcuts_map.values())]
cmd_open_with.valid_args = [s[1] for s in list(shortcuts_map.values()) if s[0] == SHORTCUT_TYPE_EXECUTABLE]
cmd_unlearn_open.valid_args = [s[1] for s in list(shortcuts_map.values())]
Expand Down
43 changes: 27 additions & 16 deletions enso/commands/web_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import xml.sax.saxutils
import logging
import json

from urllib.parse import urlparse, urlunparse

Expand All @@ -22,7 +23,7 @@ def __init__(self, target, args = None):
threading.Thread.__init__(self)
self.__success = False
self.__retval = None
self.setDaemon(True)
self.daemon = True
self.start()

def run(self):
Expand All @@ -33,12 +34,12 @@ def run(self):
self.__success = True

def wasSuccessful(self):
if self.isAlive():
if self.is_alive():
raise Exception( "Thread not finished" )
return self.__success

def getRetval(self):
if self.isAlive():
if self.is_alive():
raise Exception( "Thread not finished" )
return self.__retval

Expand Down Expand Up @@ -233,7 +234,7 @@ def cmd_is_down(ensoapi, url = None):
get_selection_thread = ThreadedFunc(
target = ensoapi.get_selection
)
while get_selection_thread.isAlive():
while get_selection_thread.is_alive():
yield
if get_selection_thread.wasSuccessful():
seldict = get_selection_thread.getRetval()
Expand All @@ -253,28 +254,38 @@ def cmd_is_down(ensoapi, url = None):
netloc = parsed_url.netloc
if netloc.endswith(":80"):
netloc = netloc[:-3]
base_url = scheme + "://" + netloc
#base_url = scheme + "://" + netloc
base_url = netloc

print(base_url)

query_url = "http://downforeveryoneorjustme.com/%s" % urllib.parse.quote_plus(base_url)
query_url = "https://api-prod.downfor.cloud/httpcheck/%s" % urllib.parse.quote_plus(base_url)
t = ThreadedFunc(
target = get_html,
args = (ensoapi, query_url))

while t.isAlive():
while t.is_alive():
yield

if t.wasSuccessful():
html = t.getRetval()
if html.find("It's just you") > -1:
displayMessage("<p>Site <command>%s</command> is online</p>" % base_url)
elif html.find("doesn't look like a site") > -1:
displayMessage("<p>Site <command>%s</command> is unknown!</p>" % base_url)
elif html.find("It's not just you") > -1:
result = json.loads(t.getRetval())
print(result)
if result["isDown"]:
displayMessage("<p>Site <command>%s</command> is down!</p>" % base_url)
else:
print(html)
else:
displayMessage("<p>Site <command>%s</command> is online</p>" % base_url)
else:
displayMessage("<p>Site <command>%s</command> is unknown!</p>" % base_url)

# html = t.getRetval()
# if html.find("It's just you") > -1:
# displayMessage("<p>Site <command>%s</command> is online</p>" % base_url)
# elif html.find("doesn't look like a site") > -1:
# displayMessage("<p>Site <command>%s</command> is unknown!</p>" % base_url)
# elif html.find("It's not just you") > -1:
# displayMessage("<p>Site <command>%s</command> is down!</p>" % base_url)
# else:
# print(html)


def cmd_url(ensoapi, parameter = None):
Expand Down Expand Up @@ -322,7 +333,7 @@ def get_url():

import re
thread = ThreadedFunc(make_get_url_func("http://checkip.dyndns.com/"))
while thread.isAlive():
while thread.is_alive():
yield
matches = []
ip = re.search("Address: ([^<]+)", thread.getRetval()).group(1)
Expand Down
1 change: 1 addition & 0 deletions enso/enso/platform/win32/selection/_ContextUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def translateKey( keyCode ):
try:
hkl = win32api.GetKeyboardLayout(dwFGThread)
sc = win32api.MapVirtualKey(keyCode, 0, hkl)
win32api.GetKeyState(win32con.VK_SHIFT) # shift state is delayed otherwise. magic!
kbst = win32api.GetKeyboardState()
kbst_buff = to_ctypes_char_buffer(kbst)

Expand Down
Loading

0 comments on commit cb3f9dd

Please sign in to comment.