Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jan Zelenka
prasopes
Commits
863d9e29
Commit
863d9e29
authored
Oct 04, 2019
by
3Yan
Browse files
ZCE can be now copied to clipboard
parent
53960fe8
Changes
1
Hide whitespace changes
Inline
Side-by-side
prasopes/zcetools.py
View file @
863d9e29
from
matplotlib.backends.backend_qt5agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
from
PyQt5
import
QtCore
from
PyQt5
import
QtGui
from
PyQt5
import
QtWidgets
from
PyQt5
import
QtPrintSupport
from
prasopes.zcetools_help
import
helpstr
from
io
import
BytesIO
import
numpy
as
np
import
prasopes.graphtools
as
gt
import
prasopes.filetools
as
ft
...
...
@@ -98,23 +100,49 @@ def help_msg(pw):
pw
,
"TSQ zce tool help"
,
"{}"
.
format
(
helpstr
))
def
p
r
int_graph
(
ds
,
coff
,
coffgrad
,
filename
):
p
r
intfig
=
Figure
(
figsize
=
(
5
,
2
),
dpi
=
1
00
)
printplot
=
p
r
intfig
.
add_subplot
(
111
)
def
p
a
int_
zce
graph
(
ds
,
coff
,
coffgrad
,
filename
):
p
a
intfig
=
Figure
(
figsize
=
(
5
,
2
),
dpi
=
3
00
,
constrained_layout
=
True
)
printplot
=
p
a
intfig
.
add_subplot
(
111
)
printplot_overlay
=
printplot
.
twinx
()
print
canvas
=
FigureCanvas
(
p
r
intfig
)
canvas
=
FigureCanvas
(
p
a
intfig
)
textfield
=
QtWidgets
.
QLabel
()
pop_dial
(
printplot
,
printplot_overlay
,
ds
,
coff
,
coffgrad
,
textfield
,
filename
,
None
)
widget
=
QtWidgets
.
QDialog
(
None
,
windowTitle
=
'Print preview'
)
layout
=
QtWidgets
.
QVBoxLayout
(
widget
)
layout
.
addWidget
(
printcanvas
)
widget
.
resize
(
600
,
400
)
widget
.
show
()
dialog
=
QtPrintSupport
.
QPrintDialog
()
if
dialog
.
exec_
()
==
QtWidgets
.
QDialog
.
Accepted
:
printcanvas
.
render
(
dialog
.
printer
())
widget
.
close
()
cache_file
=
BytesIO
()
paintfig
.
savefig
(
cache_file
)
cache_file
.
seek
(
0
)
image
=
QtGui
.
QImage
.
fromData
(
cache_file
.
read
())
return
image
def
clip_spect_img
(
ds
,
coff
,
coffgrad
,
filename
):
image
=
paint_zcegraph
(
ds
,
coff
,
coffgrad
,
filename
)
QtWidgets
.
QApplication
.
clipboard
().
setImage
(
image
)
QtWidgets
.
QApplication
.
clipboard
().
setPixmap
(
QtGui
.
QPixmap
.
fromImage
(
image
))
def
print_graph
(
ds
,
coff
,
coffgrad
,
filename
):
def
printimage
(
printdevice
,
img
):
printer
.
setResolution
(
600
)
painter
=
QtGui
.
QPainter
(
printdevice
)
painter
.
drawImage
(
0
,
0
,
img
)
painter
.
end
()
#TODO: substitute the QPrintPreviewDialog with QPrintPreviewWidget
printPreview
=
QtPrintSupport
.
QPrintPreviewDialog
()
printer
=
printPreview
.
printer
()
printer
.
setPageSize
(
printer
.
A5
)
printer
.
setDuplex
(
printer
.
DuplexNone
)
image
=
paint_zcegraph
(
ds
,
coff
,
coffgrad
,
filename
)
printPreview
.
paintRequested
.
connect
(
lambda
:
printimage
(
printer
,
image
))
printPreview
.
exec
()
def
key_pressed
(
event
,
ds
,
coff
,
coffgrad
,
filename
):
print
(
"trigged"
)
if
event
.
key
()
==
QtCore
.
Qt
.
Key_C
:
if
event
.
modifiers
().
__int__
()
==
QtCore
.
Qt
.
ControlModifier
:
clip_spect_img
(
ds
,
coff
,
coffgrad
,
filename
)
def
dialog
(
parent
,
ds
,
filename
,
update_signal
):
...
...
@@ -144,7 +172,6 @@ def dialog(parent, ds, filename, update_signal):
graph_canvas
=
FigureCanvas
(
dial_graph
)
graph_canvas
.
setStyleSheet
(
"background-color:transparent;"
)
graph_canvas
.
setAutoFillBackground
(
False
)
graph_canvas
.
setFocusPolicy
(
QtCore
.
Qt
.
ClickFocus
)
gt
.
zoom_factory
(
coffspect_grad
,
1.15
,
coffgrad
)
gt
.
pan_factory
(
coffspect_grad
,
coffgrad
)
...
...
@@ -160,6 +187,9 @@ def dialog(parent, ds, filename, update_signal):
close_button
=
QtWidgets
.
QPushButton
(
"Close"
)
close_button
.
clicked
.
connect
(
dial_widget
.
close
)
dial_widget
.
keyPressEvent
=
lambda
event
:
key_pressed
(
event
,
ds
,
coff
,
coffgrad
,
filename
)
butt_layout
=
QtWidgets
.
QHBoxLayout
()
butt_layout
.
addWidget
(
zce_help
)
butt_layout
.
addStretch
(
1
)
...
...
@@ -173,6 +203,7 @@ def dialog(parent, ds, filename, update_signal):
dial_layout
=
QtWidgets
.
QVBoxLayout
(
dial_widget
)
dial_layout
.
addWidget
(
graph_canvas
)
dial_layout
.
addLayout
(
butt_layout
)
dial_widget
.
setFocus
()
dial_widget
.
show
()
pop_dial
(
coffspect
,
coffspect_grad
,
ds
,
coff
,
coffgrad
,
textfield
,
filename
,
parent
)
Write
Preview
Supports
Markdown
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