1+ import logging
2+ from log_setter import set_logging
3+ ## STEP6a - import the tool function from the file you imported into the CTOOLS3 project folder
4+ from populate import run_populate
5+ from ui_help import gen_tool_layout , gen_custom_tool_layout , create_tool_bar
6+ from login import global_admin_login
7+ from PySide6 .QtCore import Qt
8+ from PySide6 .QtWidgets import (
9+ QMainWindow ,
10+ QWidget ,
11+ QPushButton ,
12+ QVBoxLayout ,
13+ QLabel ,
14+ QHBoxLayout ,
15+ QTextEdit ,
16+ QFrame ,
17+ )
18+ from PySide6 .QtGui import (
19+ QPixmap
20+ )
21+ WINDOW_WIDTH = 600
22+ WINDOW_HEIGHT = 500
23+ OUTPUT_HEIGHT = 250
24+ class populateCloudFoldersWindow (QMainWindow ):
25+ """PyCalc's main window (GUI or view)."""
26+ def __init__ (self , widget ):
27+ super ().__init__ ()
28+ self .widget = widget
29+ self .setWindowTitle ("CTools 3.0" )
30+ self .setFixedSize (WINDOW_WIDTH , WINDOW_HEIGHT )
31+ self .generalLayout = QVBoxLayout ()
32+ self .top = QHBoxLayout ()
33+ welcome = QLabel ("<h2>Welcome to CTools!</h2><h5>One tool for all</h5>" )
34+ pic_label = QLabel (self )
35+ pixmap = QPixmap ("logo.png" )
36+ pic_label .setPixmap (pixmap )
37+ #pic_label.setScaledContents(True)
38+ self .top .addWidget (welcome )
39+ self .top .addStretch ()
40+ self .top .addWidget (pic_label )
41+ self .mainContent = QHBoxLayout ()
42+ centralWidget = QWidget (self )
43+ centralWidget .setLayout (self .generalLayout )
44+ self .setCentralWidget (centralWidget )
45+ self .generalLayout .addLayout (self .top )
46+ self .generalLayout .addLayout (self .mainContent )
47+ self ._createToolBar ()
48+ self ._createToolViewLayout ()
49+ def _createToolBar (self ):
50+ tools = create_tool_bar (self .widget , 13 )
51+ # Add line separator between Tool List and Tool View
52+ line = QFrame ()
53+ line .setFrameShape (QFrame .VLine )
54+ line .setFrameShadow (QFrame .Sunken )
55+ line .setLineWidth (1 )
56+ self .mainContent .addLayout (tools )
57+ self .mainContent .addWidget (line )
58+ def _createToolViewLayout (self ):
59+ toolView = QVBoxLayout ()
60+ # Step3 - You will change the next two lines according to the KB
61+ BoilerLayout , self .input_widgets = gen_custom_tool_layout ("Populate Cloud Folders" , ["Device Name" ], ["Ignore cert warnings for login" , "Verbose Logging" ])
62+ toolView .addLayout (BoilerLayout )
63+ # Create action buttons
64+ actionButtonLayout = QHBoxLayout ()
65+ self .cancel = QPushButton ("Cancel" )
66+ self .start = QPushButton ("Start" )
67+ actionButtonLayout .addWidget (self .cancel )
68+ actionButtonLayout .addWidget (self .start )
69+ toolView .addLayout (actionButtonLayout )
70+ # STEP5 - Add button listeners
71+ self .start .clicked .connect (self .tool )
72+ # Create Output box
73+ self .output = QTextEdit ()
74+ self .output .setReadOnly (True )
75+ toolView .addWidget (self .output )
76+ self .mainContent .addLayout (toolView )
77+ # STEP4 - Grab the arguments for you tool
78+ def tool (self ):
79+ portal_address = self .input_widgets [0 ].text ()
80+ portal_username = self .input_widgets [1 ].text ()
81+ portal_password = self .input_widgets [2 ].text ()
82+ device_name = self .input_widgets [3 ].text ()
83+ ignore_cert = self .input_widgets [4 ].isChecked ()
84+ verbose = self .input_widgets [5 ].isChecked ()
85+ if verbose :
86+ set_logging (logging .DEBUG , 'debug-log.txt' )
87+ else :
88+ set_logging ()
89+ ## Step6b - Run the tool here
90+ # Ex: run_status(global_admin, filename, all_tenants_flag)
91+ run_populate (portal_address , portal_username , portal_password , device_name )
92+ self ._updateOutput ()
93+ def _updateOutput (self ):
94+ file = open ("output.tmp" , 'r' )
95+ with file :
96+ text = file .read ()
97+ self .output .setText (text )
98+ self .output .verticalScrollBar ().setValue (self .output .verticalScrollBar ().maximum ())
0 commit comments