Esempio n. 1
0
    def __init__(self):
        super().__init__()
        self.setMenuBar(QMenuBar())

        self.deploy_files_action = QAction(QIcon('resources/deploy.png'), "Deploy selected", self)
        self.backup_files_action = QAction(QIcon('resources/backup.png'), "Backup selected", self)
        self.settings_action = QAction(QIcon('resources/settings.png'), "Settings", self)
        self.exit_action = QAction(QIcon('resources/exit.png'), "Exit", self)

        self.deploy_files_action.connect(self.deploy_files_action, SIGNAL("triggered()"), self.deploy_files)
        self.backup_files_action.connect(self.backup_files_action, SIGNAL("triggered()"), self.backup_files)
        self.settings_action.connect(self.settings_action, SIGNAL("triggered()"), self.show_settings)
        self.exit_action.connect(self.exit_action, SIGNAL("triggered()"), self.exit)

        self.file_menu = self.menuBar().addMenu("File")
        self.file_menu.addAction(self.settings_action)
        self.file_menu.addAction(self.exit_action)

        self.actions_menu = self.menuBar().addMenu("Actions")
        self.actions_menu.addAction(self.backup_files_action)
        self.actions_menu.addAction(self.deploy_files_action)

        """

        ##################################################

        """

        # outer frame. this is the central widget for the application
        self.outer_frame = Frame(QVBoxLayout(), QFrame.StyledPanel)
        # inner top frame. holds list widget and tab widget
        self.inner_top_frame = Frame(QHBoxLayout(), QFrame.StyledPanel)
        # inner btm frame.
        self.inner_btm_frame = Frame(QVBoxLayout(), QFrame.StyledPanel)

        # text area
        self.display_area = TextDisplay()

        # status bar. shows hover actions and status
        self.status_bar = QStatusBar()
        self.setStatusBar(self.status_bar)
        self.status_bar.showMessage("Status Bar Message...")

        # tab widget. holds description and powershell tabs. they both have text boxes inside to display text
        self.tab_container = TabContainer()
        tabs = (Tab("Description", TextDisplay(), QVBoxLayout()),
                Tab("Powershell", TextDisplay(), QVBoxLayout()))
        self.tab_container.set_tabs(tabs)

        # list widget. holds selectable items
        self.list_widget = ListWidget()
        self.list_items = [ListItem("PXSurveyAPI"),
                           ListItem("PXWeb"),
                           ListItem("PXReporting"),
                           ListItem("PXNotification"),
                           ListItem("SampleUI"),
                           ListItem("SampleEngine"),
                           ListItem("PXClientMGMT"),
                           ListItem("InsightsOnline"),
                           ListItem("TEST"),
                           ListItem("PXSurveyMGMT"),
                           ListItem("PXVerintSurveyACL")]
        self.list_widget.add_sort_list_items(self.list_items)
        self.list_widget.connect(self.list_widget, SIGNAL("itemClicked(QListWidgetItem*)"), self.selected)

        # pull everything together.
        self.inner_top_frame.get_layout().addWidget(self.list_widget)
        self.inner_btm_frame.get_layout().addWidget(self.tab_container)

        self.outer_frame.get_layout().addWidget(self.inner_top_frame)
        self.outer_frame.get_layout().addWidget(self.inner_btm_frame)

        self.inner_top_frame.get_layout().addWidget(self.display_area)

        self.setWindowIcon(QIcon('resources\conan.png'))
        self.setCentralWidget(self.outer_frame)
        self.show()

        """
Esempio n. 2
0
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setMenuBar(QMenuBar())

        self.deploy_files_action = QAction(QIcon('resources/deploy.png'), "Deploy selected", self)
        self.backup_files_action = QAction(QIcon('resources/backup.png'), "Backup selected", self)
        self.settings_action = QAction(QIcon('resources/settings.png'), "Settings", self)
        self.exit_action = QAction(QIcon('resources/exit.png'), "Exit", self)

        self.deploy_files_action.connect(self.deploy_files_action, SIGNAL("triggered()"), self.deploy_files)
        self.backup_files_action.connect(self.backup_files_action, SIGNAL("triggered()"), self.backup_files)
        self.settings_action.connect(self.settings_action, SIGNAL("triggered()"), self.show_settings)
        self.exit_action.connect(self.exit_action, SIGNAL("triggered()"), self.exit)

        self.file_menu = self.menuBar().addMenu("File")
        self.file_menu.addAction(self.settings_action)
        self.file_menu.addAction(self.exit_action)

        self.actions_menu = self.menuBar().addMenu("Actions")
        self.actions_menu.addAction(self.backup_files_action)
        self.actions_menu.addAction(self.deploy_files_action)

        """

        ##################################################

        """

        # outer frame. this is the central widget for the application
        self.outer_frame = Frame(QVBoxLayout(), QFrame.StyledPanel)
        # inner top frame. holds list widget and tab widget
        self.inner_top_frame = Frame(QHBoxLayout(), QFrame.StyledPanel)
        # inner btm frame.
        self.inner_btm_frame = Frame(QVBoxLayout(), QFrame.StyledPanel)

        # text area
        self.display_area = TextDisplay()

        # status bar. shows hover actions and status
        self.status_bar = QStatusBar()
        self.setStatusBar(self.status_bar)
        self.status_bar.showMessage("Status Bar Message...")

        # tab widget. holds description and powershell tabs. they both have text boxes inside to display text
        self.tab_container = TabContainer()
        tabs = (Tab("Description", TextDisplay(), QVBoxLayout()),
                Tab("Powershell", TextDisplay(), QVBoxLayout()))
        self.tab_container.set_tabs(tabs)

        # list widget. holds selectable items
        self.list_widget = ListWidget()
        self.list_items = [ListItem("PXSurveyAPI"),
                           ListItem("PXWeb"),
                           ListItem("PXReporting"),
                           ListItem("PXNotification"),
                           ListItem("SampleUI"),
                           ListItem("SampleEngine"),
                           ListItem("PXClientMGMT"),
                           ListItem("InsightsOnline"),
                           ListItem("TEST"),
                           ListItem("PXSurveyMGMT"),
                           ListItem("PXVerintSurveyACL")]
        self.list_widget.add_sort_list_items(self.list_items)
        self.list_widget.connect(self.list_widget, SIGNAL("itemClicked(QListWidgetItem*)"), self.selected)

        # pull everything together.
        self.inner_top_frame.get_layout().addWidget(self.list_widget)
        self.inner_btm_frame.get_layout().addWidget(self.tab_container)

        self.outer_frame.get_layout().addWidget(self.inner_top_frame)
        self.outer_frame.get_layout().addWidget(self.inner_btm_frame)

        self.inner_top_frame.get_layout().addWidget(self.display_area)

        self.setWindowIcon(QIcon('resources\conan.png'))
        self.setCentralWidget(self.outer_frame)
        self.show()

        """

        Call powershell function and pass parameters:

script_path = "c:\\users\\cherbison\\desktop\\test-function.ps1"

posh_path = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"

posh2 = subprocess.call([posh_path, ". \"" + script_path + "\";", "&test-function(\" test \")"])

script call

def call_script(self, type_, btn_pushed):

    posh = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
    script = self.script_path + type_ + "_" + btn_pushed + ".ps1"

    try:
        subprocess.Popen([posh, "Start-Process", '-Verb', "runAs", posh, [script]])
    except subprocess.CalledProcessError as e:
        print(e.output, "There was an error.")

@staticmethod
def read_file(file_path):
    file = open(file_path)
    return file.read()

"""

    def deploy_files(self):
        self.display_area.append("deploy files clicked")

    def backup_files(self):
        self.display_area.append("backup files clicked")

    def show_settings(self):
        self.display_area.append("settings clicked")

    def selected(self):
        selected_item = self.list_widget.currentItem().text
        self.display_area.append(selected_item + " selected")
        self.display_area.ensureCursorVisible()

    def exit(self):
        self.display_area.append("exit clicked")