Skip to content

Commit 5a27959

Browse files
authored
Add files via upload
1 parent 7a405fd commit 5a27959

File tree

3 files changed

+90
-47
lines changed

3 files changed

+90
-47
lines changed

entry.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Entry.py - ColorPicker
55

66

7-
__version__ = 1.0
7+
__version__ = 1.1
88
PLUGIN_ID = "tp.plugin.process_checker"
99
PLUGIN_NAME = "Process_Checker"
1010

@@ -75,21 +75,42 @@
7575
'valueChoices': ["0","5", "10", "15", "30", "45", "60", "120", "240"]
7676
},
7777
}
78-
}
78+
},
79+
80+
'Stop Process Monitor': {
81+
'category': "main",
82+
'id': PLUGIN_ID + ".act.stop_process.Monitor",
83+
'name': "Stop Process Monitor for [X]",
84+
'prefix': TP_PLUGIN_CATEGORIES['main']['name'],
85+
'type': "communicate",
86+
'tryInline': True,
87+
'format': "Stop $[1] Process Monitor",
88+
'data': {
89+
'Process Name to Stop': {
90+
'id': PLUGIN_ID + ".act.process_name.stop",
91+
'type': "choice",
92+
'label': "Text",
93+
'default': "ALL",
94+
'valueChoices': ["ALL"]
95+
}
96+
# 'check_per_seconds': {
97+
# 'id': PLUGIN_ID + ".act.process_name.checktime",
98+
# 'type': "choice",
99+
# 'label': "check every x seconds",
100+
# 'default': "0",
101+
# 'valueChoices': ["0","5", "10", "15", "30", "45", "60", "120", "240"]
102+
# },
103+
}
104+
},
105+
79106

80107
}
81108

82109
TP_PLUGIN_STATES = {
83-
'Text Name Style': {
84-
'category': "main",
85-
'id': PLUGIN_ID + ".state.current_text_name_style",
86-
'desc': "Color Picker: Text Name Style",
87-
'default': ""
88-
},
89-
'Last Mouse X': {
110+
'Total Monitors Running': {
90111
'category': "main",
91-
'id': PLUGIN_ID + ".state.last_mouse_x",
92-
'desc': "Color Picker: Last Mouse Location - X",
112+
'id': PLUGIN_ID + ".state.process_monitor.count",
113+
'desc': "PM | Total Process Monitors Running",
93114
'default': ""
94115
}
95116
}

entry.tp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": 6,
3-
"version": 100,
3+
"version": 110,
44
"name": "Process Checker",
55
"id": "tp.plugin.process_checker",
66
"configuration": {
@@ -48,19 +48,32 @@
4848
]
4949
}
5050
]
51+
},
52+
{
53+
"id": "tp.plugin.process_checker.act.stop_process.Monitor",
54+
"name": "Stop Process Monitor for [X]",
55+
"prefix": "Process Checker",
56+
"type": "communicate",
57+
"format": "Stop {$tp.plugin.process_checker.act.process_name.stop$} Process Monitor",
58+
"tryInline": true,
59+
"data": [
60+
{
61+
"id": "tp.plugin.process_checker.act.process_name.stop",
62+
"type": "choice",
63+
"label": "Text",
64+
"default": "ALL",
65+
"valueChoices": [
66+
"ALL"
67+
]
68+
}
69+
]
5170
}
5271
],
5372
"states": [
5473
{
55-
"id": "tp.plugin.process_checker.state.current_text_name_style",
56-
"type": "text",
57-
"desc": "Color Picker: Text Name Style",
58-
"default": ""
59-
},
60-
{
61-
"id": "tp.plugin.process_checker.state.last_mouse_x",
74+
"id": "tp.plugin.process_checker.state.process_monitor.count",
6275
"type": "text",
63-
"desc": "Color Picker: Last Mouse Location - X",
76+
"desc": "PM | Total Process Monitors Running",
6477
"default": ""
6578
}
6679
],

process_checker.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ def the_task(self, data, the_process):
6363

6464

6565
if process_checked:
66+
process_monitor_dict[data] = the_process
67+
the_list = list(process_monitor_dict.keys())
68+
the_list.append("ALL")
69+
TPClient.choiceUpdate(choiceId=PLUGIN_ID + ".act.process_name.stop", values=the_list)
70+
## update a state showing how many values are in the list minus the "ALL" value
71+
TPClient.stateUpdate(stateId=PLUGIN_ID + ".state.process_monitor.count", stateValue=str(len(the_list) - 1))
6672

