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
39132f56
Commit
39132f56
authored
Oct 31, 2020
by
hejulian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init add
parent
a2f1778f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
circle_btn.py
circle_btn.py
+71
-0
No files found.
circle_btn.py
0 → 100644
View file @
39132f56
# importing libraries
from
PyQt5.QtWidgets
import
*
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
numpy
as
np
import
sys
class
Window
(
QMainWindow
):
def
__init__
(
self
):
super
().
__init__
()
# setting title
self
.
setWindowTitle
(
"Python "
)
# setting geometry
self
.
setGeometry
(
100
,
100
,
600
,
400
)
# calling method
self
.
UiComponents
()
self
.
coordinates
=
np
.
load
(
"/Users/julian/polybox/PhD/Social/Hat/Frutiger/led_locations.npy"
)
self
.
set_array
=
np
.
zeros
(
self
.
coordinates
.
shape
[
0
])
# showing all the widgets
self
.
show
()
# method for widgets
def
UiComponents
(
self
):
btn_list
=
list
()
coordinates
=
np
.
load
(
"/Users/julian/polybox/PhD/Social/Hat/Frutiger/led_locations.npy"
)
scale_f
=
250
minx
,
miny
=
(
np
.
abs
(
np
.
min
(
coordinates
[:,
0
]))
*
scale_f
,
np
.
abs
(
np
.
min
(
coordinates
[:,
1
]))
*
scale_f
)
for
i
,
(
x
,
y
)
in
enumerate
(
coordinates
):
# creating a push button
button
=
QPushButton
(
""
,
self
)
# setting geometry of button
button
.
setGeometry
(
minx
+
x
*
scale_f
,
miny
+
y
*
scale_f
,
10
,
10
)
button
.
setCheckable
(
True
)
button
.
setObjectName
(
f
"
{
i
}
"
)
# setting radius and border
button
.
setStyleSheet
(
"border-radius : 5; border : 1px solid black; background-color : lightgrey"
)
# adding action to a button
button
.
clicked
.
connect
(
self
.
clickme
)
# action method
def
clickme
(
self
):
btn
=
self
.
sender
()
i
=
int
(
btn
.
objectName
())
if
btn
.
isChecked
():
self
.
set_array
[
i
]
=
1
# setting background color to light-blue
btn
.
setStyleSheet
(
"border-radius :5; border : 1px solid black;background-color : red"
)
# if it is unchecked
else
:
self
.
set_array
[
i
]
=
0
# set background color back to light-grey
btn
.
setStyleSheet
(
"border-radius : 5; border : 1px solid black;background-color : lightgrey"
)
# printing pressed
print
(
"pressed"
,
str
(
i
))
# create pyqt5 app
App
=
QApplication
(
sys
.
argv
)
# create the instance of our Window
window
=
Window
()
# start the app
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