1
1
import tkinter as tk
2
2
from tkinter import messagebox
3
3
import subprocess # Import the subprocess module
4
+ import mss
4
5
5
6
# Assuming Flags_Library.py contains your flags data, compulsory_flags, and conflicts
6
7
try :
9
10
print ("Flags_Library.py not found. Please ensure it exists and contains the necessary data." )
10
11
exit (1 )
11
12
13
+ with mss .mss () as sct :
14
+ monitors = sct .monitors
15
+ for idx , monitor in enumerate (monitors ):
16
+ test = f"Monitor { idx } : Left={ monitor ['left' ]} , Top={ monitor ['top' ]} , Width={ monitor ['width' ]} , Height={ monitor ['height' ]} "
17
+
12
18
# Initialize the main window
13
19
root = tk .Tk ()
14
- root .title ("Dynamic Command Builder" )
15
- root .geometry ("400x300" )
20
+ root .title ("⚠️ BETA ⚠️ Dynamic Command Builder " )
21
+ result_width = int (monitor ['width' ] - (monitor ['width' ]/ 7 ))
22
+ result_height = int (monitor ['height' ] - (monitor ['height' ]/ 7 ))
23
+ root .geometry (f"{ result_width } x{ result_height } " )
16
24
disabled_buttons = set ()
17
25
18
26
# Variable to hold the command preview
40
48
41
49
42
50
def reset_and_enable_buttons_except_execute ():
51
+ """
52
+ Reset the command preview to the default state, validate the command to check for errors,
53
+ and enable all buttons except the Execute button.
54
+ """
43
55
# Reset the command preview to the default state
44
56
command_preview .set ("./Logicytics.py" )
45
57
@@ -54,6 +66,15 @@ def reset_and_enable_buttons_except_execute():
54
66
55
67
# Function to handle hover events and update the tooltip
56
68
def show_tooltip (event ):
69
+ """
70
+ Shows a tooltip when the mouse hovers over a button.
71
+
72
+ Parameters:
73
+ event (tkinter.Event): The event object that triggered the tooltip display.
74
+
75
+ Returns:
76
+ None
77
+ """
57
78
button_text = event .widget .cget ("text" )
58
79
for flag_tuple in flags :
59
80
if flag_tuple [0 ] == button_text :
@@ -76,19 +97,58 @@ def show_tooltip(event):
76
97
77
98
# Function to handle mouse leave events to hide the tooltip
78
99
def hide_tooltip ():
100
+ """
101
+ Hides the tooltip by clearing the tooltip text and removing the tooltip label from the window.
102
+
103
+ This function is called when the mouse leaves an element with a tooltip.
104
+ It clears the tooltip text by setting it to an empty string using the `config` method of the `tooltip_label` widget.
105
+ It then removes the tooltip label from the window by calling the `pack_forget` method.
106
+ Finally, it ensures that the tooltip label remains on top of other elements by calling the `lift` method.
107
+
108
+ Returns:
109
+ None
110
+ """
79
111
tooltip_label .config (text = "" )
80
112
tooltip_label .pack_forget ()
81
113
tooltip_label .lift () # Optionally keep it on top even when hidden
82
114
83
115
84
116
def enable_all_buttons ():
117
+ """
118
+ Enables all the buttons by setting their state to 'normal' and then clears the disabled buttons list.
119
+ """
85
120
for btn in disabled_buttons :
86
121
btn ['state' ] = 'normal'
87
122
disabled_buttons .clear ()
88
123
89
124
90
125
# Function to validate the command and update the error label
91
126
def validate_command ():
127
+ """
128
+ Validates the current command stored in `command_preview` against a set of rules defined by `compulsory_flags`
129
+ and `conflicts`.
130
+ These rules include checking for the presence of compulsory flags and ensuring there are no conflicting
131
+ flag combinations.
132
+ If the command fails validation, an appropriate error message is displayed, and the 'Execute' button
133
+ is disabled to prevent execution of invalid commands.
134
+ If the command passes validation, the error message is cleared,
135
+ and the 'Execute' button is enabled, indicating that the command is ready to be executed.
136
+
137
+ This function operates on global variables:
138
+ - `command_preview`: Contains the current command to be validated.
139
+ - `compulsory_flags`: A list of flags that must be present in the command for it to be considered valid.
140
+ - `conflicts`: A dictionary mapping sets of conflicting flags to error messages.
141
+ A command is considered invalid
142
+ if it contains both flags in any set of conflicts.
143
+ - `error_label`: A Tkinter Label widget used to display error messages.
144
+ - `execute_btn`: A Tkinter Button widget controlling the execution of the command.
145
+ Its state is toggled based on the
146
+ validation result.
147
+
148
+ Effects:
149
+ - Modifies the text of `error_label` to reflect the validation status or error message.
150
+ - Toggles the state of `execute_btn` between 'disabled' and 'normal' based on whether the command is valid.
151
+ """
92
152
full_command = command_preview .get ()
93
153
compulsory_flag_count = 0 # Initialize the counter for compulsory flags
94
154
@@ -145,6 +205,28 @@ def find_button_by_name(name):
145
205
146
206
# Modify the append_to_command_preview function to call validate_command immediately after updating the command preview
147
207
def append_to_command_preview (button_name ):
208
+ """
209
+ Appends a button's name to the current command preview and disables the corresponding button.
210
+
211
+ This function updates the global command preview by appending the specified button's name to it,
212
+ effectively simulating the action of pressing the button within the context of the command line interface.
213
+ It then locates and disables the button associated with the appended name to prevent duplicate actions.
214
+ Finally, it calls the `validate_command()` function to automatically check the validity of the updated command.
215
+
216
+ Parameters:
217
+ - button_name (str): The name of the button to be appended to the command preview and disabled.
218
+
219
+ Effects:
220
+ - Modifies the global `command_preview`
221
+ string by appending the new button name and joining the command parts with spaces.
222
+ - Updates the state of the button identified by `button_name` to 'disabled',
223
+ adding it to the `disabled_buttons` set to track disabled states.
224
+ - Calls the `validate_command()` function to ensure the command remains valid after the update.
225
+
226
+ Note:
227
+ This function assumes the existence of global variables `command_preview`,
228
+ `find_button_by_name()`, `disabled_buttons`, and `validate_command()`.
229
+ """
148
230
current_command = command_preview .get ().split ()
149
231
current_command .append (button_name )
150
232
command_preview .set (' ' .join (current_command ))
@@ -173,6 +255,15 @@ def append_to_command_preview(button_name):
173
255
174
256
# Function to execute the command in cmd
175
257
def execute_command (command_string ):
258
+ """
259
+ A function that executes a command using powershell.exe based on the given command_string.
260
+
261
+ Parameters:
262
+ command_string (str): The command to be executed.
263
+
264
+ Returns:
265
+ None
266
+ """
176
267
try :
177
268
command = f'powershell.exe -Command "& { command_string } "'
178
269
subprocess .Popen (command , shell = True )
0 commit comments