def new_proj(self): """New file.""" filename, _ = QFileDialog.getSaveFileName( self, "New Project", self.env, SUPPORT_FILE_FORMATS ) if not filename: return self.env = QFileInfo(filename).absolutePath() root_node = QTreeRoot( QFileInfo(filename).baseName(), filename, str(self.data.new_num()) ) suffix_text = file_suffix(filename) if suffix_text == 'md': root_node.setIcon(0, file_icon("markdown")) elif suffix_text == 'html': root_node.setIcon(0, file_icon("html")) elif suffix_text == 'kmol': root_node.setIcon(0, file_icon("kmol")) else: root_node.setIcon(0, file_icon("txt")) self.tree_main.addTopLevelItem(root_node)
def open_proj(self): """Open file.""" file_names, ok = QFileDialog.getOpenFileNames( self, "Open Projects", self.env, SUPPORT_FILE_FORMATS ) if not ok: return def in_widget(path: str) -> int: """Is name in tree widget.""" for i in range(self.tree_main.topLevelItemCount()): if path == self.tree_main.topLevelItem(i).text(1): return i return -1 for file_name in file_names: self.env = QFileInfo(file_name).absolutePath() index = in_widget(file_name) if index == -1: root_node = QTreeRoot(QFileInfo(file_name).baseName(), file_name, '') self.tree_main.addTopLevelItem(root_node) parse(root_node, self.data) self.tree_main.setCurrentItem(root_node) else: self.tree_main.setCurrentItem(self.tree_main.topLevelItem(index)) self.__add_macros()
def dropEvent(self, event): """Drop file in to our window.""" for url in event.mimeData().urls(): filename = url.toLocalFile() root_node = QTreeRoot(QFileInfo(filename).baseName(), filename, '') self.tree_main.addTopLevelItem(root_node) parse(root_node, self.data) self.tree_main.setCurrentItem(root_node) self.__add_macros() event.acceptProposedAction()
def dropEvent(self, event): """Drop file in to our window.""" for url in event.mimeData().urls(): file_name = url.toLocalFile() self.env = QFileInfo(file_name).absolutePath() index = self.__in_widget(file_name) if index == -1: root_node = QTreeRoot( QFileInfo(file_name).baseName(), file_name, '') self.tree_main.addTopLevelItem(root_node) parse(root_node, self.data) self.tree_main.setCurrentItem(root_node) else: self.tree_main.setCurrentIndex(index) self.__add_macros() event.acceptProposedAction()
def __open_proj(self, file_names: Optional[Sequence[str]] = None): """Open file.""" if file_names is None: file_names, ok = QFileDialog.getOpenFileNames( self, "Open Projects", self.env, SUPPORT_FILE_FORMATS) if not ok: return for file_name in file_names: self.env = QFileInfo(file_name).absolutePath() index = self.__in_widget(file_name) if index == -1: root_node = QTreeRoot( QFileInfo(file_name).baseName(), file_name, '') self.tree_main.addTopLevelItem(root_node) self.refresh_proj(root_node) self.tree_main.setCurrentItem(root_node) else: self.tree_main.setCurrentItem( self.tree_main.topLevelItem(index))
def __init__(self): super(MainWindow, self).__init__(None) self.setupUi(self) # Start new window. @pyqtSlot() def new_main_window(): XStream.back() run = self.__class__() run.show() self.action_New_Window.triggered.connect(new_main_window) # Text editor self.text_editor = TextEditor(self) self.h_splitter.addWidget(self.text_editor) self.text_editor.word_changed.connect(self.__set_not_saved_title) self.edge_line_option.toggled.connect(self.text_editor.setEdgeMode) self.trailing_blanks_option.toggled.connect(self.text_editor.set_remove_trailing_blanks) # Highlighters self.highlighter_option.addItems(sorted(QSCIHIGHLIGHTERS)) self.highlighter_option.setCurrentText("Markdown") self.highlighter_option.currentTextChanged.connect( self.text_editor.set_highlighter ) # Tree widget context menu. self.tree_widget.customContextMenuRequested.connect( self.on_tree_widget_context_menu ) self.popMenu_tree = QMenu(self) self.popMenu_tree.setSeparatorsCollapsible(True) self.popMenu_tree.addAction(self.action_new_project) self.popMenu_tree.addAction(self.action_open) self.tree_add = QAction("&Add Node", self) self.tree_add.triggered.connect(self.add_node) self.tree_add.setShortcut("Ctrl+I") self.tree_add.setShortcutContext(Qt.WindowShortcut) self.popMenu_tree.addAction(self.tree_add) self.popMenu_tree.addSeparator() self.tree_path = QAction("Set Path", self) self.tree_path.triggered.connect(self.set_path) self.popMenu_tree.addAction(self.tree_path) self.tree_refresh = QAction("&Refresh from Path", self) self.tree_refresh.triggered.connect(self.refresh_proj) self.popMenu_tree.addAction(self.tree_refresh) self.tree_openurl = QAction("&Open from Path", self) self.tree_openurl.triggered.connect(self.open_path) self.popMenu_tree.addAction(self.tree_openurl) self.action_save.triggered.connect(self.save_proj) self.popMenu_tree.addAction(self.action_save) self.tree_copy = QAction("Co&py", self) self.tree_copy.triggered.connect(self.copy_node) self.popMenu_tree.addAction(self.tree_copy) self.tree_clone = QAction("C&lone", self) self.tree_clone.triggered.connect(self.clone_node) self.popMenu_tree.addAction(self.tree_clone) self.tree_copy_tree = QAction("Recursive Copy", self) self.tree_copy_tree.triggered.connect(self.copy_node_recursive) self.popMenu_tree.addAction(self.tree_copy_tree) self.tree_clone_tree = QAction("Recursive Clone", self) self.tree_clone_tree.triggered.connect(self.clone_node_recursive) self.popMenu_tree.addAction(self.tree_clone_tree) self.popMenu_tree.addSeparator() self.tree_delete = QAction("&Delete", self) self.tree_delete.triggered.connect(self.delete_node) self.popMenu_tree.addAction(self.tree_delete) self.tree_close = QAction("&Close", self) self.tree_close.triggered.connect(self.close_file) self.popMenu_tree.addAction(self.tree_close) self.tree_main.header().setSectionResizeMode(QHeaderView.ResizeToContents) # Console self.console.setFont(self.text_editor.font) if not ARGUMENTS.debug_mode: XStream.stdout().messageWritten.connect(self.__append_to_console) XStream.stderr().messageWritten.connect(self.__append_to_console) for info in INFO: print(info) print('-' * 7) # Searching function. find_next = QShortcut(QKeySequence("F3"), self) find_next.activated.connect(self.find_next_button.click) find_previous = QShortcut(QKeySequence("F4"), self) find_previous.activated.connect(self.find_previous_button.click) find_tab = QShortcut(QKeySequence("Ctrl+F"), self) find_tab.activated.connect(lambda: self.panel_widget.setCurrentIndex(1)) find_project = QShortcut(QKeySequence("Ctrl+Shift+F"), self) find_project.activated.connect(self.find_project_button.click) # Replacing function. replace = QShortcut(QKeySequence("Ctrl+R"), self) replace.activated.connect(self.replace_node_button.click) replace_project = QShortcut(QKeySequence("Ctrl+Shift+R"), self) replace_project.activated.connect(self.replace_project_button.click) # Translator. self.panel_widget.addTab(TranslatorWidget(self), "Translator") # Node edit function. (Ctrl + ArrowKey) move_up_node = QShortcut(QKeySequence("Ctrl+Up"), self) move_up_node.activated.connect(self.__move_up_node) move_down_node = QShortcut(QKeySequence("Ctrl+Down"), self) move_down_node.activated.connect(self.__move_down_node) move_right_node = QShortcut(QKeySequence("Ctrl+Right"), self) move_right_node.activated.connect(self.__move_right_node) move_left_node = QShortcut(QKeySequence("Ctrl+Left"), self) move_left_node.activated.connect(self.__move_left_node) # Run script button. run_sript = QShortcut(QKeySequence("F5"), self) run_sript.activated.connect(self.exec_button.click) self.macros_toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) # Splitter self.h_splitter.setStretchFactor(0, 10) self.h_splitter.setStretchFactor(1, 60) self.v_splitter.setStretchFactor(0, 30) self.v_splitter.setStretchFactor(1, 10) # Data self.data = DataDict() self.data.not_saved.connect(self.__set_not_saved_title) self.data.all_saved.connect(self.__set_saved_title) self.env = QStandardPaths.writableLocation(QStandardPaths.DesktopLocation) for filename in ARGUMENTS.r: filename = QFileInfo(filename).canonicalFilePath() if not filename: return root_node = QTreeRoot(QFileInfo(filename).baseName(), filename, '') self.tree_main.addTopLevelItem(root_node) parse(root_node, self.data) self.__add_macros()
def __new_proj(self): """New file.""" file_name, suffix_type = QFileDialog.getSaveFileName( self, "New Project", self.env, SUPPORT_FILE_FORMATS) if not file_name: return suffix = _str_between(suffix_type, '(', ')').split('*')[-1] if QFileInfo(file_name).completeSuffix() != suffix[1:]: file_name += suffix self.env = QFileInfo(file_name).absolutePath() root_node = QTreeRoot( QFileInfo(file_name).baseName(), file_name, str(self.data.new_num())) suffix_text = file_suffix(file_name) if suffix_text == 'md': root_node.setIcon(0, file_icon("markdown")) elif suffix_text == 'py': root_node.setIcon(0, file_icon("python")) elif suffix_text == 'html': root_node.setIcon(0, file_icon("html")) elif suffix_text == 'kmol': root_node.setIcon(0, file_icon("kmol")) else: root_node.setIcon(0, file_icon("txt")) self.tree_main.addTopLevelItem(root_node)