Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pythondraw
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hejulian
pythondraw
Commits
c63f1ab6
Commit
c63f1ab6
authored
Oct 14, 2020
by
hejulian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial add
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
python_draw.py
python_draw.py
+97
-0
No files found.
python_draw.py
0 → 100644
View file @
c63f1ab6
import
sys
from
PyQt5
import
QtCore
,
QtGui
,
QtWidgets
,
uic
from
PyQt5.QtCore
import
Qt
import
numpy
as
np
class
Canvas
(
QtWidgets
.
QLabel
):
def
__init__
(
self
):
super
().
__init__
()
pixmap
=
QtGui
.
QPixmap
(
28
,
28
)
self
.
setPixmap
(
pixmap
)
self
.
last_x
,
self
.
last_y
=
None
,
None
self
.
pen_color
=
QtGui
.
QColor
(
'#000000'
)
def
set_pen_color
(
self
,
c
):
print
(
c
)
self
.
pen_color
=
QtGui
.
QColor
(
c
)
def
report_pixels
(
self
,
x
,
y
):
print
(
int
(
np
.
clip
(
x
,
0
,
600
)
/
600
*
28
),
int
(
np
.
clip
(
y
,
0
,
600
)
/
600
*
28
))
def
mouseMoveEvent
(
self
,
e
):
if
self
.
last_x
is
None
:
# First event.
self
.
last_x
=
e
.
x
()
self
.
last_y
=
e
.
y
()
return
# Ignore the first time.
painter
=
QtGui
.
QPainter
(
self
.
pixmap
())
p
=
painter
.
pen
()
p
.
setWidth
(
600
/
28
)
p
.
setColor
(
self
.
pen_color
)
painter
.
setPen
(
p
)
painter
.
drawLine
(
self
.
last_x
,
self
.
last_y
,
e
.
x
(),
e
.
y
())
self
.
report_pixels
(
e
.
x
(),
e
.
y
())
painter
.
end
()
self
.
update
()
# Update the origin for next time.
self
.
last_x
=
e
.
x
()
self
.
last_y
=
e
.
y
()
def
mouseReleaseEvent
(
self
,
e
):
self
.
last_x
=
None
self
.
last_y
=
None
COLORS
=
[
# 17 undertones https://lospec.com/palette-list/17undertones
'#000000'
,
'#141923'
,
'#414168'
,
'#3a7fa7'
,
'#35e3e3'
,
'#8fd970'
,
'#5ebb49'
,
'#458352'
,
'#dcd37b'
,
'#fffee5'
,
'#ffd035'
,
'#cc9245'
,
'#a15c3e'
,
'#a42f3b'
,
'#f45b7a'
,
'#c24998'
,
'#81588d'
,
'#bcb0c2'
,
'#ffffff'
,
]
class
QPaletteButton
(
QtWidgets
.
QPushButton
):
def
__init__
(
self
,
color
):
super
().
__init__
()
self
.
setFixedSize
(
QtCore
.
QSize
(
24
,
24
))
self
.
color
=
color
self
.
setStyleSheet
(
"background-color: %s;"
%
color
)
class
MainWindow
(
QtWidgets
.
QMainWindow
):
def
__init__
(
self
):
super
().
__init__
()
self
.
canvas
=
Canvas
()
w
=
QtWidgets
.
QWidget
()
l
=
QtWidgets
.
QVBoxLayout
()
w
.
setLayout
(
l
)
l
.
addWidget
(
self
.
canvas
)
palette
=
QtWidgets
.
QHBoxLayout
()
self
.
add_palette_buttons
(
palette
)
l
.
addLayout
(
palette
)
self
.
setCentralWidget
(
w
)
def
button_pressed
(
self
,
c
):
print
(
"Button Pressed"
,
c
)
def
add_palette_buttons
(
self
,
layout
):
for
i
,
c
in
enumerate
(
COLORS
):
b
=
QPaletteButton
(
COLORS
[
i
])
b
.
clicked
.
connect
(
lambda
state
,
c
=
c
:
self
.
canvas
.
set_pen_color
(
c
))
layout
.
addWidget
(
b
)
app
=
QtWidgets
.
QApplication
(
sys
.
argv
)
window
=
MainWindow
()
window
.
show
()
app
.
exec_
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment