-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryPlugin.py
114 lines (95 loc) · 3.94 KB
/
QueryPlugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# ----------------------------------------------------------------
# Author: WayneFerdon [email protected]
# Date: 2023-03-04 12:45:55
# LastEditors: WayneFerdon [email protected]
# LastEditTime: 2023-04-11 05:26:28
# FilePath: \FlowLauncher\Plugins\WoxBasePluginQuery\QueryPlugin.py
# ----------------------------------------------------------------
# Copyright (c) 2023 by Wayne Ferdon Studio. All rights reserved.
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.
# ----------------------------------------------------------------
# -*- coding: utf-8 -*-
import win32con
import win32clipboard
import json
from Launcher import *
class Plugin(PluginBase):
with open('./plugin.json','r') as f:
pluginJson = json.load(f)
plugName = pluginJson['Name']
id = pluginJson['ID']
defaultIcon = pluginJson['IcoPath']
actionKeyword = Launcher.settings['PluginSettings']['Plugins'][id]['ActionKeywords'][0]
def close_launcher(self):
Launcher.close_launcher()
@staticmethod
def setPlatformAsPluginIcon():
launcherIcon = Launcher.icon
if Plugin.defaultIcon == launcherIcon:
return
Plugin.defaultIcon = Launcher.icon
Plugin.pluginJson['IcoPath'] = Plugin.defaultIcon
with open('./plugin.json','w') as f:
f.write(json.dumps(Plugin.pluginJson))
def __init__(self):
super().__init__()
def context_menu(self, data) -> list:
return super().context_menu(data)
def debug(self, msg: str):
return super().debug(msg)
def query(self, param: str = '') -> list:
return super().query(param)
class QueryPlugin(Plugin):
def copyData(self, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, data)
win32clipboard.CloseClipboard()
def getCopyDataResult(self, type, titleData, iconPath) -> dict:
title = type + ": " + titleData
subTitle = 'Press Enter to Copy ' + type
return QueryResult(title, subTitle, iconPath, None, self.copyData.__name__, True, titleData).toDict()
def getTitleOnlyResult(self, title:str):
return QueryResult(title,None,self.defaultIcon,None,None,False).toDict()
def getExceptionResult(self, traceback:str) -> dict:
return self.getTitleOnlyResult(traceback)
def context_menu(self, data) -> list:
return super().context_menu(data)
def debug(self, msg: str):
return super().debug(msg)
def query(self, param: str = '') -> list:
return super().query(param)
class InstallationCheck(Plugin):
def query(self, _:str):
if 'WoxBasePluginQuery' == Plugin.plugName:
Plugin.setPlatformAsPluginIcon()
msg = f'{Plugin.plugName} is installed.'
self.debug(msg=msg)
return [QueryResult(msg,None,Plugin.defaultIcon,None,None,False).toDict()]
class QueryResult:
def __init__(self, title:str, subtitle:str, icon:str, context, method:str, hideAfterAction:bool, *args) -> None:
self.title = title
self.subtitle = subtitle
self.icon = icon
self.context = context
self.method = method
self.hideAfterAction = hideAfterAction
self.parameters = args
def toDict(self):
jsonResult = {
'Title': self.title,
'SubTitle': self.subtitle,
'IcoPath': self.icon,
'ContextData': self.context
}
if self.method is not None:
jsonResult['JsonRPCAction'] = {
'method': self.method,
'parameters': self.parameters,
"doNotHideAfterAction".replace('oNo', 'on'): (not self.hideAfterAction),
}
return jsonResult
if __name__ == "__main__":
InstallationCheck()