-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#187 - First prototype of new UI main application, outer layer
- Loading branch information
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
|
||
from PyQt6.QtGui import QAction, QIcon | ||
from PyQt6.QtWidgets import QStyle | ||
|
||
ICON_DIRECTORY = os.path.join("icons") | ||
ICON_FILE_EXTENSION = ".png" | ||
|
||
|
||
class Actions: | ||
def __init__(self, style: QStyle): | ||
self._style = style | ||
assert os.path.isdir(ICON_DIRECTORY) | ||
|
||
self.file_new = QAction("New") | ||
self.file_new.setShortcut("Ctrl+N") | ||
self.file_new.setIcon(style.standardIcon(QStyle.StandardPixmap.SP_ArrowBack)) | ||
|
||
self.file_open = QAction("Open") | ||
self.file_open.setShortcut("Ctrl+O") | ||
self.file_open.setIcon(self.get_custom_icon("sample_icon")) | ||
|
||
self.file_save = QAction("Save") | ||
self.file_save.setShortcut("Ctrl+S") | ||
self.file_save.setIcon(style.standardIcon(QStyle.StandardPixmap.SP_DirHomeIcon)) | ||
|
||
self.file_save_as = QAction("Save As") | ||
self.file_save_as.setShortcut("Ctrl+A") | ||
self.file_save_as.setIcon(style.standardIcon(QStyle.StandardPixmap.SP_DialogOpenButton)) | ||
|
||
@staticmethod | ||
def get_custom_icon(icon_name: str): | ||
file_path = os.path.join(ICON_DIRECTORY, icon_name + ".png") | ||
assert os.path.isfile(file_path) | ||
return QIcon(file_path) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import sys | ||
import os | ||
|
||
from PyQt6.QtCore import Qt | ||
from PyQt6.QtWidgets import QMainWindow, QApplication, QLabel, QProgressBar | ||
|
||
from prototype_ui.actions import Actions | ||
from prototype_ui.menubar import MenuBarManager | ||
from prototype_ui.toolbar import ToolBarManager | ||
|
||
|
||
class MainWindow(QMainWindow): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
self.setMinimumSize(200, 200) | ||
self.resize(500, 400) | ||
self.setWindowTitle("Example") | ||
|
||
# Status Bar | ||
self._status_bar_label = QLabel("Hello Status Bar") | ||
self._status_bar_progress = QProgressBar() | ||
self._status_bar_progress.setRange(0, 10) | ||
self._status_bar_progress.setValue(7) | ||
self.statusBar().addPermanentWidget(self._status_bar_label) | ||
self.statusBar().addPermanentWidget(self._status_bar_progress) | ||
|
||
# Define UI actions | ||
self._actions = Actions(self.style()) | ||
|
||
# Menu & Tool bars | ||
self._menu_bar_manager = MenuBarManager(self.menuBar(), self._actions) | ||
self._tool_bar_manager = ToolBarManager(self.addToolBar("Main"), self._actions) | ||
|
||
# Connect actions with callback methods to implement them | ||
self._actions.file_new.triggered.connect(self._new_file) | ||
self._actions.file_open.triggered.connect(self._open_file) | ||
|
||
self.canvas = QLabel("Hello") | ||
self.setCentralWidget(self.canvas) | ||
|
||
self.show() | ||
|
||
def _new_file(self): | ||
print("New File") | ||
self.statusBar().showMessage("Hello Briefly", 5000) # 5 secs | ||
|
||
def _open_file(self): | ||
self.canvas.setCursor(Qt.CursorShape.CrossCursor) | ||
|
||
|
||
if __name__ == '__main__': | ||
app = QApplication([]) | ||
|
||
# app.setStyleSheet("QLabel { color: red } QProgressBar::chunk { background-color: blue }") | ||
|
||
window = MainWindow() | ||
sys.exit(app.exec()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from PyQt6.QtWidgets import QMenuBar | ||
|
||
from prototype_ui.actions import Actions | ||
|
||
|
||
class MenuBarManager: | ||
def __init__(self, menu_bar: QMenuBar, actions: Actions): | ||
self._menu_bar = menu_bar | ||
self._actions = actions | ||
self.setup_menu_bar() | ||
|
||
def setup_menu_bar(self): | ||
self._create_file_menu() | ||
|
||
def _create_file_menu(self): | ||
menu = self._menu_bar.addMenu("File") | ||
menu.addAction(self._actions.file_new) | ||
menu.addAction(self._actions.file_open) | ||
menu.addAction(self._actions.file_save) | ||
menu.addAction(self._actions.file_save_as) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from PyQt6.QtWidgets import QToolBar | ||
|
||
from prototype_ui.actions import Actions | ||
|
||
|
||
class ToolBarManager: | ||
def __init__(self, tool_bar: QToolBar, actions: Actions): | ||
self._toolbar = tool_bar | ||
self._actions = actions | ||
self.setup_tool_bar() | ||
|
||
def setup_tool_bar(self): | ||
self._toolbar.addAction(self._actions.file_new) | ||
self._toolbar.addAction(self._actions.file_open) | ||
self._toolbar.addAction(self._actions.file_save) | ||
self._toolbar.addAction(self._actions.file_save_as) |