diff options
Diffstat (limited to 'src/main/python/utils')
-rw-r--r-- | src/main/python/utils/app.py | 5 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 24 | ||||
-rw-r--r-- | src/main/python/utils/dialogs.py | 19 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 2 | ||||
-rw-r--r-- | src/main/python/utils/toolbar.py | 43 | ||||
-rw-r--r-- | src/main/python/utils/undo.py | 6 |
6 files changed, 72 insertions, 27 deletions
diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py index 9812fda..4cc8228 100644 --- a/src/main/python/utils/app.py +++ b/src/main/python/utils/app.py @@ -5,14 +5,15 @@ Declare fbs application so that it can be imported in other modules. from fbs_runtime.application_context.PyQt5 import ApplicationContext from PyQt5.QtCore import QSettings from json import JSONEncoder, dumps, loads, dump, load +from os.path import join app = ApplicationContext() settings = QSettings(QSettings.IniFormat, QSettings.UserScope ,"FOSSEE", "Chemical-PFD") version = app.build_settings['version'] -def fileImporter(file): +def fileImporter(*file): # Helper function to fetch files from src/main/resources - return app.get_resource(file) + return app.get_resource(join(*file)) class JSON_Encoder: diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 3f9cee5..66d38e8 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -16,13 +16,14 @@ class canvas(QWidget): for context menu and dialogs. """ - def __init__(self, parent=None, size= 'A4', ppi= '72' , parentMdiArea = None, parentFileWindow = None): + def __init__(self, parent=None, size= 'A4', ppi= '72' , parentMdiArea = None, parentFileWindow = None, landscape=False): super(canvas, self).__init__(parent) #Store values for the canvas dimensions for ease of access, these are here just to be # manipulated by the setters and getters self._ppi = ppi self._canvasSize = size + self._landscape = landscape # self.setFixedSize(parent.size()) #Create area for the graphic items to be placed, this is just here right now for the future # when we will draw items on this, this might be changed if QGraphicScene is subclassed. @@ -104,22 +105,33 @@ class canvas(QWidget): @property def canvasSize(self): return self._canvasSize + @property def ppi(self): return self._ppi + @property + def landscape(self): + return self._landscape + @canvasSize.setter def canvasSize(self, size): self._canvasSize = size if self.painter: - self.resizeView(*paperSizes[self.canvasSize][self.ppi]) + self.resizeView(*(sorted(paperSizes[self.canvasSize][self.ppi], reverse = self.landscape))) @ppi.setter def ppi(self, ppi): self._ppi = ppi if self.painter: - self.resizeView(*paperSizes[self.canvasSize][self.ppi]) - + self.resizeView(*(sorted(paperSizes[self.canvasSize][self.ppi], reverse = self.landscape))) + + @landscape.setter + def landscape(self, bool): + self._landscape = bool + if self.painter: + self.resizeView(*(sorted(paperSizes[self.canvasSize][self.ppi], reverse = self.landscape))) + #following 2 methods are defined for correct pickling of the scene. may be changed to json or xml later so as # to not have a binary file. def __getstate__(self) -> dict: @@ -129,12 +141,14 @@ class canvas(QWidget): "canvasSize": self._canvasSize, "ObjectName": self.objectName(), "symbols": [i for i in self.painter.items() if isinstance(i, shapes.NodeItem)], - "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0) + "lines": sorted([i for i in self.painter.items() if isinstance(i, shapes.Line)], key = lambda x: 1 if x.refLine else 0), + "landscape": self.landscape } def __setstate__(self, dict): self._ppi = dict['ppi'] self._canvasSize = dict['canvasSize'] + self.landscape = dict['landscape'] self.setObjectName(dict['ObjectName']) for item in dict['symbols']: diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py index fa3b5f1..79685c5 100644 --- a/src/main/python/utils/dialogs.py +++ b/src/main/python/utils/dialogs.py @@ -1,12 +1,16 @@ -from PyQt5.QtWidgets import QDialog, QPushButton, QFormLayout, QComboBox, QLabel, QMessageBox, QDialogButtonBox, QHBoxLayout -from .data import sheetDimensionList, ppiList +from PyQt5.QtWidgets import (QCheckBox, QComboBox, QDialog, QDialogButtonBox, + QFormLayout, QHBoxLayout, QLabel, QMessageBox, + QPushButton) + +from .data import ppiList, sheetDimensionList + class paperDims(QDialog): """ Utility dialog box to adjust the current canvas's dimensions, might return just dimensions later so that sizes do not need to be imported in every other module. """ - def __init__(self, parent=None, size='A4', ppi='72', name='Canvas Size'): + def __init__(self, parent=None, size='A4', ppi='72', name='Canvas Size', landscape=False): super(paperDims, self).__init__(parent) #store initial values to show currently set value, also updated when changed. these are returned at EOL @@ -36,6 +40,10 @@ class paperDims(QDialog): dialogBoxLayout.setWidget(1, QFormLayout.LabelRole, ppiLabel) dialogBoxLayout.setWidget(1, QFormLayout.FieldRole, ppiComboBox) + self.landscapeCheckBox = QCheckBox('&Landscape Mode') + self.landscapeCheckBox.setChecked(landscape) + dialogBoxLayout.setWidget(2, QFormLayout.SpanningRole, self.landscapeCheckBox) + # add ok and cancel buttons buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) buttonBox.accepted.connect(self.accept) @@ -50,7 +58,8 @@ class paperDims(QDialog): super(paperDims, self).exec_() self.deleteLater() #remove from memory #if ok was pressed return value else return None - return (self.returnCanvasSize, self.returnCanvasPPI) if self.result() else None + print(self.landscapeCheckBox.isChecked()) + return (self.returnCanvasSize, self.returnCanvasPPI, self.landscapeCheckBox.isChecked()) if self.result() else None class sideViewSwitchDialog(QDialog): """ @@ -107,4 +116,4 @@ def showUndoDialog(undoView, parent): layout = QHBoxLayout(dialogBox) layout.addWidget(undoView) dialogBox.setWindowTitle("Undo Stack") - dialogBox.show()
\ No newline at end of file + dialogBox.show() diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index 663a7f3..e0f5652 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -123,7 +123,7 @@ class fileWindow(QMdiSubWindow): def adjustCanvasDialog(self): #helper context menu function to the context menu dialog box currentTab = self.tabber.currentWidget() - result = dialogs.paperDims(self, currentTab._canvasSize, currentTab._ppi, currentTab.objectName()).exec_() + result = dialogs.paperDims(self, currentTab._canvasSize, currentTab._ppi, currentTab.objectName(), currentTab.landscape).exec_() if result is not None: currentTab.painter.undoStack.push(resizeCommand(result, currentTab, self)) diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py index 7883136..90b46fb 100644 --- a/src/main/python/utils/toolbar.py +++ b/src/main/python/utils/toolbar.py @@ -2,7 +2,7 @@ from fbs_runtime.application_context.PyQt5 import ApplicationContext from PyQt5.QtCore import QSize, Qt, pyqtSignal, QMimeData from PyQt5.QtGui import QIcon, QDrag from PyQt5.QtWidgets import (QBoxLayout, QDockWidget, QGridLayout, QLineEdit, - QScrollArea, QToolButton, QWidget, QApplication, QStyle) + QScrollArea, QToolButton, QWidget, QApplication, QStyle, QLabel) from re import search, IGNORECASE from .data import toolbarItems @@ -20,12 +20,12 @@ class toolbar(QDockWidget): def __init__(self, parent = None): super(toolbar, self).__init__(parent) self.toolbarButtonDict = dict() #initializes empty dict to store toolbar buttons - self.toolbarButtonClassList = [] + self.toolbarLabelDict = dict() self.toolbarItems(toolbarItems.keys()) #creates all necessary buttons self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable) #mainly used to disable closeability of QDockWidget - + self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.NoDockWidgetArea) #declare main widget and layout self.widget = QWidget(self) self.layout = QBoxLayout(QBoxLayout.TopToBottom, self.widget) @@ -57,11 +57,12 @@ class toolbar(QDockWidget): # since changing parent would effect indexing, its important to go in reverse self.diagAreaLayout.itemAt(i).widget().setParent(self) - def populateToolbar(self, list): + def populateToolbar(self, filterFunc=None): #called everytime the button box needs to be updated(incase of a filter) self.clearLayout() #clears layout - for itemClass in list: - for item in self.toolbarButtonDict[itemClass].keys(): + for itemClass in self.toolbarButtonDict.keys(): + self.diagAreaLayout.addWidget(self.toolbarLabelDict[itemClass]) + for item in filter(filterFunc, self.toolbarButtonDict[itemClass].keys()): self.diagAreaLayout.addWidget(self.toolbarButtonDict[itemClass][item]) self.resize() @@ -70,10 +71,10 @@ class toolbar(QDockWidget): # self.populateToolbar() # populate with toolbar items text = self.searchBox.text() #get text if text == '': - self.populateToolbar(self.toolbarItemList) # restore everything on empty string + self.populateToolbar() # restore everything on empty string else: # use regex to search filter through button list and add the remainder to toolbar - self.populateToolbar(filter(lambda x: search(text, x, IGNORECASE), self.toolbarItemList)) + self.populateToolbar(lambda x: search(text, x, IGNORECASE)) def resize(self): # called when main window resizes, overloading resizeEvent caused issues. @@ -81,18 +82,24 @@ class toolbar(QDockWidget): self.layout.setDirection(QBoxLayout.TopToBottom) # here so that a horizontal toolbar can be implemented later # self.setFixedHeight(self.height()) #span available height width = self.width() - QApplication.style().pixelMetric(QStyle.PM_ScrollBarExtent) + # the following line, sets the required height for the current width, so that blank space doesnt occur self.diagAreaWidget.setMinimumHeight(self.diagAreaLayout.heightForWidth(width)) self.setMinimumWidth(.17*parent.width()) #12% of parent width # self.setMinimumWidth(self.diagAreaLayout.minimumSize().width()) #12% of parent width self.diagAreaWidget.setLayout(self.diagAreaLayout) self.diagArea.setWidget(self.diagAreaWidget) + + for _, label in self.toolbarLabelDict.items(): + label.setFixedSize(width, 20) + def toolbarItems(self, itemClasses): #helper functions to create required buttons for itemClass in itemClasses: self.toolbarButtonDict[itemClass] = {} - self.toolbarButtonClassList.append(itemClass) + label = sectionLabel(itemClass) + self.toolbarLabelDict[itemClass] = label for item in toolbarItems[itemClass].keys(): obj = toolbarItems[itemClass][item] button = toolbarButton(self, obj) @@ -113,7 +120,7 @@ class toolbarButton(QToolButton): def __init__(self, parent = None, item = None): super(toolbarButton, self).__init__(parent) #uses fbs resource manager to get icons - self.setIcon(QIcon(fileImporter(f'toolbar/{item["icon"]}'))) + self.setIcon(QIcon(fileImporter('toolbar', item['icon']))) self.setIconSize(QSize(64, 64)) #unecessary but left for future references self.dragStartPosition = None #intialize value for drag event self.itemObject = item['object'] #refer current item object, to handle drag mime @@ -147,4 +154,18 @@ class toolbarButton(QToolButton): def minimumSizeHint(self): #defines button size - return QSize(40, 40)
\ No newline at end of file + return QSize(40, 40) + +class sectionLabel(QLabel): + + def __init__(self, *args): + super(sectionLabel, self).__init__(*args) + self.setAlignment(Qt.AlignHCenter) + self.setStyleSheet(""" + QLabel{ + background-color: #E6E6E3; + border: 2px solid gray; + border-left: 0px; + background-clip: padding; + } + """)
\ No newline at end of file diff --git a/src/main/python/utils/undo.py b/src/main/python/utils/undo.py index b060550..8426494 100644 --- a/src/main/python/utils/undo.py +++ b/src/main/python/utils/undo.py @@ -95,15 +95,15 @@ class resizeCommand(QUndoCommand): def __init__(self, new, canvas, widget, parent = None): super(resizeCommand, self).__init__(parent) self.parent = canvas - self.old = self.parent.canvasSize, self.parent.ppi + self.old = self.parent.canvasSize, self.parent.ppi, self.parent.landscape self.new = new self.widget = widget self.setText(f'Change canvas dimensions to {new[0]} at {new[1]} ppi') def undo(self): - self.parent.canvasSize, self.parent.ppi = self.old + self.parent.canvasSize, self.parent.ppi, self.parent.landscape = self.old self.widget.resizeHandler() def redo(self): - self.parent.canvasSize, self.parent.ppi = self.new + self.parent.canvasSize, self.parent.ppi, self.parent.landscape = self.new self.widget.resizeHandler()
\ No newline at end of file |