-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import a2ctrl | ||
from a2qt import QtWidgets | ||
from a2element import DrawCtrl, EditCtrl | ||
from a2widget import a2item_editor, a2text_field | ||
|
||
|
||
class Draw(DrawCtrl): | ||
""" | ||
The frontend widget visible to the user with options | ||
to change the default behavior of the element. | ||
""" | ||
|
||
def __init__(self, *args): | ||
super(Draw, self).__init__(*args) | ||
self.main_layout = QtWidgets.QVBoxLayout(self) | ||
self.main_layout.setContentsMargins(0, 0, 0, 0) | ||
|
||
self.editor = a2item_editor.A2ItemEditor(self) | ||
# self.editor.ignore_default_values = False | ||
self.editor.set_data(self.user_cfg) | ||
self.editor.data_changed.connect(self.delayed_check) | ||
self.main_layout.addWidget(self.editor) | ||
self.is_expandable_widget = True | ||
|
||
url = a2text_field.A2CodeField(self) | ||
self.editor.add_data_label_widget('url', url, url.setText, url.editing_finished, '', 'URL') | ||
|
||
def check(self): | ||
self.user_cfg.update(self.editor.data) | ||
self.set_user_value(self.user_cfg) | ||
self.change() | ||
|
||
|
||
class Edit(EditCtrl): | ||
""" | ||
The background widget that sets up how the user can edit the element, | ||
visible when editing the module. | ||
""" | ||
|
||
def __init__(self, cfg, main, parent_cfg): | ||
super(Edit, self).__init__(cfg, main, parent_cfg) | ||
|
||
@staticmethod | ||
def element_name(): | ||
"""The elements display name shown in UI""" | ||
return 'Websearch_Lister' | ||
|
||
@staticmethod | ||
def element_icon(): | ||
return a2ctrl.Icons.inst().check | ||
|
||
|
||
def get_settings(module_key, cfg, db_dict, user_cfg): | ||
if user_cfg: | ||
db_dict['variables']['websearch_data'] = user_cfg |
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,37 @@ | ||
[ | ||
{ | ||
"author": "eric", | ||
"date": "2021 8 19", | ||
"description": "Look up selected text on any search engine via Hotkey or menu.", | ||
"display_name": "", | ||
"tags": [ | ||
"lookup" | ||
], | ||
"typ": "nfo", | ||
"url": "", | ||
"version": "0.1" | ||
}, | ||
{ | ||
"disablable": true, | ||
"enabled": true, | ||
"functionCode": "websearch()", | ||
"functionMode": 0, | ||
"key": [ | ||
"Win+W" | ||
], | ||
"keyChange": true, | ||
"label": "Call the WebSeach menu", | ||
"multiple": true, | ||
"name": "WebSearch_Hotkey", | ||
"scopeChange": true, | ||
"typ": "hotkey" | ||
}, | ||
{ | ||
"file": "websearch.ahk", | ||
"typ": "include" | ||
}, | ||
{ | ||
"name": "websearch_lister", | ||
"typ": "a2_local_element" | ||
} | ||
] |
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,37 @@ | ||
; WebSearch - websearch.ahk | ||
; author: eric | ||
; created: 2021 8 19 | ||
|
||
websearch() { | ||
if !websearch_data | ||
{ | ||
MsgBox, Nothing set up?!, Please open the user interface of "WebSearch" and add at least one item. | ||
Return | ||
} | ||
|
||
global _webseach_selection := clipboard_get() | ||
|
||
for name, data in websearch_data | ||
Menu, WebSearchMenu, Add, %name%, websearch_handler | ||
|
||
Menu, WebSearchMenu, Show | ||
Menu, WebSearchMenu, DeleteAll | ||
} | ||
|
||
websearch_handler(menu_name) { | ||
global _webseach_selection | ||
phrase := _webseach_selection | ||
_webseach_selection := "" | ||
|
||
if (!phrase) { | ||
msg := "Nothing selected! What do you want to look up on " menu_name "?" | ||
InputBox, phrase, WebSearch "%menu_name%", %msg%,,450, 130,,,,, | ||
if ErrorLevel | ||
Return | ||
if !phrase | ||
Return | ||
} | ||
|
||
url := StringReplace(websearch_data[menu_name]["url"], "###", phrase) | ||
Run, %url% | ||
} |