def validatePage(self): project_name = self.et_project_name.text().trimmed() #project_dir = self.et_project_location.text().trimmed() wizard_template = self.cb_wizard_type.currentText() component_type = self.cb_component_type.currentIndex() platform_type = 0 if self.cb_pt_win.isChecked(): platform_type |= configuration.PT_WIN32 if self.cb_pt_linux.isChecked(): platform_type |= configuration.PT_LINUX if self.cb_pt_version.currentIndex() == 1: app.g_configurations.platform_version = "x86_64" else: app.g_configurations.platform_version = "x86_32" app.g_configurations.project_name = app.QString2str(project_name) #app.g_configurations.project_location = app.QString2str(project_dir) app.g_configurations.template_source = app.QString2str(wizard_template) app.g_configurations.platform_type = platform_type if component_type == 0: app.g_configurations.component_type = "server" elif component_type == 1: app.g_configurations.component_type = "window" template_name = app.g_configurations.template_source template_dir = app.g_pwd + os.sep + 'templates' + os.sep + template_name with open(template_dir + os.sep + 'config.json', 'r') as f: app.g_configurations.config_content = f.read() return True
def on_gen(self): '''生成工程''' if not self.currentConfig: return #获取工程名及有效路径 project_name = self.et_project_name.text() project_location = self.et_project_location.text() qdir = QDir(project_location) if not qdir.exists(): if not qdir.mkpath(project_location): QMessageBox.warning(self, '警告', '路径无效!') return project_location = qdir.absolutePath() if not project_location.endsWith( '/') and not project_location.endsWith('\\'): project_location += os.sep project_location.replace('\\', '/') if project_name.isEmpty() or project_location.isEmpty(): QMessageBox.warning(self, '警告', '项目名称或路径不能为空!') return self.currentConfig.project_name = app.QString2str(project_name) self.currentConfig.project_location = app.QString2str(project_location) content = self.currentConfig.toJson() fileInfo = QFileInfo(self.path) if not self.path.isEmpty(): path = app.QString2str(self.path) with open(path, 'w+') as f: f.write(content) item = self.lw.currentItem() item.setData(QtCore.Qt.UserRole, content) template_name = self.currentConfig.template_source template_dir = app.g_pwd + os.sep + 'templates' + os.sep + template_name.encode( 'utf-8') with open(template_dir + os.sep + 'config.json', 'r') as f: self.currentConfig.config_content = f.read() ret_json = app.render(self.currentConfig.config_content, config=self.currentConfig) self.currentConfig.config = json.loads(ret_json) for file in self.currentConfig.config['files']: sourcepath = template_dir + os.sep + file['source'].encode('utf-8') targetdir = self.currentConfig.project_location + self.currentConfig.project_name targetpath = targetdir + os.sep + file['target'] fi = QFileInfo(targetpath) qdir = fi.absoluteDir() if not qdir.exists(): qdir.mkpath(fi.absolutePath()) with open(sourcepath, 'r') as f: content = f.read() content = app.render(content, config=self.currentConfig) #渲染文件 with open(targetpath, 'w+') as f: f.write(content.encode('utf-8')) QMessageBox.information(self, '提示', '生成成功!')
def on_select(self): '''选取配置''' item = self.lw.currentItem() if item != None: content = item.data(QtCore.Qt.UserRole).toString() config = Configuration() config.fromJson(app.QString2str(content)) self.currentConfig = config self.showConfigInfo(self.currentConfig) self.bGroup.setEnabled(True) self.path = item.data(QtCore.Qt.UserRole + 1).toString()
def validatePage(self): interfaces = {} for i in range(self.lw_interface.count()): litem = self.lw_interface.item(i) key = app.QString2str(litem.text()) if litem.checkState() == 2: interfaces[key] = True else: interfaces[key] = False app.g_configurations.interfaces = interfaces return True
def on_modify(self): '''修改配置''' if self.currentConfig: app.g_configurations = copy.copy(self.currentConfig) dlg = wizard.MyWizard() if dlg.exec_(): item = self.lw.currentItem() if item != None: content = app.g_configurations.toJson() item.setData(QtCore.Qt.UserRole, content) path = item.data(QtCore.Qt.UserRole + 1).toString() if not path.isEmpty(): path = app.QString2str(path) with open(path, 'w+') as f: f.write(content) self.on_select()
def on_open(self): '''打开现有配置''' fileName = QFileDialog.getOpenFileName( self, "选择现有模板", app.g_pwd + os.sep + "configurations", "Config (*.json)") if fileName.isEmpty(): return self.path = fileName with open(app.QString2str(fileName), 'r') as f: content = f.read() fileInfo = QFileInfo(fileName) if not fileInfo.exists(): return config = Configuration() config.fromJson(content) config.allone_dir = os.getenv('ALLONEDIR', '../..').replace('\\', '/') self.addConfig(fileInfo.baseName(), fileInfo.filePath(), content) self.on_select()
def on_new(self): '''新建向导''' app.g_configurations = Configuration() # 用来渲染的配置数据 dlg = wizard.MyWizard() if dlg.exec_(): app.g_configurations.initialized = True app.g_projects.append(app.g_configurations) content = app.g_configurations.toJson() self.path = QFileDialog.getSaveFileName( self, "选择模板保存的路径", app.g_pwd + os.sep + "configurations" + os.sep + app.g_configurations.project_name.encode('utf-8') + ".json", "Config (*.json)") fileInfo = QFileInfo(self.path) if not self.path.isEmpty(): path = app.QString2str(self.path) with open(path, 'w+') as f: f.write(content) self.addConfig(fileInfo.baseName(), fileInfo.filePath(), content)