-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmdframebox.py
More file actions
271 lines (208 loc) · 11.7 KB
/
cmdframebox.py
File metadata and controls
271 lines (208 loc) · 11.7 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
from tkinter import *
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showinfo
from tkinter import scrolledtext
from settings import *
#Add Menu
def showcmdframe(self, choice, *args, **kwargs):
# this shows the correct frame in the cmd window based on the combo selection.
print("this is showcmdframe")
print(f"combobox selected is :{choice}")
# self.lblUpdate.config(text=f"Using: {connectselect} ")
'''
self.listOfCMDs = ['show version',
'show running-config',
'show ip interface brief',
'show ip route'
'show interface gigabitEthernet 0/0',
'show interface gigabitEthernet 0/1',
'show interface gigabitEthernet 0/2',
'show interface gigabitEthernet 0/3',
'show interface gigabitEthernet 0/4',
'show interface gigabitEthernet 1/0',
'show interface gigabitEthernet 1/1',
'show arp',
'show flash:'
'show vlan'
]
'''
'''
def populatebox():
for i in listOfCMDs:
self.listBox.insert("end", i)
'''
if choice == "Paramiko":
#self.statustext.set("Method: Paramiko")
#if self.btncopy["state"] == "active" or "normal": self.btncopy["state"] = "disabled"
#if self.btnpaste["state"] == "active" or "normal": self.btnpaste["state"] = "disabled"
# self.btnpaste.config(state='disabled')
self.btncopy.configure(state='disabled')
self.btnpaste.configure(state='disabled')
for widgets in self.cmdframea.winfo_children():
widgets.destroy()
self.cmdframecontainer = Frame(self.cmdframea, background="light sky blue")
self.cmdframecontainer.pack(fill='both', expand=TRUE, anchor='n', side=TOP)
#self.btnsipb=ttk.Button(self.cmdframea, text="Run the selected command", command=self.runcmdselection)
#self.btnsipb.pack(side='left', anchor='s')
self.listbox = Listbox(self.cmdframecontainer,
activestyle='none',
font=("Helvetica", 11, "bold"),
highlightthickness=0,
selectforeground='black',
background='light goldenrod yellow',
selectbackground="palegreen",
exportselection=False) # exportselection=False on combobox and listbox to clear conflict
self.listbox.pack(side = LEFT, fill = 'both', expand=True, anchor='nw', padx=(15, 5), pady=(10, 5))
self.scrollbar = Scrollbar(self.cmdframecontainer)
self.scrollbar.pack(side = RIGHT, fill = BOTH)
'''
self.listbox.insert(0, 'show version')
self.listbox.insert(1, 'show running-config')
'''
# listOfCMDs located in the settigs file
for i in listOfCMDs:
self.listbox.insert("end", i)
self.listbox.select_set(1)
self.cmdvarselected.set("show running-config")
self.statusvarcmd2.set(value=self.cmdvarselected.get())
self.listbox.config(yscrollcommand = self.scrollbar.set)
self.scrollbar.config(command = self.listbox.yview)
def localindex_selected(event):
selected_indices = self.listbox.curselection()
selected_index = selected_indices[0]
selected_value = self.listbox.get(selected_index)
self.cmdvarselected.set(selected_value)
print(f"localindex_selected: {selected_value}")
print(f"localindex_selected cmdvarselected value: {self.cmdvarselected.get()}")
self.statusvarcmd2.set(value=self.cmdvarselected.get()) # Update status label
self.listbox.bind('<<ListboxSelect>>', localindex_selected)
elif choice == "Netmiko":
#self.statustext.set("Method: Netmiko")
self.btncopy.configure(state='disabled')
self.btnpaste.configure(state='disabled')
for widgets in self.cmdframea.winfo_children():
widgets.destroy()
self.cmdframecontainer = Frame(self.cmdframea, background="light sky blue")
self.cmdframecontainer.pack(fill='both', expand=TRUE, anchor='n', side=TOP)
#self.btnsipb=ttk.Button(self.cmdframea, text="Run the selected command", command=self.runcmdselection)
#self.btnsipb.pack(side='left', anchor='s')
self.listbox = Listbox(self.cmdframecontainer,
activestyle='none',
font=("Helvetica", 11, "bold"),
highlightthickness=0,
selectforeground='black',
background='light goldenrod yellow',
selectbackground="palegreen",
exportselection=False) # exportselection=False on combobox and listbox to clear conflict
self.listbox.pack(side = LEFT, fill = 'both', expand=True, anchor='nw', padx=(15, 5), pady=(10, 5))
self.scrollbar = Scrollbar(self.cmdframecontainer)
self.scrollbar.pack(side = RIGHT, fill = BOTH)
'''
self.listbox.insert(0, 'show version')
self.listbox.insert(1, 'show running-config')
'''
# listOfCMDs located in the settigs file
for i in listOfCMDs:
self.listbox.insert("end", i)
self.listbox.select_set(1)
self.cmdvarselected.set("show running-config")
self.statusvarcmd2.set(value=self.cmdvarselected.get())
self.listbox.config(yscrollcommand = self.scrollbar.set)
self.scrollbar.config(command = self.listbox.yview)
def localindex_selected(event):
selected_indices = self.listbox.curselection()
selected_index = selected_indices[0]
selected_value = self.listbox.get(selected_index)
self.cmdvarselected.set(selected_value)
print(f"localindex_selected: {selected_value}")
print(f"localindex_selected cmdvarselected value: {self.cmdvarselected.get()}")
self.statusvarcmd2.set(value=self.cmdvarselected.get()) # Update status label
self.listbox.bind('<<ListboxSelect>>', localindex_selected)
#return self.cmdcmdvarselected.get()
elif choice == "Netmiko_ch":
#self.statustext.set("Method: Netmiko_ch")
self.btncopy.configure(state='disabled')
self.btnpaste.configure(state='disabled')
for widgets in self.cmdframea.winfo_children():
widgets.destroy()
self.cmdframecontainer = Frame(self.cmdframea, background="light sky blue")
self.cmdframecontainer.pack(fill='both', expand=TRUE, anchor='n', side=TOP)
#self.btnsipb=ttk.Button(self.cmdframea, text="Run the selected command", command=self.runcmdselection)
#self.btnsipb.pack(side='left', anchor='s')
self.listbox = Listbox(self.cmdframecontainer,
activestyle='none',
font=("Helvetica", 11, "bold"),
highlightthickness=0,
selectforeground='black',
background='light goldenrod yellow',
selectbackground="palegreen",
exportselection=False) # exportselection=False on combobox and listbox to clear conflict
self.listbox.pack(side = LEFT, fill = 'both', expand=True, anchor='nw', padx=(15, 5), pady=(10, 5))
self.scrollbar = Scrollbar(self.cmdframecontainer)
self.scrollbar.pack(side = RIGHT, fill = BOTH)
'''
self.listbox.insert(0, 'show version')
self.listbox.insert(1, 'show running-config')
'''
# listOfCMDs located in the settigs file
for i in listOfCMDs:
self.listbox.insert("end", i)
self.listbox.select_set(1)
self.cmdvarselected.set("show running-config")
self.statusvarcmd2.set(value=self.cmdvarselected.get())
self.listbox.config(yscrollcommand = self.scrollbar.set)
self.scrollbar.config(command = self.listbox.yview)
def localindex_selected(event):
selected_indices = self.listbox.curselection()
selected_index = selected_indices[0]
selected_value = self.listbox.get(selected_index)
self.cmdvarselected.set(selected_value)
print(f"localindex_selected: {selected_value}")
print(f"localindex_selected cmdvarselected value: {self.cmdvarselected.get()}")
self.statusvarcmd2.set(value=self.cmdvarselected.get()) # Update status label
self.listbox.bind('<<ListboxSelect>>', localindex_selected)
elif choice == "Netmiko_ch_config":
#self.statustext.set("Method: Netmiko_ch_config")
self.btncopy.configure(state='normal')
self.btnpaste.configure(state='normal')
for widgets in self.cmdframea.winfo_children():
widgets.destroy()
self.cmdframecontainer = Frame(self.cmdframea, background="light sky blue")
self.cmdframecontainer.pack(fill='both', expand=TRUE, anchor='n', side=TOP)
self.cmdtxtbox = scrolledtext.ScrolledText(self.cmdframecontainer,
wrap=WORD,
background='light goldenrod yellow',
font=("Helvetica", 11, "bold"),
height=5) #, height=23, width=83
self.cmdtxtbox.pack(side = LEFT, fill = 'both', expand=True, anchor='nw', padx=(15, 5), pady=(10, 5))
# POP UP MENU
def copy_select(): # copy selected text to clipboard
global cmddata
if self.cmdtxtbox.selection_get():
cmddata=self.cmdtxtbox.selection_get() # copy selected text to clipboard
self.clipboard_clear()
self.clipboard_append(cmddata)
def paste_select():
global data
self.cmdtxtbox.insert(tk.END,self.clipboard_get()) # Paste data from clipboard
self.statusvarcmd2.set(value="Netmiko config multiline") # Update status label
#Add Menu
popup = Menu(self.cmdtxtbox, tearoff=0)
#Adding Menu Items
popup.add_command(label="Copy", command=lambda:copy_select())
popup.add_command(label="Paste", command=lambda:paste_select())
def menu_popup(event):
# display the popup menu
try:
popup.tk_popup(event.x_root, event.y_root, 0)
finally:
#Release the grab
popup.grab_release()
self.bind("<Button-3>", menu_popup)
else:
#self.statustext.set("Method: Undefined")
self.btncopy.configure(state='disabled')
self.btnpaste.configure(state='disabled')
for widgets in self.cmdframea.winfo_children():
widgets.destroy()