OpenStructure
Loading...
Searching...
No Matches
build-2.11
stage
lib
python3.11
site-packages
ost
gui
scene
color_select_widget.py
Go to the documentation of this file.
1
#------------------------------------------------------------------------------
2
# This file is part of the OpenStructure project <www.openstructure.org>
3
#
4
# Copyright (C) 2008-2020 by the OpenStructure authors
5
#
6
# This library is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU Lesser General Public License as published by the Free
8
# Software Foundation; either version 3.0 of the License, or (at your option)
9
# any later version.
10
# This library is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13
# details.
14
#
15
# You should have received a copy of the GNU Lesser General Public License
16
# along with this library; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#------------------------------------------------------------------------------
19
# -*- coding: utf-8 -*-
20
21
from
ost
import
gui
22
from
ost
import
gfx
23
from
PyQt5
import
QtCore, QtWidgets, QtGui
24
25
#Gradient Stop
26
class
ColorSelectWidget
(QtWidgets.QWidget):
27
28
colorChanged = QtCore.pyqtSignal()
29
30
def
__init__
(self, width, height, color, parent=None):
31
QtWidgets.QWidget.__init__(self, parent)
32
33
#Membervars
34
self.
width_
= width
35
self.
height_
= height
36
37
if(color
is
None
):
38
self.
color_
= QtWidgets.QColor(
"White"
)
39
else
:
40
self.
color_
= color
41
42
self.show()
43
44
#ContextMenu
45
self.
change_color_
= QtWidgets.QAction(
'ChangeColor'
, self)
46
47
self.
change_color_
.triggered.connect(self.
ChangeColor
ChangeColor
)
48
49
self.addAction(self.
change_color_
)
50
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
51
52
self.
Resize
()
53
54
def
ChangeColor
(self):
55
color = QtWidgets.QColorDialog.getColor(initial = self.
color_
, parent = self,
56
title =
"Select Color"
)
57
58
if(color != self.
color_
and
color.isValid()):
59
self.
color_
= color
60
self.
colorChanged
.emit()
61
self.update()
62
63
def
GetColor
(self):
64
return
self.
color_
65
66
def
GetGfxColor
(self):
67
color = self.
GetColor
()
68
return
gfx.RGB(color.redF(), color.greenF(), color.blueF())
69
70
def
SetColor
(self, color):
71
if(self.
color_
!= color):
72
self.
color_
= color
73
self.
colorChanged
.emit()
74
self.update()
75
76
def
SetGfxColor
(self, color):
77
qcolor= QtWidgets.QColor(color.Red()*255,color.Green()*255,color.Blue()*255,color.Alpha()*255)
78
self.
SetColor
(qcolor)
79
80
def
paintEvent
(self, event):
81
if
self.isEnabled():
82
size = self.size()
83
paint = QtGui.QPainter()
84
if
paint.begin(self):
85
brush = QtGui.QBrush(self.
color_
)
86
paint.setBrush(brush)
87
paint.drawRect(0,
88
0,
89
self.width() - 1,
90
self.height() - 1)
91
paint.end()
92
93
def
mouseDoubleClickEvent
(self, event):
94
self.
ChangeColor
ChangeColor
()
95
96
def
SetSize
(self, width, height):
97
self.
width_
= width
98
self.
height_
= height
99
self.
Resize
()
100
101
def
Resize
(self):
102
self.setMinimumSize(self.
width_
, self.
height_
)
103
self.setMaximumSize(self.
width_
, self.
height_
)
104
self.resize(self.
width_
, self.
height_
)
ost::gui.scene.color_select_widget.ColorSelectWidget
Definition
color_select_widget.py:26
ost::gui.scene.color_select_widget.ColorSelectWidget.paintEvent
paintEvent(self, event)
Definition
color_select_widget.py:80
ost::gui.scene.color_select_widget.ColorSelectWidget.Resize
Resize(self)
Definition
color_select_widget.py:101
ost::gui.scene.color_select_widget.ColorSelectWidget.colorChanged
colorChanged
Definition
color_select_widget.py:28
ost::gui.scene.color_select_widget.ColorSelectWidget.color_
color_
Definition
color_select_widget.py:38
ost::gui.scene.color_select_widget.ColorSelectWidget.GetColor
GetColor(self)
Definition
color_select_widget.py:63
ost::gui.scene.color_select_widget.ColorSelectWidget.mouseDoubleClickEvent
mouseDoubleClickEvent(self, event)
Definition
color_select_widget.py:93
ost::gui.scene.color_select_widget.ColorSelectWidget.__init__
__init__(self, width, height, color, parent=None)
Definition
color_select_widget.py:30
ost::gui.scene.color_select_widget.ColorSelectWidget.GetGfxColor
GetGfxColor(self)
Definition
color_select_widget.py:66
ost::gui.scene.color_select_widget.ColorSelectWidget.ChangeColor
ChangeColor(self)
Definition
color_select_widget.py:54
ost::gui.scene.color_select_widget.ColorSelectWidget.change_color_
change_color_
Definition
color_select_widget.py:45
ost::gui.scene.color_select_widget.ColorSelectWidget.ChangeColor
ChangeColor
Definition
color_select_widget.py:47
ost::gui.scene.color_select_widget.ColorSelectWidget.width_
width_
Definition
color_select_widget.py:34
ost::gui.scene.color_select_widget.ColorSelectWidget.SetSize
SetSize(self, width, height)
Definition
color_select_widget.py:96
ost::gui.scene.color_select_widget.ColorSelectWidget.SetColor
SetColor(self, color)
Definition
color_select_widget.py:70
ost::gui.scene.color_select_widget.ColorSelectWidget.height_
height_
Definition
color_select_widget.py:35
ost::gui.scene.color_select_widget.ColorSelectWidget.SetGfxColor
SetGfxColor(self, color)
Definition
color_select_widget.py:76
Generated by
1.9.8