提交 df3eb15c 编写于 作者: M Michael Pitidis

Add Restore Defaults button in color dialog

上级 b491268f
......@@ -2,15 +2,29 @@
from PyQt4.QtGui import *
from PyQt4.QtCore import *
BB = QDialogButtonBox
class ColorDialog(QColorDialog):
def __init__(self, parent=None):
super(ColorDialog, self).__init__(parent)
self.setOption(QColorDialog.ShowAlphaChannel)
## Add a restore defaults button.
# The default is set at invocation time, so that it
# works across dialogs for different elements.
self.default = None
self.bb = self.layout().itemAt(1).widget()
self.bb.addButton(BB.RestoreDefaults)
self.bb.clicked.connect(self.checkRestore)
def getColor(self, value=None, title=None):
def getColor(self, value=None, title=None, default=None):
self.default = default
if title:
self.setWindowTitle(title)
if value:
self.setCurrentColor(value)
return self.currentColor() if self.exec_() else None
def checkRestore(self, button):
if self.bb.buttonRole(button) & BB.ResetRole and self.default:
self.setCurrentColor(self.default)
......@@ -14,7 +14,7 @@ from PyQt4.QtCore import *
import resources
from lib import struct, newAction, addActions, labelValidator
from shape import Shape
from shape import Shape, DEFAULT_LINE_COLOR, DEFAULT_FILL_COLOR
from canvas import Canvas
from zoomWidget import ZoomWidget
from labelDialog import LabelDialog
......@@ -32,7 +32,6 @@ __appname__ = 'labelme'
# - [low] Label validation/postprocessing breaks with TAB.
# TODO:
# - [medium] Add a 'Reset' button to color dialogs.
# - [medium] Highlight label list on shape selection and vice-verca.
# - [medium] Add undo button for vertex addition.
# - [medium,maybe] Support vertex moving.
......@@ -501,7 +500,8 @@ class MainWindow(QMainWindow, WindowMixin):
return os.path.dirname(unicode(self.filename)) if self.filename else '.'
def chooseColor1(self):
color = self.colorDialog.getColor(self.lineColor, u'Choose line color')
color = self.colorDialog.getColor(self.lineColor, u'Choose line color',
default=DEFAULT_LINE_COLOR)
if color:
self.lineColor = color
# Change the color for all shape lines:
......@@ -509,7 +509,8 @@ class MainWindow(QMainWindow, WindowMixin):
self.canvas.repaint()
def chooseColor2(self):
color = self.colorDialog.getColor(self.fillColor, u'Choose fill color')
color = self.colorDialog.getColor(self.fillColor, u'Choose fill color',
default=DEFAULT_FILL_COLOR)
if color:
self.fillColor = color
Shape.fill_color = self.fillColor
......
......@@ -10,14 +10,18 @@ from PyQt4.QtCore import *
# TODO:
# - [opt] Store paths instead of creating new ones at each paint.
DEFAULT_LINE_COLOR = QColor(0, 255, 0, 128)
DEFAULT_FILL_COLOR = QColor(255, 0, 0, 128)
DEFAULT_SELECT_COLOR = QColor(255, 255, 255)
class Shape(object):
P_SQUARE, P_ROUND = range(2)
## The following class variables influence the drawing
## of _all_ shape objects.
line_color = QColor(0, 255, 0, 128)
fill_color = QColor(255, 0, 0, 128)
select_color = QColor(255, 255, 255)
line_color = DEFAULT_LINE_COLOR
fill_color = DEFAULT_FILL_COLOR
select_color = DEFAULT_SELECT_COLOR
point_type = P_SQUARE
point_size = 8
scale = 1.0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册