diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/icons/toolbar/ellipse.png | bin | 0 -> 37162 bytes | |||
-rw-r--r-- | src/main/python/main.py | 28 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/data.py (renamed from src/main/python/utils/sizes.py) | 13 | ||||
-rw-r--r-- | src/main/python/utils/dialogs.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/funcs.py | 4 | ||||
-rw-r--r-- | src/main/python/utils/toolbar.py | 58 |
7 files changed, 95 insertions, 12 deletions
diff --git a/src/main/icons/toolbar/ellipse.png b/src/main/icons/toolbar/ellipse.png Binary files differnew file mode 100644 index 0000000..e708bdd --- /dev/null +++ b/src/main/icons/toolbar/ellipse.png diff --git a/src/main/python/main.py b/src/main/python/main.py index fc4c145..583baf0 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -3,15 +3,17 @@ import sys from fbs_runtime.application_context.PyQt5 import ApplicationContext from PyQt5.QtCore import QObject, Qt, pyqtSignal -from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette +from PyQt5.QtGui import QBrush, QColor, QImage, QPainter, QPalette, QPen from PyQt5.QtWidgets import (QComboBox, QFileDialog, QFormLayout, QVBoxLayout, QHBoxLayout, QLabel, QMainWindow, QMenu, - QPushButton, QWidget, QMdiArea, QSplitter) + QPushButton, QWidget, QMdiArea, QSplitter, QGraphicsItem) +from PyQt5 import QtWidgets from utils.canvas import canvas from utils.fileWindow import fileWindow -from utils.sizes import ppiList, sheetDimensionList +from utils.data import ppiList, sheetDimensionList from utils import dialogs +from utils.toolbar import toolbar class appWindow(QMainWindow): """ @@ -44,7 +46,7 @@ class appWindow(QMainWindow): #create toolbar and add the toolbar plus mdi to layout self.createToolbar() - mainLayout.addWidget(self.toolbar) + # mainLayout.addWidget(self.toolbar) mainLayout.addWidget(QSplitter(Qt.Vertical, self)) mainLayout.addWidget(self.mdi) @@ -62,11 +64,19 @@ class appWindow(QMainWindow): def createToolbar(self): #place holder for toolbar with fixed width, layout may change - self.toolbar = QWidget(self.mainWidget) - self.toolbar.setObjectName("Toolbar") - self.toolbar.setFixedWidth(200) - toolbarLayout = QFormLayout(self.toolbar) - self.toolbar.setLayout(toolbarLayout) + self.toolbar = toolbar(self.mainWidget) + # self.toolbar.setObjectName("Toolbar") + self.addToolBar(Qt.LeftToolBarArea, self.toolbar) + self.toolbar.toolbuttonClicked.connect(self.toolButtonClicked) + self.toolbar.populateToolbar() + + def toolButtonClicked(self, object): + currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter + if currentDiagram: + graphic = getattr(QtWidgets, object['object'])(*object['args']) + graphic.setPen(QPen(Qt.black, 2)) + graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) + currentDiagram.addItem(graphic) def newProject(self): #call to create a new file inside mdi area diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index a4c56f3..d393e36 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -8,7 +8,7 @@ from PyQt5.QtWidgets import (QFileDialog, QApplication, from . import dialogs from .graphics import customView -from .sizes import paperSizes, ppiList, sheetDimensionList +from .data import paperSizes, ppiList, sheetDimensionList class canvas(QWidget): """ diff --git a/src/main/python/utils/sizes.py b/src/main/python/utils/data.py index b0aa70a..d0b5ca1 100644 --- a/src/main/python/utils/sizes.py +++ b/src/main/python/utils/data.py @@ -33,4 +33,15 @@ paperSizes = { sheetDimensionList = [f'A{i}' for i in range(5)] -ppiList = ["72", "96", "150", "300"]
\ No newline at end of file +ppiList = ["72", "96", "150", "300"] + +toolbarItems = { + 'Ellipse': { + 'name': 'Ellipse', + 'icon': 'ellipse.png', + 'object': 'QGraphicsEllipseItem', + 'args': [20, 20, 300, 300] + } +} + +defaultToolbarItems = toolbarItems.keys()
\ No newline at end of file diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py index 4351f16..e008aa5 100644 --- a/src/main/python/utils/dialogs.py +++ b/src/main/python/utils/dialogs.py @@ -1,5 +1,5 @@ from PyQt5.QtWidgets import QDialog, QPushButton, QFormLayout, QComboBox, QLabel, QMessageBox, QDialogButtonBox -from .sizes import sheetDimensionList, ppiList +from .data import sheetDimensionList, ppiList class paperDims(QDialog): """ diff --git a/src/main/python/utils/funcs.py b/src/main/python/utils/funcs.py new file mode 100644 index 0000000..cd2dc65 --- /dev/null +++ b/src/main/python/utils/funcs.py @@ -0,0 +1,4 @@ +from itertools import zip_longest +def grouper(n, iterable, fillvalue=None): + args = [iter(iterable)] * n + return zip_longest(fillvalue=fillvalue, *args)
\ No newline at end of file diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py new file mode 100644 index 0000000..9a48aa9 --- /dev/null +++ b/src/main/python/utils/toolbar.py @@ -0,0 +1,58 @@ +from PyQt5.QtCore import pyqtSignal, QSize +from PyQt5.QtGui import QIcon +from PyQt5.QtWidgets import QToolBar, QWidget, QHBoxLayout, QLineEdit, QToolButton + +from .data import defaultToolbarItems, toolbarItems +from .funcs import grouper + +class toolbar(QToolBar): + toolbuttonClicked = pyqtSignal(dict) + + def __init__(self, parent = None): + super(toolbar, self).__init__(parent) + self.toolbarItems = defaultToolbarItems + self.toolbarWidgets = [] + self.setFixedWidth = 200 + + self.searchBox = QLineEdit(self) + self.searchBox.textChanged.connect(self.searchQuery) + self.addWidget(self.searchBox) + + def populateToolbar(self): + # self.clearWidgets() + + for a, b, c in grouper(3, self.toolbarItems): + widget = QWidget(self) + layout = QHBoxLayout(widget) + if a is not None: + item = toolbarItems[a] + button = toolbarButton(self, item) + button.clicked.connect(lambda : self.toolbuttonClicked.emit(item)) + layout.addWidget(button) + # layout.addItem(b) + # layout.addItem(c) + self.toolbarWidgets.append(widget) + self.addWidget(widget) + + def clearWidgets(self): + for i in self.toolbarWidgets(): + i.deleteLater() + + def searchQuery(self): + # shorten toolbaritems list with search items + # self.populateToolbar() # populate with toolbar items + text = self.searchBox.toPlainText() + if text == '': + self.toolbarItems = defaultToolbarItems + else: + pass + #implement shortlisting + +class toolbarButton(QToolButton): + + def __init__(self, parent = None, item = None): + super(toolbarButton, self).__init__(parent) + self.setIcon(QIcon(f'../../icons/toolbar/{item["icon"]}')) + self.setIconSize(QSize(25, 25)) + self.setText(f'item["name"]') + self.setFixedSize(30, 30)
\ No newline at end of file |