Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Python-Roadshow
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
workshops
Python-Roadshow
Commits
3b0fbec1
Commit
3b0fbec1
authored
Jan 19, 2018
by
Wichit Sombat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
organize ให้ใช้ folder ร่วมกัน
parent
60a005fc
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
163 additions
and
0 deletions
+163
-0
1.bmp
sessions/session-3/Image/1.bmp
+0
-0
1.bmp
sessions/session-3/Image/1/1.bmp
+0
-0
2.bmp
sessions/session-3/Image/1/2.bmp
+0
-0
1.bmp
sessions/session-3/Image/2/1.bmp
+0
-0
ubuwidgets.py
sessions/session-3/ubuwidgets.py
+120
-0
window.py
sessions/session-3/window.py
+43
-0
No files found.
sessions/session-3/Image/1.bmp
0 → 100644
View file @
3b0fbec1
246 Bytes
sessions/session-3/Image/1/1.bmp
0 → 100644
View file @
3b0fbec1
246 Bytes
sessions/session-3/Image/1/2.bmp
0 → 100644
View file @
3b0fbec1
246 Bytes
sessions/session-3/Image/2/1.bmp
0 → 100644
View file @
3b0fbec1
246 Bytes
sessions/session-3/ubuwidgets.py
0 → 100644
View file @
3b0fbec1
from
PyQt5.QtCore
import
Qt
,
QDir
,
QFile
,
QPoint
,
QRect
,
QSize
from
PyQt5.QtWidgets
import
QWidget
,
QPushButton
,
QLineEdit
,
QLabel
,
QGridLayout
from
PyQt5.QtGui
import
QImage
,
QImageWriter
,
QPainter
,
QPen
,
qRgb
,
QPixmap
class
Button
(
QWidget
):
def
__init__
(
self
,
parent
=
None
,
label
=
"Button"
,
on_click
=
None
):
super
(
Button
,
self
)
.
__init__
(
parent
)
button
=
QPushButton
(
label
,
self
)
button
.
move
(
220
,
0
)
button
.
clicked
.
connect
(
on_click
)
grid
=
QGridLayout
()
grid
.
addWidget
(
button
,
1
,
0
,
1
,
2
)
self
.
setLayout
(
grid
)
class
ComboWidget
(
QWidget
):
def
__init__
(
self
,
parent
=
None
,
text_on_label
=
"Label"
,
text_on_button
=
"button"
,
on_click
=
None
,
readOnly
=
False
):
super
(
ComboWidget
,
self
)
.
__init__
(
parent
)
button
=
QPushButton
(
text_on_button
,
self
)
lbl
=
QLabel
(
self
)
lbl
.
setText
(
text_on_label
)
self
.
qle
=
QLineEdit
(
self
)
self
.
qle
.
setReadOnly
(
readOnly
)
self
.
qle
.
setAlignment
(
Qt
.
AlignCenter
)
button
.
clicked
.
connect
(
on_click
)
grid
=
QGridLayout
()
grid
.
addWidget
(
lbl
,
1
,
0
)
grid
.
addWidget
(
self
.
qle
,
1
,
1
)
grid
.
addWidget
(
button
,
1
,
2
)
self
.
setLayout
(
grid
)
def
text
(
self
):
return
self
.
qle
.
text
()
def
set_text
(
self
,
text
=
""
):
self
.
qle
.
setText
(
text
)
class
Board
(
QWidget
):
def
__init__
(
self
,
parent
=
None
):
super
(
Board
,
self
)
.
__init__
(
parent
)
self
.
setAttribute
(
Qt
.
WA_StaticContents
)
self
.
penWidth
=
50
self
.
writing
=
False
self
.
penColor
=
Qt
.
black
self
.
image
=
QImage
()
self
.
lastPoint
=
QPoint
()
self
.
setFixedSize
(
512
,
512
)
def
saveImage
(
self
,
label
):
import
os
visibleImage
=
self
.
image
self
.
resizeImage
(
visibleImage
,
self
.
size
())
if
QDir
(
'Image'
)
.
exists
()
==
False
:
QDir
()
.
mkdir
(
'Image'
)
label
=
'Image/'
+
label
if
QDir
(
label
)
.
exists
()
==
False
:
QDir
()
.
mkdir
(
label
)
cnt
=
0
maxf
=
0
for
file
in
os
.
listdir
(
label
):
if
file
.
endswith
(
'.bmp'
):
cnt
+=
1
tmpN
=
int
(
file
[:
-
4
:])
maxf
=
max
(
maxf
,
tmpN
)
visibleImage
.
save
(
'tmp.bmp'
)
pixmap
=
QPixmap
(
'tmp.bmp'
)
.
scaled
(
8
,
8
)
pixmap
.
save
(
label
+
'/'
+
str
(
max
(
cnt
,
maxf
)
+
1
)
+
'.bmp'
)
QFile
.
remove
(
'tmp.bmp'
)
def
paintEvent
(
self
,
event
):
painter
=
QPainter
(
self
)
dirtyRect
=
event
.
rect
()
painter
.
drawImage
(
dirtyRect
,
self
.
image
,
dirtyRect
)
def
clearImage
(
self
):
self
.
image
.
fill
(
qRgb
(
255
,
255
,
255
))
self
.
update
()
def
mousePressEvent
(
self
,
event
):
if
event
.
button
()
==
Qt
.
LeftButton
:
self
.
lastPoint
=
event
.
pos
()
self
.
writing
=
True
def
mouseMoveEvent
(
self
,
event
):
if
(
event
.
buttons
()
&
Qt
.
LeftButton
)
and
self
.
writing
:
self
.
drawLineTo
(
event
.
pos
())
def
mouseReleaseEvent
(
self
,
event
):
if
event
.
button
()
==
Qt
.
LeftButton
and
self
.
writing
:
self
.
drawLineTo
(
event
.
pos
())
self
.
writing
=
False
def
resizeEvent
(
self
,
event
):
self
.
resizeImage
(
self
.
image
,
self
.
size
())
self
.
update
()
super
(
Board
,
self
)
.
resizeEvent
(
event
)
def
drawLineTo
(
self
,
endPoint
):
painter
=
QPainter
(
self
.
image
)
painter
.
setPen
(
QPen
(
self
.
penColor
,
self
.
penWidth
,
Qt
.
SolidLine
,
Qt
.
RoundCap
,
Qt
.
RoundJoin
))
painter
.
drawLine
(
self
.
lastPoint
,
endPoint
)
self
.
writing
=
True
rad
=
self
.
penWidth
/
2
+
2
self
.
update
(
QRect
(
self
.
lastPoint
,
endPoint
)
.
normalized
()
.
adjusted
(
-
rad
,
-
rad
,
+
rad
,
+
rad
))
self
.
lastPoint
=
QPoint
(
endPoint
)
def
resizeImage
(
self
,
image
,
newSize
):
if
image
.
size
()
==
newSize
:
return
newImage
=
QImage
(
newSize
,
QImage
.
Format_RGB32
)
newImage
.
fill
(
qRgb
(
255
,
255
,
255
))
painter
=
QPainter
(
newImage
)
painter
.
drawImage
(
QPoint
(
0
,
0
),
image
)
self
.
image
=
newImage
sessions/session-3/window.py
0 → 100644
View file @
3b0fbec1
from
PyQt5.QtCore
import
Qt
from
PyQt5.QtWidgets
import
(
QAction
,
QApplication
,
QWidget
,
QGridLayout
)
#from board import Board
#from clearButton import ClearButton
#from trainWidget import TrainWidget
#from testWidget import TestWidget
from
ubuwidgets
import
(
Button
,
ComboWidget
,
Board
)
class
MainWindow
(
QWidget
):
def
__init__
(
self
,
parent
=
None
):
super
(
MainWindow
,
self
)
.
__init__
(
parent
)
self
.
scribbleArea
=
Board
()
self
.
clearButton
=
Button
(
self
,
"Clear Image"
,
self
.
on_clear
)
self
.
saveCombo
=
ComboWidget
(
self
,
"Label: "
,
"Save"
,
self
.
on_save
)
self
.
testCombo
=
ComboWidget
(
self
,
"Result: "
,
"Test"
,
self
.
on_test
,
True
)
grid
=
QGridLayout
()
grid
.
addWidget
(
self
.
scribbleArea
,
1
,
0
)
grid
.
addWidget
(
self
.
clearButton
,
2
,
0
)
grid
.
addWidget
(
self
.
saveCombo
,
3
,
0
)
grid
.
addWidget
(
self
.
testCombo
,
4
,
0
)
self
.
setLayout
(
grid
)
self
.
setWindowTitle
(
"number ubu"
)
self
.
resize
(
512
,
650
)
def
on_clear
(
self
):
self
.
scribbleArea
.
clearImage
()
def
on_save
(
self
):
print
(
'on_save'
)
self
.
scribbleArea
.
saveImage
(
self
.
saveCombo
.
text
())
self
.
scribbleArea
.
clearImage
()
def
on_test
(
self
):
print
(
"testing..."
)
if
__name__
==
'__main__'
:
import
sys
app
=
QApplication
(
sys
.
argv
)
window
=
MainWindow
()
window
.
show
()
sys
.
exit
(
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