Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Merge requests
!324
Add color button (for later use in preferences)
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add color button (for later use in preferences)
colorbutton
into
master
Overview
0
Commits
1
Pipelines
1
Changes
2
Merged
Oscar Gustafsson
requested to merge
colorbutton
into
master
1 year ago
Overview
0
Commits
1
Pipelines
1
Changes
2
Expand
Related to
#104
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
28e6c3a5
1 commit,
1 year ago
2 files
+
68
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
b_asic/gui_utils/color_button.py
0 → 100644
+
62
−
0
Options
"""
Qt button for use in preference dialogs, selecting color.
"""
from
qtpy.QtCore
import
Qt
,
Signal
from
qtpy.QtGui
import
QColor
from
qtpy.QtWidgets
import
QColorDialog
,
QPushButton
class
ColorButton
(
QPushButton
):
"""
Button to select color.
Parameters
----------
color : QColor
The initial color of the button.
*args, **kwargs
Additional arguments are passed to QPushButton.
"""
_color_changed
=
Signal
(
QColor
)
def
__init__
(
self
,
color
:
QColor
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_color
=
None
self
.
_default
=
color
self
.
pressed
.
connect
(
self
.
pick_color
)
# Set the initial/default state.
self
.
set_color
(
self
.
_default
)
def
set_color
(
self
,
color
:
QColor
):
"""
Set new color.
"""
if
color
!=
self
.
_color
:
self
.
_color
=
color
self
.
_color_changed
.
emit
(
color
)
if
self
.
_color
:
self
.
setStyleSheet
(
"
background-color: %s;
"
%
self
.
_color
)
else
:
self
.
setStyleSheet
(
""
)
@property
def
color
(
self
):
"""
Current color.
"""
return
self
.
_color
def
pick_color
(
self
):
"""
Show color-picker dialog to select color.
"""
dlg
=
QColorDialog
(
self
)
if
self
.
_color
:
dlg
.
setCurrentColor
(
self
.
_color
)
if
dlg
.
exec_
():
self
.
set_color
(
dlg
.
currentColor
())
def
mousePressEvent
(
self
,
e
):
if
e
.
button
()
==
Qt
.
RightButton
:
self
.
set_color
(
self
.
_default
)
return
super
().
mousePressEvent
(
e
)
Loading