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
f1c0f3f9
Commit
f1c0f3f9
authored
Oct 31, 2020
by
hejulian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved output, add clear, change dimensions, fullscreen
parent
f564d1a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
16 deletions
+31
-16
python_draw.py
python_draw.py
+31
-16
No files found.
python_draw.py
View file @
f1c0f3f9
import
sys
from
PyQt5
import
QtCore
,
QtGui
,
QtWidgets
,
uic
from
PyQt5.QtCore
import
Qt
#
import numpy as np
#
import matplotlib.pyplot as plt
#
import matplotlib.cm as cm
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.cm
as
cm
class
Canvas
(
QtWidgets
.
QLabel
):
def
__init__
(
self
):
super
().
__init__
()
self
.
width
=
5
*
128
self
.
height
=
5
*
128
self
.
width
=
320
self
.
height
=
320
pixmap
=
QtGui
.
QPixmap
(
self
.
width
,
self
.
height
)
# pixmap = pixmap.scaled(self.width*5, self.height*5)
self
.
setPixmap
(
pixmap
)
self
.
clear_screen
()
self
.
last_x
,
self
.
last_y
=
None
,
None
self
.
pen_color
=
QtGui
.
QColor
(
'#a42f3b'
)
...
...
@@ -22,15 +22,23 @@ class Canvas(QtWidgets.QLabel):
print
(
c
)
self
.
pen_color
=
QtGui
.
QColor
(
c
)
def
report_pixels
(
self
,
x
,
y
):
def
clear_screen
(
self
):
empty
=
np
.
zeros
((
self
.
width
,
self
.
height
))
self
.
pixmap
().
fill
(
Qt
.
GlobalColor
.
transparent
)
self
.
update
()
self
.
report_pixels
()
def
report_pixels
(
self
):
channels_count
=
4
w
=
int
(
self
.
width
/
5
)
h
=
int
(
self
.
height
/
5
)
w
=
int
(
self
.
width
)
h
=
int
(
self
.
height
)
image
=
self
.
pixmap
().
scaled
(
w
,
h
).
toImage
()
s
=
image
.
bits
().
asstring
(
w
*
h
*
channels_count
)
# arr = np.frombuffer(s, dtype=np.uint8).reshape((h, w, channels_count))
# img = np.int64(np.all(arr[:, :, :3] == 0, axis=2))
# plt.imsave("image.png", img, cmap=cm.gray)
arr
=
np
.
frombuffer
(
s
,
dtype
=
np
.
uint8
).
reshape
((
h
,
w
,
channels_count
))
img
=
1
-
np
.
int64
(
np
.
all
(
arr
[:,
:,
:
3
]
==
0
,
axis
=
2
))
# img = img.reshape()
plt
.
imsave
(
"image.png"
,
img
,
cmap
=
cm
.
gray
)
# img.show()
# print(int(np.clip(x, 0, 600)/600*28), int(np.clip(y, 0, 600)/600*28))
...
...
@@ -42,12 +50,12 @@ class Canvas(QtWidgets.QLabel):
painter
=
QtGui
.
QPainter
(
self
.
pixmap
())
p
=
painter
.
pen
()
p
.
setWidth
(
2
5
)
p
.
setWidth
(
5
)
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
()
)
self
.
report_pixels
()
painter
.
end
()
self
.
update
()
...
...
@@ -91,12 +99,19 @@ class MainWindow(QtWidgets.QMainWindow):
palette
=
QtWidgets
.
QHBoxLayout
()
# self.add_palette_buttons(palette)
self
.
add_buttons
(
palette
)
l
.
addLayout
(
palette
)
self
.
setCentralWidget
(
w
)
self
.
showFullScreen
()
def
button_pressed
(
self
):
print
(
"Button Pressed"
)
def
button_pressed
(
self
,
c
):
print
(
"Button Pressed"
,
c
)
def
add_buttons
(
self
,
layout
):
btn
=
QtWidgets
.
QPushButton
(
"Clear"
)
btn
.
clicked
.
connect
(
self
.
canvas
.
clear_screen
)
layout
.
addWidget
(
btn
)
def
add_palette_buttons
(
self
,
layout
):
for
i
,
c
in
enumerate
(
COLORS
):
...
...
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