def on_button_clicked(self): msgBox = QtWidgets.QMessageBox() buttonReply = msgBox.question( self, 'JaSONx', "Select json files in this folder?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if buttonReply == QtWidgets.QMessageBox.Yes: response = utility.createFileList(self.path, ".json") dialog = ActThingMainInterface.ActThingMainInterface( response, self.obj) dialog.show() self.close()
def __init__(self, obj, parent=None): super(ActThingMainInterface, self).__init__(parent) self.obj = obj '''Window settings''' self.setWindowTitle("actTHING") self.setFixedSize(1050, 600) self.setWindowIcon( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "acthing.png"))) '''Font settings''' font = QtGui.QFont() font.setPointSize(13) fontToolbar = QtGui.QFont() fontToolbar.setPointSize(10) self.setFont(font) '''Button settings''' self.button = QtWidgets.QPushButton("Activate Things") self.button.setStyleSheet( "background-color: orange; color: white; height:50; border-radius:10" ) self.button.setFont(font) if (type(obj) != list): '''Create list file .json''' self.list_file_json = utility.createFileList( os.path.join(self.obj.json_files_path, self.obj.name_hierarchy), ".json") else: self.list_file_json = obj '''Layout settings''' grid = QtWidgets.QGridLayout() self.table = QtWidgets.QTableWidget() self.table.setFont(font) self.table.setRowCount(len(self.list_file_json)) self.table.setColumnCount(1) self.table.setHorizontalHeaderLabels(["File JSON"]) self.table.setColumnWidth(0, 1000) '''Grid Layout''' grid.addWidget(self.table, 0, 0) grid.addWidget(self.button, 1, 0) '''Layout QWidget''' layout = QtWidgets.QWidget() layout.setLayout(grid) '''Layout QMainWindow''' self.setCentralWidget(layout) '''Table settings''' count = 0 for file in self.list_file_json: self.table.setItem(count, 0, QtWidgets.QTableWidgetItem(file)) count += 1 '''Button clicked''' self.button.clicked.connect(self.on_pushButton_clicked)
def add_file_hierarchy(path): file_path = os.path.basename(path) if (os.path.isfile(path) and utility.getSubstring(file_path, start=".") == "xml"): shutil.copy(path, hierarchy_path) return True elif (os.path.isdir(path)): list_files = utility.createFileList(path, ".xml") for file in list_files: shutil.copy(os.path.join(path, file), hierarchy_path) return True else: return False
def getTemplateData(self, hierarchy_name): list_json_file = utility.createFileList( os.path.join(self.json_files_path, hierarchy_name), ".json") dict_measures = {} for file in list_json_file: file_json = utility.readJsonFile( os.path.join(self.json_files_path, hierarchy_name, file)) for measure in file_json["parameters"]["filter_tag"]: if (measure["tag"] != "CommunicationCode"): dict_measures[measure["tag"]] = [ measure["id"], measure["period"] ] return (dict_measures)
def addJsonTemplate(path): file_path = os.path.basename(path) if (os.path.isfile(path) and utility.getSubstring(file_path, start=".") == "json"): path_name, file_name = os.path.splitext(file_path) shutil.copy(path, os.path.join(json_templates_path)) utility.refreshTemplateConfiguration() return True elif (os.path.isdir(path)): list_files = utility.createFileList(path, ".json") for file in list_files: shutil.copy(os.path.join(path, file), os.path.join(json_templates_path)) utility.add_measures_template(list_files) return True else: return False
def __init__(self, parent=None): super(MainInterface, self).__init__(parent) '''Configuration path''' dict_configuration_path = utility.getConfigurationPath() self.json_templates_path = dict_configuration_path[ "json_templates_path"] self.excel_templates_path = dict_configuration_path[ "excel_templates_path"] self.json_files_path = dict_configuration_path["json_files_path"] self.excel_files_path = dict_configuration_path["excel_files_path"] self.hierarchy_path = dict_configuration_path["hierarchy_path"] '''Window settings''' self.setWindowTitle("JaSONx") self.setFixedSize(1050, 600) self.setWindowIcon( QtGui.QIcon(os.path.join(os.path.realpath(''), "image", "logo.png"))) '''Font settings''' font = QtGui.QFont() font.setPointSize(13) fontToolbar = QtGui.QFont() fontToolbar.setPointSize(10) self.setFont(font) '''Label settings''' self.title_label = QtWidgets.QLabel() self.user_name_label = QtWidgets.QLabel() self.password_label = QtWidgets.QLabel() self.match_group_value_label = QtWidgets.QLabel() self.combo_box_hierarchy_label = QtWidgets.QLabel() self.gateway_id_label = QtWidgets.QLabel() self.combo_box_environment_prefix_label = QtWidgets.QLabel() self.title_label.setAlignment(QtCore.Qt.AlignCenter) '''Label text''' self.title_label.setPixmap( QtGui.QPixmap( os.path.join(os.path.realpath(''), "image", "title.png"))) self.user_name_label.setText("Username: "******"Password: "******"Hierarchy: ") self.gateway_id_label.setText("Gateway id: ") self.combo_box_environment_prefix_label.setText("Environment prefix: ") '''Textbox settings''' self.user_name_text = QtWidgets.QLineEdit(self) self.password_text = QtWidgets.QLineEdit(self) '''Combobox settings''' self.combo_box_hierarchy = QtWidgets.QComboBox() self.combo_box_hierarchy.addItems( utility.createFileList(self.hierarchy_path, ".xml")) self.combo_box_environment_prefix = QtWidgets.QComboBox() self.combo_box_environment_prefix.addItems( utility.readJsonFile( os.path.join(os.path.realpath(''), "configuration", "environmentPrefixConfiguration.json"))) self.combo_box_gateway_id = QtWidgets.QComboBox() self.combo_box_gateway_id.addItems( utility.readJsonFile( os.path.join(os.path.realpath(''), "configuration", "gatewayIdConfiguration.json"))) '''Button settings''' self.button = QtWidgets.QPushButton("Send data") self.button.setStyleSheet( "background-color: #8b0000; color: white; height:50; border-radius:10" ) self.button.setFont(font) self.button.clicked.connect(self.on_pushButton_clicked) '''Grid layout''' grid = QtWidgets.QGridLayout() grid.addWidget(self.user_name_label, 0, 0) grid.addWidget(self.user_name_text, 0, 1) grid.addWidget(self.password_label, 1, 0) grid.addWidget(self.password_text, 1, 1) grid.addWidget(self.gateway_id_label, 2, 0) grid.addWidget(self.combo_box_gateway_id, 2, 1) grid.addWidget(self.combo_box_environment_prefix_label, 3, 0) grid.addWidget(self.combo_box_environment_prefix, 3, 1) grid.addWidget(self.combo_box_hierarchy_label, 4, 0) grid.addWidget(self.combo_box_hierarchy, 4, 1) '''Vertical layout''' vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.title_label) vbox.addLayout(grid) vbox.addWidget(self.button) '''Layout QWidget''' layout = QtWidgets.QWidget() layout.setLayout(vbox) '''Layout QMainWindow''' self.setCentralWidget(layout) '''TOOLBAR''' toolbar = self.addToolBar('Toolbar') toolbar.setMovable(False) toolbar.setIconSize(QtCore.QSize(40, 40)) toolbar.setFont(fontToolbar) toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) '''Icon toolbar''' '''Exit application''' exit_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "exiticon.png")), '', self) exit_act.setShortcut('Ctrl+Q') exit_act.setStatusTip('Close application') '''Add Hierarchy xml''' add_xml_hierarchy_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "xmlicon.png")), 'Hierarchy', self) add_xml_hierarchy_act.setShortcut('Ctrl+H') add_xml_hierarchy_act.setStatusTip('Add Hierarchy XML') '''Add template json''' add_json_template_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "jsonicon.png")), 'Template', self) add_json_template_act.setShortcut('Ctrl+T') add_json_template_act.setStatusTip('Add JSON Template') '''Refresh application''' refresh_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "refreshicon.png")), '', self) refresh_act.setShortcut('Ctrl+R') refresh_act.setStatusTip('Refresh application') '''Add evironment prefix''' add_environment_prefix_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "addlisticon.png")), 'Environment prefix', self) add_environment_prefix_act.setShortcut('Ctrl+P') add_environment_prefix_act.setStatusTip('Add environment prefix') '''Add gateway id''' add_gateway_id_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "addlisticon.png")), 'Gateway id', self) add_gateway_id_act.setShortcut('Ctrl+Y') add_gateway_id_act.setStatusTip('Add gateway id') '''acThing''' acThing_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "acthing.png")), 'acThing', self) acThing_act.setShortcut('Ctrl+I') acThing_act.setStatusTip('Open acThing Interface') '''Excel Append''' excel_append_act = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "icon", "excelicon.png")), 'Append', self) excel_append_act.setShortcut('Ctrl+Z') excel_append_act.setStatusTip('Open Excel Append Interface') '''ACTION TOOLBAR''' toolbar.addAction(exit_act) toolbar.addSeparator() toolbar.addSeparator() toolbar.addSeparator() toolbar.addAction(add_xml_hierarchy_act) toolbar.addAction(add_json_template_act) toolbar.addAction(add_environment_prefix_act) toolbar.addAction(add_gateway_id_act) toolbar.addSeparator() toolbar.addSeparator() toolbar.addSeparator() toolbar.addAction(acThing_act) toolbar.addAction(excel_append_act) toolbar.addSeparator() toolbar.addSeparator() toolbar.addSeparator() toolbar.addAction(refresh_act) '''TOOOLBAR TRIGGERED''' exit_act.triggered.connect(self.closeFunction) add_xml_hierarchy_act.triggered.connect(self.addHierarchy) add_json_template_act.triggered.connect(self.addJsonTemplate) refresh_act.triggered.connect(self.refreshWindow) add_environment_prefix_act.triggered.connect(self.addEnvironmentPrefix) add_gateway_id_act.triggered.connect(self.addGatewayId) acThing_act.triggered.connect(self.openActThingInterface) excel_append_act.triggered.connect(self.openExcelAppendInterface) '''MENU SETTINGS''' '''Configuration Json path''' configJsonPathAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "json.png")), 'Json output', self) configJsonPathAct.setShortcut('Ctrl+J') configJsonPathAct.setStatusTip('') configJsonPathAct.triggered.connect(self.changePathJsonFile) '''Configuration Hierarchy path''' configHierarchyPathAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "xml.png")), 'Hierarchy', self) configHierarchyPathAct.setShortcut('Ctrl+X') configHierarchyPathAct.setStatusTip('') configHierarchyPathAct.triggered.connect(self.changePathHierarchy) '''Configuration Template path''' configTemplatePathAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "json.png")), 'Template', self) configTemplatePathAct.setShortcut('Ctrl+L') configTemplatePathAct.setStatusTip('') configTemplatePathAct.triggered.connect(self.changePathTemplate) '''Configuration Excel path''' configExcelPathAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "excel.png")), 'Excel output', self) configExcelPathAct.setShortcut('Ctrl+E') configExcelPathAct.setStatusTip('') configExcelPathAct.triggered.connect(self.changePathExcel) '''Configuration Excel Final path''' configExcelFinalPathAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "excel.png")), 'Excel Final output', self) configExcelFinalPathAct.setShortcut('Ctrl+S') configExcelFinalPathAct.setStatusTip('') configExcelFinalPathAct.triggered.connect(self.changePathExcelFinal) '''Reset paths default''' resetPathAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "reset.png")), 'Reset Path to Default', self) resetPathAct.setShortcut('Ctrl+D') resetPathAct.setStatusTip('') resetPathAct.triggered.connect(self.resetDefaultPath) '''User Guide''' UserGuideAct = QtWidgets.QAction( QtGui.QIcon( os.path.join(os.path.realpath(''), "image", "menu", "guide.png")), 'Open User Guide', self) UserGuideAct.setShortcut('Ctrl+G') UserGuideAct.setStatusTip('') UserGuideAct.triggered.connect(self.openUserGuide) '''Add bar menu''' menubar = self.menuBar() '''Menu path population''' fileMenu = menubar.addMenu('&Change Path') fileMenu.addAction(configJsonPathAct) fileMenu.addAction(configHierarchyPathAct) fileMenu.addAction(configTemplatePathAct) fileMenu.addAction(configExcelPathAct) fileMenu.addAction(configExcelFinalPathAct) fileMenu.addAction(resetPathAct) '''Menu Info - User Guide''' fileMenu2 = menubar.addMenu('&Info') fileMenu2.addAction(UserGuideAct)