Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PreCourlis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
opentelemac
PreCourlis
Commits
c755f1f5
Commit
c755f1f5
authored
4 years ago
by
Arnaud MORVAN
Browse files
Options
Downloads
Patches
Plain Diff
Add DrawBoxTool
parent
5f015cd2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PreCourlis/widgets/graph_tools.py
+72
-0
72 additions, 0 deletions
PreCourlis/widgets/graph_tools.py
PreCourlis/widgets/graph_widget.py
+4
-0
4 additions, 0 deletions
PreCourlis/widgets/graph_widget.py
with
76 additions
and
0 deletions
PreCourlis/widgets/graph_tools.py
0 → 100644
+
72
−
0
View file @
c755f1f5
from
qgis.PyQt
import
QtCore
from
matplotlib.pyplot
import
Rectangle
class
DrawBoxTool
(
QtCore
.
QObject
):
released
=
QtCore
.
pyqtSignal
(
float
,
float
,
float
,
float
)
# xmin, ymin, xmax, ymax
def
__init__
(
self
,
canvas
,
graph
):
super
().
__init__
(
canvas
)
self
.
canvas
=
canvas
self
.
graph
=
graph
self
.
x0
=
None
self
.
y0
=
None
self
.
background
=
None
def
activate
(
self
):
self
.
cidpress
=
self
.
canvas
.
mpl_connect
(
"
button_press_event
"
,
self
.
on_press
)
self
.
cidrelease
=
self
.
canvas
.
mpl_connect
(
"
button_release_event
"
,
self
.
on_release
)
self
.
cidmotion
=
self
.
canvas
.
mpl_connect
(
"
motion_notify_event
"
,
self
.
on_motion
)
def
deactivate
(
self
):
self
.
canvas
.
mpl_disconnect
(
self
.
cidpress
)
self
.
canvas
.
mpl_disconnect
(
self
.
cidrelease
)
self
.
canvas
.
mpl_disconnect
(
self
.
cidmotion
)
def
on_press
(
self
,
event
):
if
event
.
button
==
1
:
self
.
x0
,
self
.
y0
=
event
.
xdata
,
event
.
ydata
self
.
rect
=
Rectangle
((
event
.
xdata
,
event
.
ydata
),
0
,
0
,
fill
=
False
)
self
.
graph
.
add_patch
(
self
.
rect
)
# draw everything but the selected rectangle and store the pixel buffer
self
.
rect
.
set_animated
(
True
)
self
.
canvas
.
draw
()
self
.
background
=
self
.
canvas
.
copy_from_bbox
(
self
.
graph
.
bbox
)
self
.
graph
.
draw_artist
(
self
.
rect
)
self
.
canvas
.
blit
(
self
.
graph
.
bbox
)
def
on_motion
(
self
,
event
):
if
event
.
button
==
1
:
x1
,
y1
=
event
.
xdata
,
event
.
ydata
xmin
,
ymin
,
width
,
height
=
(
min
(
self
.
x0
,
x1
),
min
(
self
.
y0
,
y1
),
abs
(
self
.
x0
-
x1
),
abs
(
self
.
y0
-
y1
),
)
self
.
rect
.
set_bounds
(
xmin
,
ymin
,
width
,
height
)
self
.
canvas
.
restore_region
(
self
.
background
)
self
.
graph
.
draw_artist
(
self
.
rect
)
self
.
canvas
.
blit
(
self
.
graph
.
bbox
)
def
on_release
(
self
,
event
):
if
event
.
button
==
1
:
self
.
rect
.
remove
()
self
.
rect
=
None
self
.
background
=
None
self
.
canvas
.
draw
()
x1
,
y1
=
event
.
xdata
,
event
.
ydata
xmin
,
ymin
,
xmax
,
ymax
=
(
min
(
self
.
x0
,
x1
),
min
(
self
.
y0
,
y1
),
max
(
self
.
x0
,
x1
),
max
(
self
.
y0
,
y1
),
)
self
.
released
.
emit
(
xmin
,
ymin
,
xmax
,
ymax
)
This diff is collapsed.
Click to expand it.
PreCourlis/widgets/graph_widget.py
+
4
−
0
View file @
c755f1f5
...
@@ -5,6 +5,7 @@ from qgis.core import (
...
@@ -5,6 +5,7 @@ from qgis.core import (
from
qgis.PyQt
import
QtCore
,
QtWidgets
from
qgis.PyQt
import
QtCore
,
QtWidgets
from
PreCourlis.core.precourlis_file
import
PreCourlisFileLine
from
PreCourlis.core.precourlis_file
import
PreCourlisFileLine
from
PreCourlis.widgets.graph_tools
import
DrawBoxTool
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
matplotlib.backends.backend_qt4agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.backends.backend_qt4agg
import
FigureCanvasQTAgg
as
FigureCanvas
...
@@ -21,6 +22,9 @@ class GraphWidget(FigureCanvas):
...
@@ -21,6 +22,9 @@ class GraphWidget(FigureCanvas):
self
.
graph
=
plt
.
subplot
(
111
)
self
.
graph
=
plt
.
subplot
(
111
)
self
.
zoom_tool
=
DrawBoxTool
(
self
,
self
.
graph
)
self
.
zoom_tool
.
activate
()
self
.
file
=
None
self
.
file
=
None
self
.
feature
=
None
self
.
feature
=
None
self
.
previous_section
=
None
self
.
previous_section
=
None
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment