def __init__(self, parent: QWidget): super().__init__(parent) self.tabs = QTabWidget(self) self.tabs.setTabsClosable(True) self.tabs.setMovable(True) # noinspection PyUnresolvedReferences self.tabs.tabCloseRequested.connect(self.tab_closing) layout = ThinVBoxLayout() layout.addWidget(self.tabs) self.setLayout(layout) signals().file_selected_signal.connect(self.file_double_clicked) signals().folder_opened_signal.connect(self.folder_opened) # Mapping from file paths to tabs. self.open_files: Dict[str, EditorTab] = dict() # Restore from settings user_settings().restore_widget(self, Key.editor) for open_file_path in user_settings().get_from_json( Key.editor_open_files, []): self.add_file(open_file_path) self.select_file(user_settings().get(Key.editor_current_file))
def __init__(self, parent: QWidget): super().__init__(parent) self.tree_view = ProjectTreeView(self) layout = ThinVBoxLayout() layout.addWidget(self.tree_view) self.setLayout(layout) user_settings().restore_widget(self, Key.project)
def __init__(self, parent: QWidget): super().__init__(parent) frame = QFrame(self) frame.setFrameShape(QFrame.StyledPanel) layout = ThinVBoxLayout() layout.addWidget(frame) self.setLayout(layout) user_settings().restore_widget(self, Key.tools)
def __init__(self, path: str, parent: QWidget): super().__init__(parent) self.path = path self.settings_key = Key.editor_tab.value + to_base64(path) self.editor = CodeEditor(self) self.highlighter = NASMHighlighter(self.editor.document()) self.editor.setPlainText(read_file_text(path)) layout = ThinVBoxLayout() layout.addWidget(self.editor) self.setLayout(layout) user_settings().restore_widget(self, self.settings_key)
def __init__(self, parent: QWidget): super().__init__(parent) self.setWindowFlags(Qt.Tool | Qt.Dialog) self.setWindowModality(Qt.WindowModal) self.setWindowTitle("Settings") self.resize(size_from_percentage_of_screen(0.7, 0.7)) centre_on_screen(self) self.close_shortcut = QShortcut(QKeySequence("Esc"), self) # noinspection PyUnresolvedReferences self.close_shortcut.activated.connect(self.cancel_clicked) self.ok_button = QPushButton(self) self.ok_button.setText("OK") self.ok_button.clicked.connect(self.ok_clicked) self.cancel_button = QPushButton(self) self.cancel_button.setText("Cancel") self.cancel_button.clicked.connect(self.cancel_clicked) self.apply_button = QPushButton(self) self.apply_button.setText("Apply") self.apply_button.clicked.connect(self.apply_clicked) horizontal_layout = QHBoxLayout() horizontal_layout.addStretch(1) horizontal_layout.addWidget(self.ok_button) horizontal_layout.addWidget(self.cancel_button) horizontal_layout.addWidget(self.apply_button) self.vertical_splitter = QSplitter(Qt.Horizontal) self.vertical_splitter.setSizes([100000, 400000]) vertical_layout = QVBoxLayout() vertical_layout.addWidget(self.vertical_splitter) vertical_layout.addLayout(horizontal_layout) self.setLayout(vertical_layout) user_settings().restore_widget(self, Key.appearance)
def __init__(self, parent: QWidget): super().__init__(parent) self.doubleClicked.connect(self.file_or_directory_double_clicked) signals().folder_opened_signal.connect(self.folder_opened) self.file_system_model = QFileSystemModel(self) # noinspection PyUnresolvedReferences self.file_system_model.directoryLoaded.connect(self.directory_loaded) self.file_system_model.setFilter(QDir.NoDotAndDotDot | QDir.AllEntries) self.setModel(self.file_system_model) self.setHeaderHidden(True) # Hide all but the name column of the tree view. for i in range(1, self.file_system_model.columnCount()): self.hideColumn(i) self.set_path(user_settings().get(Key.last_folder_opened, Default.last_folder_opened)) self.loading_previous_folder = True
def closeEvent(self, event: QCloseEvent): user_settings().save_widget(self, Key.editor) user_settings().save_as_json(Key.editor_open_files, list(self.open_files.keys())) current_index = self.tabs.currentIndex() if current_index >= 0: tab: EditorTab = self.tabs.widget(current_index) user_settings().save(Key.editor_current_file, tab.path) for tab in self.open_files.values(): tab.close() super().closeEvent(event)
def open_folder(self): """ Open a folder with the user's project files. """ dialog = QFileDialog( self.parent, 'Select your project folder', user_settings().get(Key.last_folder_opened, Default.last_folder_opened), "Assembly (*.asm);;All files (*)") dialog.setFileMode(QFileDialog.DirectoryOnly) if dialog.exec() == QDialog.Accepted: # Check a directory really was chosen as this is reliant on the system dialog if not dialog.selectedFiles(): QErrorMessage().showMessage( "Please select only a folder to open.") return chosen_directory = dialog.selectedFiles()[0] if not os.path.isdir(chosen_directory): QErrorMessage().showMessage( "Please select only a folder to open.") return signals().folder_opened_signal.emit(chosen_directory)
def closeEvent(self, event: QCloseEvent): user_settings().save_widget(self, self.settings_key) super().closeEvent(event)
def closeEvent(self, event: QCloseEvent): user_settings().save_widget(self, Key.tools) super().closeEvent(event)
def closeEvent(self, event: QCloseEvent): user_settings().save_widget(self, Key.appearance) super().closeEvent(event)
def closeEvent(self, event: QCloseEvent): user_settings().save_widget(self, Key.project_tree) super().closeEvent(event)
def folder_opened(self, folder: str): self.set_path(folder) user_settings().save(Key.last_folder_opened, folder)
def directory_loaded(self, path): # We have to restore the tree view here to ensure it is expanded # only when the directory is ready to be searched. if self.loading_previous_folder: user_settings().restore_widget(self, Key.project_tree) self.loading_previous_folder = False
def closeEvent(self, event: QCloseEvent): user_settings().save_widget(self, Key.project) self.tree_view.close() super().closeEvent(event)