def activate(self): """Adds items to scene and setup graphics effect. Called in the constructor and when re-adding the item to the project in the context of undo/redo. """ scene = self._toolbox.ui.graphicsView.scene() scene.addItem(self) shadow_effect = QGraphicsDropShadowEffect() shadow_effect.setOffset(1) shadow_effect.setEnabled(False) self.setGraphicsEffect(shadow_effect)
def __init__(self, toolbox, x, y, w, h, project_item, icon_file, icon_color, background_color): """Base class for project item icons drawn in Design View. Args: toolbox (ToolBoxUI): QMainWindow instance x (float): Icon x coordinate y (float): Icon y coordinate w (float): Icon width h (float): Icon height project_item (ProjectItem): Item icon_file (str): Path to icon resource icon_color (QColor): Icon's color background_color (QColor): Background color """ super().__init__() self._toolbox = toolbox self._project_item = project_item self._moved_on_scene = False self.renderer = QSvgRenderer() self.svg_item = QGraphicsSvgItem() self.colorizer = QGraphicsColorizeEffect() self.setRect(QRectF(x, y, w, h)) # Set ellipse coordinates and size self.text_font_size = 10 # point size # Make item name graphics item. name = project_item.name if project_item else "" self.name_item = QGraphicsSimpleTextItem(name) shadow_effect = QGraphicsDropShadowEffect() shadow_effect.setOffset(1) shadow_effect.setEnabled(False) self.setGraphicsEffect(shadow_effect) self.set_name_attributes() # Set font, size, position, etc. # Make connector buttons self.connectors = dict( bottom=ConnectorButton(self, toolbox, position="bottom"), left=ConnectorButton(self, toolbox, position="left"), right=ConnectorButton(self, toolbox, position="right"), ) # Make exclamation and rank icons self.exclamation_icon = ExclamationIcon(self) self.rank_icon = RankIcon(self) # Group the drawn items together by setting the background rectangle as the parent of other QGraphicsItems # NOTE: setting the parent item moves the items as one! self.name_item.setParentItem(self) for conn in self.connectors.values(): conn.setParentItem(self) self.svg_item.setParentItem(self) self.exclamation_icon.setParentItem(self) self.rank_icon.setParentItem(self) brush = QBrush(background_color) self._setup(brush, icon_file, icon_color) # Add items to scene scene = self._toolbox.ui.graphicsView.scene() scene.addItem(self)
def add_window_drop_shadow() -> None: """Adds a drop-shadow behind the window""" if self.__use_shadow: self.layout().setMargin(self.__style.window.SHADOW_RADIUS_PX) drop_shadow_effect = QGraphicsDropShadowEffect(self) drop_shadow_effect.setEnabled(True) drop_shadow_effect.setBlurRadius( self.__style.window.SHADOW_RADIUS_PX) color = QColor(self.__style.window.SHADOW_COLOR_RGB) color.setAlpha(self.__style.window.SHADOW_OPACITY_HEX) drop_shadow_effect.setColor(color) drop_shadow_effect.setOffset(0) self.setGraphicsEffect(drop_shadow_effect)
def __init__(self, toolbox, icon_file, icon_color, background_color): """ Args: toolbox (ToolboxUI): QMainWindow instance icon_file (str): Path to icon resource icon_color (QColor): Icon's color background_color (QColor): Background color """ super().__init__() self._toolbox = toolbox self.icon_file = icon_file self._moved_on_scene = False self.previous_pos = QPointF() self.current_pos = QPointF() self.icon_group = {self} self.renderer = QSvgRenderer() self.svg_item = QGraphicsSvgItem(self) self.colorizer = QGraphicsColorizeEffect() self.setRect( QRectF(-self.ITEM_EXTENT / 2, -self.ITEM_EXTENT / 2, self.ITEM_EXTENT, self.ITEM_EXTENT)) self.text_font_size = 10 # point size # Make item name graphics item. self._name = "" self.name_item = QGraphicsSimpleTextItem(self._name, self) self.set_name_attributes() # Set font, size, position, etc. # Make connector buttons self.connectors = dict( bottom=ConnectorButton(self, toolbox, position="bottom"), left=ConnectorButton(self, toolbox, position="left"), right=ConnectorButton(self, toolbox, position="right"), ) # Make exclamation and rank icons self.exclamation_icon = ExclamationIcon(self) self.execution_icon = ExecutionIcon(self) self.rank_icon = RankIcon(self) brush = QBrush(background_color) self._setup(brush, icon_file, icon_color) shadow_effect = QGraphicsDropShadowEffect() shadow_effect.setOffset(1) shadow_effect.setEnabled(False) self.setGraphicsEffect(shadow_effect)
class PreferencesGUI(App): ''' Main class for the Preferences Window ''' keys = list() finished = Signal() def __init__(self, appctxt, windowInst): super().__init__() self.appctxt = appctxt self.initUI(windowInst) # self.windowInst.setWindowFlags(QtCore.Qt.WindowTitleHint | QtCore.Qt.FramelessWindowHint) # self.windowInst.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.settings = QSettings(self.COMPANY_NAME, self.APPLICATION_NAME) self.receiversInst = Receivers(self.ui) self.receiversInst.confirmSignal.connect(self.handleExit) self.connectReceivers() self.guiHelper = GuiHelper() self.loadKeys() self.loadSettings() def terminate(self): self.storeSettings() del self.settings def initUI(self, windowInst): # self.app = QtWidgets.QApplication(sys.argv) self.ui = Ui_PreferencesDialog() self.ui.windowInst = windowInst self.ui.windowInst.hide() self.ui.setupUi(self.ui.windowInst) windowInst.setAttribute(Qt.WA_TranslucentBackground) self.backgroundEffect = QGraphicsDropShadowEffect(windowInst) self.backgroundEffect.setBlurRadius(30) self.backgroundEffect.setOffset(0, 0) self.backgroundEffect.setEnabled(True) self.ui.centralwidget.setGraphicsEffect(self.backgroundEffect) self.ui.comboBoxAutosaveMode.addItem("Don't Autosave") self.ui.comboBoxAutosaveMode.addItem("5 min Autosave") self.ui.comboBoxAutosaveMode.addItem("10 min Autosave") self.ui.comboBoxAutosaveMode.addItem("15 min Autosave") self.ui.comboBoxAutosaveMode.addItem("20 min Autosave") self.ui.comboBoxThemeSelect.addItem("Dark Theme") self.ui.comboBoxThemeSelect.addItem("Light Theme") # self.ui.comboBoxThemeSelect.addItem("Ambient Theme") def run(self): ''' Starts the Preferences Window ''' self.loadSettings() self.ui.windowInst.show() @Slot(bool) def handleExit(self, confirmed): if confirmed: self.storeLooseEntries() self.storeSettings() print('Settings saved') else: self.loadSettings() print('Settings discarded') self.finished.emit() def connectReceivers(self): ''' Connects all the buttons to the right receivers ''' self.ui.radioButtonAffectsPDF.clicked.connect( self.receiversInst.setRadioButtonAffectsPDF) self.ui.comboBoxThemeSelect.currentIndexChanged.connect( self.receiversInst.setComboBoxThemeSelect) self.ui.radioButtonSmoothLines.clicked.connect( self.receiversInst.setradioButtonSmoothLines) self.ui.radioButtonSaveOnExit.clicked.connect( self.receiversInst.setRadioButtonSaveOnExit) self.ui.comboBoxAutosaveMode.currentIndexChanged.connect( self.receiversInst.setComboBoxAutosaveMode) self.ui.pushButtonOk.clicked.connect( lambda: self.receiversInst.confirmReceiver()) self.ui.pushButtonCancel.clicked.connect( lambda: self.receiversInst.rejectReceiver()) self.receiversInst.confirmSignal.connect(self.onClose) def loadKeys(self): ''' Load the preferences keys ''' scriptPath = os.path.dirname(os.path.abspath(__file__)) + '\\' # absKeysFilePath = os.path.normpath(scriptPath + KEYSFILEPATH) absKeysFilePath = self.appctxt.get_resource('preferences.keys') keysFileContent = readFile(absKeysFilePath) for key in keysFileContent['lines']: self.keys.append(key.replace('\n', '')) def storeSettings(self): ''' Store the settings from the gui to the local dict and then to the settings instance ''' for key in self.keys: self.settings.setValue(key, str(Preferences.data[key])) self.settings.sync() def storeLooseEntries(self): ''' Saves all entries, which have been entered without explicit confirmation ''' Preferences.updateKeyValue( "radioButtonAffectsPDF", str(self.ui.radioButtonAffectsPDF.isChecked())) Preferences.updateKeyValue( "comboBoxThemeSelect", str(self.ui.comboBoxThemeSelect.currentIndex())) Preferences.updateKeyValue( "radioButtonSmoothLines", str(self.ui.radioButtonSmoothLines.isChecked())) Preferences.updateKeyValue( "radioButtonUsePenAsDefault", str(self.ui.radioButtonSmoothLines.isChecked())) Preferences.updateKeyValue( "radioButtonSaveOnExit", int(self.ui.radioButtonSaveOnExit.isChecked())) Preferences.updateKeyValue( "comboBoxAutosaveMode", int(self.ui.comboBoxAutosaveMode.currentIndex())) Preferences.updateKeyValue( "radioButtonNoInteractionWhileEditing", str(self.ui.radioButtonNoInteractionWhileEditing.isChecked())) @Slot(bool) def onClose(self, store): if store: self.saveSettings() else: self.discardSettings() def saveSettings(self): self.storeLooseEntries() self.storeSettings() def discardSettings(self): self.loadSettings() def loadSettings(self): ''' Load the settings from the settings instance to the local dict ''' for key in self.keys: Preferences.updateKeyValue( key, self.settings.value(key, defaultValue=None, type=str)) self.ensureValidData() self.ui.radioButtonAffectsPDF.setChecked( toBool(Preferences.data["radioButtonAffectsPDF"])) self.ui.comboBoxThemeSelect.setCurrentIndex( int(Preferences.data["comboBoxThemeSelect"])) self.receiversInst.setComboBoxThemeSelect( int(Preferences.data["comboBoxThemeSelect"])) self.ui.radioButtonUsePenAsDefault.setChecked( toBool(Preferences.data["radioButtonUsePenAsDefault"])) self.ui.radioButtonSmoothLines.setChecked( toBool(Preferences.data["radioButtonSmoothLines"])) self.ui.radioButtonSaveOnExit.setChecked( toBool(Preferences.data["radioButtonSaveOnExit"])) self.ui.comboBoxAutosaveMode.setCurrentIndex( int(Preferences.data["comboBoxAutosaveMode"])) self.ui.radioButtonNoInteractionWhileEditing.setChecked( toBool(Preferences.data["radioButtonNoInteractionWhileEditing"])) def ensureValidData(self): # Apply all default preferences if necessary if Preferences.data['radioButtonAffectsPDF'] == "": Preferences.updateKeyValue('radioButtonAffectsPDF', str(True)) if Preferences.data['comboBoxThemeSelect'] == "": Preferences.updateKeyValue('comboBoxThemeSelect', 1) if Preferences.data['radioButtonSmoothLines'] == "": Preferences.updateKeyValue('radioButtonSmoothLines', str(True)) if Preferences.data['radioButtonUsePenAsDefault'] == "": Preferences.updateKeyValue('radioButtonUsePenAsDefault', str(True)) if Preferences.data['comboBoxDrawingMode'] == "": Preferences.updateKeyValue('comboBoxDrawingMode', 0) if Preferences.data['radioButtonSaveOnExit'] == "": Preferences.updateKeyValue('radioButtonSaveOnExit', str(True)) if Preferences.data['comboBoxAutosaveMode'] == "": Preferences.updateKeyValue('comboBoxAutosaveMode', 0) if Preferences.data['radioButtonNoInteractionWhileEditing'] == "": Preferences.updateKeyValue('radioButtonNoInteractionWhileEditing', str(True)) if Preferences.data['textSize'] == "": Preferences.updateKeyValue('textSize', "('0', '0', '0')") if Preferences.data['markerSize'] == "": Preferences.updateKeyValue('markerSize', "70") if Preferences.data['markerColor'] == "": Preferences.updateKeyValue('markerColor', "('0', '0', '0')") if Preferences.data['freehandSize'] == "": Preferences.updateKeyValue('freehandSize', "70") if Preferences.data['freehandColor'] == "": Preferences.updateKeyValue('freehandColor', "('0', '0', '0')") if Preferences.data['formSize'] == "": Preferences.updateKeyValue('formSize', "70") if Preferences.data['formColor'] == "": Preferences.updateKeyValue('formColor', "('0', '0', '0')")