6773
print(f"{the_process.process_name} is running")
6874

@@ -108,6 +114,7 @@ def check_continuously(self, interval, data, the_process):
108114

109115
def stop(self):
110116
self.should_continue = False
117+
111118

112119

113120

@@ -164,6 +171,8 @@ def onConnect(data):
164171
if settings := data.get('settings'):
165172
handleSettings(settings, True)
166173

174+
TPClient.stateUpdate(stateId=PLUGIN_ID + ".state.process_monitor.count", stateValue="0")
175+
167176

168177

169178

@@ -208,7 +217,7 @@ def onSettingUpdate(data):
208217
# ## use a thread to create sttes as fast as possible
209218
# TPClient.createState(stateId=PLUGIN_ID + f".state.{the_process.process_name}.process_info.{x}", description=f"PM | {the_process.process_name} - {x}", value=str(process_checked.get(x, "None")), parentGroup=str(the_process.process_name))
210219

211-
220+
process_monitor_dict = {}
212221

213222
@TPClient.on(TP.TYPES.onAction)
214223
def onAction(data):
@@ -228,36 +237,36 @@ def onAction(data):
228237
#the_process.time_completion(data=data['data'][0]['value'], the_process=the_process)
229238
the_process.the_task(data=data, the_process=the_process)
230239
else:
231-
print(f"We are gonna check every {str(data['data'][1]['value'])} seconds")
240+
print(f"Checking every {str(data['data'][1]['value'])} seconds for {data['data'][0]['value']}")
232241
the_process = ProcessChecker(data['data'][0]['value'])
233242
process_checked = the_process.check_continuously(int(data['data'][1]['value']), data=data['data'][0]['value'], the_process=the_process)
234-
# print(process_checked)
235-
236-
237-
# the_process = ProcessChecker(data['data'][0]['value'])
238-
# process_checked = the_process.get_process_info()
239-
# if process_checked:
240-
# g_log.info(f"{the_process.process_name} is running")
241-
#
242-
# g_log.debug(f"Process Info: {process_checked}")
243-
#
244-
# print(process_checked)
245-
# for x in process_checked:
246-
# if x == 'memory_percent':
247-
# ## Round it to the 2nd decimal place
248-
# process_checked[x] = round(process_checked[x], 2)
249-
#
250-
# if x == 'create_time':
251-
# from datetime import datetime
252-
# create_time = process_checked.get('create_time', "None")
253-
# if create_time is not None:
254-
# create_time_datetime = datetime.fromtimestamp(create_time)
255-
# process_checked[x] = create_time_datetime.strftime("%m/%d/%Y [%I:%M:%S %p]")
256-
#
257-
# TPClient.createState(stateId=PLUGIN_ID + f".state.{the_process.process_name}.process_info.{x}", description=f"PM | {the_process.process_name} - {x}", value=str(process_checked.get(x, "None")), parentGroup=str(the_process.process_name))
258-
259243

260244

245+
if data['actionId'] == PLUGIN_ID +".act.stop_process.Monitor":
246+
global process_monitor_dict
247+
the_process = data['data'][0]['value']
248+
try:
249+
if the_process =="ALL":
250+
# print("Trying to remove all processes from the dict")
251+
for x in process_monitor_dict:
252+
253+
# print("Stopping the process: ", x)
254+
if x != "ALL":
255+
process_monitor_dict[x].stop()
256+
g_log.debug(stopped_process := f"Stopping the process: {x}")
257+
258+
process_monitor_dict = {}
259+
else:
260+
process_monitor_dict[the_process].stop()
261+
## delete the key from the dict
262+
# print("Trying to remove the process {} from the dict".format(the_process))
263+
process_monitor_dict.pop(the_process)
264+
265+
TPClient.stateUpdate(stateId=PLUGIN_ID + ".state.process_monitor.count", stateValue=str(len(process_monitor_dict.keys())))
266+
# del process_monitor_dict[the_process]
267+
except Exception as e:
268+
print(e)
269+
261270

262271

263272
# Shutdown handler

0 commit comments

Comments
 (0)