def removeTreeWords(files, cache): for f in files: fh = file(f) for line in fh: t = InputTree(line) for word in t.getYield(): cache.discard(word)
def __init__(self, **kwds): super(InputFileEditor, self).__init__(**kwds) self.tree = InputTree(ExecutableInfo()) self.top_layout = WidgetUtils.addLayout(vertical=True) self.setLayout(self.top_layout) self.block_tree = BlockTree(self.tree) self.top_layout.addWidget(self.block_tree) self.block_tree.blockClicked.connect(self._blockClicked) self.block_tree.blockDoubleClicked.connect(self._blockEditorRequested) self.block_tree.changed.connect(lambda block: self.blockChanged.emit(block, self.tree)) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.block_editor = None self.setup()
def executableInfoChanged(self, app_info): """ The ExecutableInfo object has changed. Input: app_info[ExecutableInfo]: The new information """ if app_info.valid(): self._closeBlockEditor() old_tree = self.tree self.tree = InputTree(app_info) if old_tree.root: self.tree.setInputFileData(old_tree.getInputFileString(), old_tree.input_filename) else: self.tree.setInputFile(old_tree.input_filename) self.block_tree.setInputTree(self.tree)
def executableInfoChanged(self, app_info): """ The ExecutableInfo object has changed. Input: app_info[ExecutableInfo]: The new information """ if app_info.valid(): input_filename = self.tree.input_filename input_tree = InputTree(app_info) self.tree = input_tree self.tree.setInputFile(input_filename) self.block_tree.setInputTree(self.tree)
class InputFileEditor(QWidget, MooseWidget): """ Holds the widget to edit the input file. Contains the tree as well as the parameter editing portion. Signals: blockChanged[BlockInfo, InputTree]: Emitted when a block is changed inputFileChanged[str]: Emitted when the input file has changed blockSelected[BlockInfo, InputTree]: Emitted when a block is selected """ blockChanged = pyqtSignal(object, object) inputFileChanged = pyqtSignal(str) blockSelected = pyqtSignal(object, object) def __init__(self, **kwds): super(InputFileEditor, self).__init__(**kwds) self.tree = InputTree(ExecutableInfo()) self.top_layout = WidgetUtils.addLayout(vertical=True) self.setLayout(self.top_layout) self.block_tree = BlockTree(self.tree) self.top_layout.addWidget(self.block_tree) self.block_tree.blockClicked.connect(self._blockClicked) self.block_tree.blockDoubleClicked.connect(self._blockEditorRequested) self.block_tree.changed.connect(lambda block: self.blockChanged.emit(block, self.tree)) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.block_editor = None self.setup() def _blockEditorRequested(self, block): """ Called when a block editor is requested. Only one editor can be opened. Input: block[BlockInfo]: The block to edit. """ if self.block_editor: # raise it to front in case it is behind windows self.block_editor.raise_() return self.block_tree.blockSignals(True) self.block_editor = BlockEditor(block, self.tree.app_info.type_to_block_map, parent=self) self.block_editor.needBlockList.connect(self.onNeedBlockList) self.block_editor.blockChanged.connect(lambda block: self.blockChanged.emit(block, self.tree)) self.block_editor.blockRenamed.connect(self.block_tree.renameBlock) self.block_editor.cloneBlock.connect(self.block_tree.copyBlock) self.block_editor.removeBlock.connect(self.block_tree.removeBlock) self.block_editor.editingFinished.connect(self.onEditingFinished) self.block_editor.setWindowFlags(Qt.Window) self.block_editor.resize(640, 480) self.block_tree.blockSignals(False) self.block_editor.updateWatchers() self.block_editor.show() self.block_editor.raise_() def onEditingFinished(self): """ Editing the block is finished. """ self.block_editor.setParent(None) # Don't know if this is required self.block_editor = None def _blockClicked(self, block): """ Called when an item in the tree is clicked. Input: block[BlockInfo]: Block that was clicked """ self.blockSelected.emit(block, self.tree) if self.block_editor: # raise it to front in case it is behind windows self.block_editor.raise_() def onNeedBlockList(self, paths): """ Get a list of children for the requested paths then call setWatchedBlockList on the current editor Input: paths[list]: A list of paths to get the children for """ if not self.block_editor: return for p in paths: b = self.tree.getBlockInfo(p) if b: children = [] for c in b.children_list: info = b.children[c] if info.user_added: children.append(c) self.block_editor.setWatchedBlockList(p, children) def executableInfoChanged(self, app_info): """ The ExecutableInfo object has changed. Input: app_info[ExecutableInfo]: The new information """ if app_info.valid(): self._closeBlockEditor() old_tree = self.tree self.tree = InputTree(app_info) if old_tree.root: self.tree.setInputFileData(old_tree.getInputFileString(), old_tree.input_filename) else: self.tree.setInputFile(old_tree.input_filename) self.block_tree.setInputTree(self.tree) def setInputFile(self, input_file): """ The input file has changed. Input: input_file[str]: The new input file """ self._closeBlockEditor() if self.tree.app_info.valid(): input_file = os.path.abspath(input_file) if self.tree.setInputFile(input_file): self.block_tree.setInputTree(self.tree) self.inputFileChanged.emit(input_file) return True elif input_file: mooseutils.mooseError("Failed to read input file", dialog=True) else: self.tree.input_filename = input_file return False def _closeBlockEditor(self): """ Just closes the block editor if it is open """ if self.block_editor: self.block_editor.close() self.block_editor = None def closing(self): """ Called when the parent is about to close. """ self._closeBlockEditor() def writeInputFile(self, filename): """ Write the input tree to a file. Input: filename: Where to write the file. """ if not self.tree.app_info.valid() or not filename: return content = self.tree.getInputFileString() try: with open(filename, "w") as f: f.write(content) except IOError as e: mooseutils.mooseWarning("Failed to write input file %s: %s" % (filename, e))
Dump the tree to a string. Return: str: A display of the current QTreeWidget """ output = cStringIO.StringIO() for i in range(self.root_item.childCount()): child = self.root_item.child(i) self._dumpItem(output, child) return output.getvalue() if __name__ == "__main__": from PyQt5.QtWidgets import QApplication, QMainWindow from InputTree import InputTree from ExecutableInfo import ExecutableInfo import sys if len(sys.argv) != 3: print("Usage: %s <exe> <input file>" % sys.argv[0]) sys.exit(1) qapp = QApplication(sys.argv) main_win = QMainWindow() exe_info = ExecutableInfo() exe_info.setPath(sys.argv[1]) tree = InputTree(exe_info) tree.setInputFile(sys.argv[2]) w = BlockTree(tree) main_win.setCentralWidget(w) main_win.show() sys.exit(qapp.exec_())
if steps and steps.value: cur_steps += int(steps.value) return cur_steps + 2 + 1 # The +2 is for setup steps the +1 is so there is always a bit left... except Exception as e: mooseutils.mooseWarning("Problem calculating time steps: %s" % e) return 0 def findTimeSteps(tree): node = tree.getBlockInfo("/Executioner") if not node or not node.included: return 0 return estimateTimeSteps(node) if __name__ == "__main__": from peacock.utils import Testing from InputTree import InputTree from ExecutableInfo import ExecutableInfo exe = Testing.find_moose_test_exe() this_dir = os.path.dirname(os.path.abspath(__file__)) peacock_dir = os.path.dirname(this_dir) test_file = os.path.join(peacock_dir, "tests", "common", "transient.i") exe_info = ExecutableInfo() exe_info.path = exe tree = InputTree(exe_info) tree.inputFileChanged(test_file) num_steps = findTimeSteps(tree) print("Estimated number of steps: %s" % num_steps)
""" self.param_editor.updateWatchers() def closeEvent(self, event): """ The user is done editing. """ self.editingFinished.emit() if __name__ == "__main__": from PyQt5.QtWidgets import QApplication, QMainWindow from InputTree import InputTree from ExecutableInfo import ExecutableInfo import sys if len(sys.argv) != 4: print("Usage: %s <exe> <input file> <block path>" % sys.argv[0]) sys.exit(1) qapp = QApplication(sys.argv) main_win = QMainWindow() exe_info = ExecutableInfo() exe_info.clearCache() exe_info.setPath(sys.argv[1]) tree = InputTree(exe_info) tree.setInputFile(sys.argv[2]) b = tree.getBlockInfo(sys.argv[3]) w = BlockEditor(b, tree.app_info.type_to_block_map) main_win.setCentralWidget(w) main_win.show() main_win.resize(640, 480) sys.exit(qapp.exec_())
if adaptivity and adaptivity.included: steps = adaptivity.getParamInfo("steps") if steps and steps.value: cur_steps += int(steps.value) return cur_steps + 2 + 1 # The +2 is for setup steps the +1 is so there is always a bit left... except Exception as e: mooseutils.mooseWarning("Problem calculating time steps: %s" % e) return 0 def findTimeSteps(tree): node = tree.getBlockInfo("/Executioner") if not node or not node.included: return 0 return estimateTimeSteps(node) if __name__ == "__main__": from peacock.utils import Testing from InputTree import InputTree from ExecutableInfo import ExecutableInfo exe = Testing.find_moose_test_exe() this_dir = os.path.dirname(os.path.abspath(__file__)) peacock_dir = os.path.dirname(this_dir) test_file = os.path.join(peacock_dir, "tests", "common", "transient.i") exe_info = ExecutableInfo() exe_info.path = exe tree = InputTree(exe_info) tree.inputFileChanged(test_file) num_steps = findTimeSteps(tree) print("Estimated number of steps: %s" % num_steps)
""" Dump the tree to a string. Return: str: A display of the current QTreeWidget """ output = cStringIO.StringIO() for i in range(self.root_item.childCount()): child = self.root_item.child(i) self._dumpItem(output, child) return output.getvalue() if __name__ == "__main__": from PyQt5.QtWidgets import QApplication, QMainWindow from InputTree import InputTree from ExecutableInfo import ExecutableInfo import sys if len(sys.argv) != 3: print("Usage: %s <exe> <input file>" % sys.argv[0]) sys.exit(1) qapp = QApplication(sys.argv) main_win = QMainWindow() exe_info = ExecutableInfo() exe_info.setPath(sys.argv[1]) tree = InputTree(exe_info) tree.setInputFile(sys.argv[2]) w = BlockTree(tree) main_win.setCentralWidget(w) main_win.show() sys.exit(qapp.exec_())
self.param_editor.updateWatchers() def closeEvent(self, event): """ The user is done editing. """ self.editingFinished.emit() if __name__ == "__main__": from PyQt5.QtWidgets import QApplication, QMainWindow from InputTree import InputTree from ExecutableInfo import ExecutableInfo import sys if len(sys.argv) != 4: print("Usage: %s <exe> <input file> <block path>" % sys.argv[0]) sys.exit(1) qapp = QApplication(sys.argv) main_win = QMainWindow() exe_info = ExecutableInfo() exe_info.clearCache() exe_info.setPath(sys.argv[1]) tree = InputTree(exe_info) tree.setInputFile(sys.argv[2]) b = tree.getBlockInfo(sys.argv[3]) w = BlockEditor(b, tree.app_info.type_to_block_map) main_win.setCentralWidget(w) main_win.show() main_win.resize(640, 480) sys.exit(qapp.exec_())