update deploy_meta to work with PyQt5

This commit is contained in:
Ronny Abraham 2019-06-23 18:23:08 +03:00
parent 0c50929581
commit 99c5d25899

View file

@ -1,7 +1,10 @@
import sys import sys
import yaml import yaml
import os 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): class DictQuery(dict):
@ -74,7 +77,7 @@ def nested_set(dic, keys, value):
dic[keys[-1]] = value dic[keys[-1]] = value
class DeployMeta(QtGui.QMainWindow): class DeployMeta(QMainWindow):
PATH_META = "../../../meta/project" PATH_META = "../../../meta/project"
PATH_TEMPLATES = "../share/templates/meta" PATH_TEMPLATES = "../share/templates/meta"
@ -273,7 +276,7 @@ class DeployMeta(QtGui.QMainWindow):
path_config_full = os.path.join( path_config_full = os.path.join(
self.path_templates, self.CONFIG_TYPES[configname]) 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 return configuration_file
def store_config(self): def store_config(self):
@ -322,8 +325,8 @@ class DeployMeta(QtGui.QMainWindow):
title = self.widgets[key]['title'] title = self.widgets[key]['title']
label = QtGui.QLabel(title) label = QLabel(title)
field = QtGui.QLineEdit() field = QLineEdit()
grid.addWidget(label, row, 0) grid.addWidget(label, row, 0)
grid.addWidget(field, row, 1) grid.addWidget(field, row, 1)
@ -337,19 +340,23 @@ class DeployMeta(QtGui.QMainWindow):
desc = "Load Configuration %s" % title desc = "Load Configuration %s" % title
loadAction = QtGui.QAction(menuname, self) loadAction = QAction(menuname, self)
loadAction.setShortcut(shortcut) loadAction.setShortcut(shortcut)
loadAction.setStatusTip(desc) loadAction.setStatusTip(desc)
loadAction.triggered.connect(self.action_loadconfig) loadAction.triggered.connect(self.action_loadconfig)
variant = QtCore.QVariant(key) variant = QVariant(key)
loadAction.setData(variant) loadAction.setData(variant)
return loadAction return loadAction
def action_loadconfig(self): def action_loadconfig(self):
sender = self.sender() 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) self.config_data = self.load_config(self.currentbranch)
@ -392,23 +399,22 @@ class DeployMeta(QtGui.QMainWindow):
# #
# get the path value from the dialog box # get the path value from the dialog box
path_newconfig = QtGui.QFileDialog.getSaveFileName( path_newconfig = QFileDialog.getSaveFileName(
self, dialog_title, self, dialog_title,
path_default_save, path_default_save,
selectedFilter='*.yml') filter='*.yml')
# #
# if the user hit 'cancel' path_newconfig will be empty # if the user hit 'cancel' path_newconfig will be empty
if path_newconfig: if path_newconfig:
stream = file(path_newconfig, 'w') stream = open(path_newconfig[0], 'w')
yaml.dump(self.config_data, stream) yaml.dump(self.config_data, stream)
else: else:
# #
# display message warning no configuration has been loaded # display message warning no configuration has been loaded
from PyQt4.QtGui import QMessageBox
msg = QMessageBox() msg = QMessageBox()
msg.setIcon(QMessageBox.Warning) msg.setIcon(QMessageBox.Warning)
msg.setText('Save Error') msg.setText('Save Error')
@ -423,12 +429,12 @@ class DeployMeta(QtGui.QMainWindow):
menubar = self.menuBar() menubar = self.menuBar()
menubar.setNativeMenuBar(False) menubar.setNativeMenuBar(False)
exitAction = QtGui.QAction('&Exit', self) exitAction = QAction('&Exit', self)
exitAction.setShortcut('Ctrl+Q') exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip("Exit application") 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.setShortcut('Ctrl+T')
saveAction.setStatusTip("Save Config File") saveAction.setStatusTip("Save Config File")
saveAction.triggered.connect(self.action_save_config) saveAction.triggered.connect(self.action_save_config)
@ -446,7 +452,7 @@ class DeployMeta(QtGui.QMainWindow):
self.setupMenu() self.setupMenu()
grid = QtGui.QGridLayout() grid = QGridLayout()
grid.setSpacing(10) grid.setSpacing(10)
self.add_widgetrow('PROJECT_NAME', grid) self.add_widgetrow('PROJECT_NAME', grid)
@ -466,7 +472,7 @@ class DeployMeta(QtGui.QMainWindow):
self.add_widgetrow('DJANGO_PORT', grid) self.add_widgetrow('DJANGO_PORT', grid)
self.add_widgetrow('NGINX_PORT', grid) self.add_widgetrow('NGINX_PORT', grid)
central = QtGui.QWidget() central = QWidget()
central.setLayout(grid) central.setLayout(grid)
self.setCentralWidget(central) self.setCentralWidget(central)
@ -477,7 +483,7 @@ class DeployMeta(QtGui.QMainWindow):
def main(): def main():
app = QtGui.QApplication(sys.argv) app = QApplication(sys.argv)
app.setStyle("cleanlooks") app.setStyle("cleanlooks")
ex = DeployMeta() ex = DeployMeta()
sys.exit(app.exec_()) sys.exit(app.exec_())