From be5d47f8634d29d58b9811657ede815814ffde18 Mon Sep 17 00:00:00 2001 From: tassaron Date: Sun, 11 Jun 2017 12:52:29 -0400 Subject: [PATCH] can't right-click empty space + color eyedropper --- components/__base__.py | 4 +++- components/text.py | 2 +- core.py | 4 ++-- mainwindow.py | 27 +++++++++++++++------------ presetmanager.py | 6 +++++- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/components/__base__.py b/components/__base__.py index b95edf4..3ccb5dc 100644 --- a/components/__base__.py +++ b/components/__base__.py @@ -24,7 +24,9 @@ class Component: exec('self.%s = value' % var) def pickColor(self): - color = QtGui.QColorDialog.getColor() + dialog = QtGui.QColorDialog() + dialog.setOption(QtGui.QColorDialog.ShowAlphaChannel, True) + color = dialog.getColor() if color.isValid(): RGBstring = '%s,%s,%s' % ( str(color.red()), str(color.green()), str(color.blue())) diff --git a/components/text.py b/components/text.py index 68cffca..e8fb3d5 100644 --- a/components/text.py +++ b/components/text.py @@ -31,7 +31,7 @@ class Component(__base__.Component): page.comboBox_textAlign.addItem("Right") page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) - page.pushButton_textColor.clicked.connect(lambda: self.pickColor()) + page.pushButton_textColor.clicked.connect(self.pickColor) btnStyle = "QPushButton { background-color : %s; outline: none; }" \ % QColor(*self.textColor).name() page.pushButton_textColor.setStyleSheet(btnStyle) diff --git a/core.py b/core.py index c50918f..e69de50 100644 --- a/core.py +++ b/core.py @@ -95,9 +95,9 @@ class Core(): origName, saveValueStore, exportPath ) + return True except: - # TODO: add proper warning message - print('couldn\'t export %s' % exportPath) + return False def createPresetFile( self, compName, vers, presetName, saveValueStore, filepath=''): diff --git a/mainwindow.py b/mainwindow.py index 5c929c3..2f04559 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -606,20 +606,25 @@ class MainWindow(QtCore.QObject): def componentContextMenu(self, QPos): '''Appears when right-clicking a component in the list''' - if not self.window.listWidget_componentList.selectedItems(): + componentList = self.window.listWidget_componentList + if not componentList.selectedItems(): + return + + # don't show menu if clicking empty space + parentPosition = componentList.mapToGlobal(QtCore.QPoint(0, 0)) + index = componentList.currentRow() + modelIndex = componentList.model().index(index) + if not componentList.visualRect(modelIndex).contains(QPos): return self.presetManager.findPresets() self.menu = QtGui.QMenu() menuItem = self.menu.addAction("Save Preset") - self.connect( - menuItem, - QtCore.SIGNAL("triggered()"), + menuItem.triggered.connect( self.presetManager.openSavePresetDialog ) # submenu for opening presets - index = self.window.listWidget_componentList.currentRow() try: presets = self.presetManager.presets[str(self.core.selectedComponents[index])] self.submenu = QtGui.QMenu("Open Preset") @@ -627,14 +632,12 @@ class MainWindow(QtCore.QObject): for version, presetName in presets: menuItem = self.submenu.addAction(presetName) - self.connect( - menuItem, - QtCore.SIGNAL("triggered()"), - lambda presetName=presetName: + menuItem.triggered.connect( + lambda _, presetName=presetName: self.presetManager.openPreset(presetName) ) - except KeyError as e: - print(e) - parentPosition = self.window.listWidget_componentList.mapToGlobal(QtCore.QPoint(0, 0)) + except KeyError: + pass + self.menu.move(parentPosition + QPos) self.menu.show() diff --git a/presetmanager.py b/presetmanager.py index 7e4efbb..3036f7a 100644 --- a/presetmanager.py +++ b/presetmanager.py @@ -259,4 +259,8 @@ class PresetManager(QtGui.QDialog): if filename: index = self.window.listWidget_presets.currentRow() comp, vers, name = self.presetRows[index] - self.core.exportPreset(filename, comp, vers, name) + if not self.core.exportPreset(filename, comp, vers, name): + self.parent.showMessage( + msg='Couldn\'t export %s.' % filename, + parent=self.window + )