From 99c5d258994f5077241132d8ef2391b11128b744 Mon Sep 17 00:00:00 2001 From: Ronny Abraham Date: Sun, 23 Jun 2019 18:23:08 +0300 Subject: [PATCH] update deploy_meta to work with PyQt5 --- bin/deploy_meta.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/bin/deploy_meta.py b/bin/deploy_meta.py index c4d2c3c..03d02f3 100644 --- a/bin/deploy_meta.py +++ b/bin/deploy_meta.py @@ -1,7 +1,10 @@ import sys import yaml import os -from PyQt4 import QtGui, QtCore +from PyQt5.QtWidgets import QMainWindow, QLineEdit, QLabel, QAction +from PyQt5.QtWidgets import QFileDialog, QGridLayout, QWidget, QApplication +from PyQt5.QtWidgets import QMessageBox +from PyQt5.QtCore import QVariant class DictQuery(dict): @@ -74,7 +77,7 @@ def nested_set(dic, keys, value): dic[keys[-1]] = value -class DeployMeta(QtGui.QMainWindow): +class DeployMeta(QMainWindow): PATH_META = "../../../meta/project" PATH_TEMPLATES = "../share/templates/meta" @@ -273,7 +276,7 @@ class DeployMeta(QtGui.QMainWindow): path_config_full = os.path.join( self.path_templates, self.CONFIG_TYPES[configname]) - configuration_file = yaml.load(file(path_config_full, 'r')) + configuration_file = yaml.load(open(path_config_full, 'r')) return configuration_file def store_config(self): @@ -322,8 +325,8 @@ class DeployMeta(QtGui.QMainWindow): title = self.widgets[key]['title'] - label = QtGui.QLabel(title) - field = QtGui.QLineEdit() + label = QLabel(title) + field = QLineEdit() grid.addWidget(label, row, 0) grid.addWidget(field, row, 1) @@ -337,19 +340,23 @@ class DeployMeta(QtGui.QMainWindow): desc = "Load Configuration %s" % title - loadAction = QtGui.QAction(menuname, self) + loadAction = QAction(menuname, self) loadAction.setShortcut(shortcut) loadAction.setStatusTip(desc) loadAction.triggered.connect(self.action_loadconfig) - variant = QtCore.QVariant(key) + variant = QVariant(key) loadAction.setData(variant) return loadAction def action_loadconfig(self): sender = self.sender() - self.currentbranch = sender.data().toString().__str__() + + if type(sender.data()) is str: + self.currentbranch = sender.data() + else: + self.currentbranch = sender.data().toString().__str__() self.config_data = self.load_config(self.currentbranch) @@ -392,23 +399,22 @@ class DeployMeta(QtGui.QMainWindow): # # get the path value from the dialog box - path_newconfig = QtGui.QFileDialog.getSaveFileName( + path_newconfig = QFileDialog.getSaveFileName( self, dialog_title, path_default_save, - selectedFilter='*.yml') + filter='*.yml') # # if the user hit 'cancel' path_newconfig will be empty if path_newconfig: - stream = file(path_newconfig, 'w') + stream = open(path_newconfig[0], 'w') yaml.dump(self.config_data, stream) else: # # display message warning no configuration has been loaded - from PyQt4.QtGui import QMessageBox msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setText('Save Error') @@ -423,12 +429,12 @@ class DeployMeta(QtGui.QMainWindow): menubar = self.menuBar() menubar.setNativeMenuBar(False) - exitAction = QtGui.QAction('&Exit', self) + exitAction = QAction('&Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip("Exit application") - exitAction.triggered.connect(QtGui.qApp.quit) + exitAction.triggered.connect(self.close) - saveAction = QtGui.QAction('&Gore', self) + saveAction = QAction('&Gore', self) saveAction.setShortcut('Ctrl+T') saveAction.setStatusTip("Save Config File") saveAction.triggered.connect(self.action_save_config) @@ -446,7 +452,7 @@ class DeployMeta(QtGui.QMainWindow): self.setupMenu() - grid = QtGui.QGridLayout() + grid = QGridLayout() grid.setSpacing(10) self.add_widgetrow('PROJECT_NAME', grid) @@ -466,7 +472,7 @@ class DeployMeta(QtGui.QMainWindow): self.add_widgetrow('DJANGO_PORT', grid) self.add_widgetrow('NGINX_PORT', grid) - central = QtGui.QWidget() + central = QWidget() central.setLayout(grid) self.setCentralWidget(central) @@ -477,7 +483,7 @@ class DeployMeta(QtGui.QMainWindow): def main(): - app = QtGui.QApplication(sys.argv) + app = QApplication(sys.argv) app.setStyle("cleanlooks") ex = DeployMeta() sys.exit(app.exec_())