Skip to content

Commit 89e5953

Browse files
committed
Merge branch 'develop' into 'master'
merge develop into master See merge request Scientific-IT-Systems/python-gr!289
2 parents 9fe709e + f4a114b commit 89e5953

4 files changed

Lines changed: 128 additions & 14 deletions

File tree

examples/pygrwidgetpyside6_ex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def set_draw_flag(self):
6565
def paintEvent(self, ev):
6666
super(GraphicsWidget, self).paintEvent(ev)
6767
painter = QtGui.QPainter(self)
68-
painter.drawText(15, 15, "Contour Example using PySide2/GRWidget ...")
68+
painter.drawText(15, 15, "Contour Example using PySide6/GRWidget ...")
6969

7070

7171
if __name__ == '__main__':

examples/pyside6_ex.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
GR / PySide interoperability example
5+
"""
6+
7+
import sys
8+
import os
9+
from PySide6 import QtCore, QtGui, QtWidgets, Shiboken
10+
from gr.pygr import *
11+
12+
class GrWidget(QtWidgets.QWidget) :
13+
def __init__(self, *args) :
14+
QtWidgets.QWidget.__init__(self)
15+
16+
self.setupUi(self)
17+
18+
os.environ["GKS_WSTYPE"] = "381"
19+
os.environ["GKS_DOUBLE_BUF"] = "True"
20+
21+
self.connect(self.DrawButton, QtCore.SIGNAL("clicked()"), self.draw)
22+
self.connect(self.QuitButton, QtCore.SIGNAL("clicked()"), self.quit)
23+
self.w = 500
24+
self.h = 500
25+
self.sizex = 1
26+
self.sizey = 1
27+
28+
def setupUi(self, Form) :
29+
30+
Form.setWindowTitle("GrWidget")
31+
Form.resize(QtCore.QSize(500, 500).expandedTo(Form.minimumSizeHint()))
32+
33+
self.DrawButton = QtWidgets.QPushButton(Form)
34+
self.DrawButton.setText("Draw")
35+
self.DrawButton.setGeometry(QtCore.QRect(290, 5, 100, 25))
36+
self.DrawButton.setObjectName("draw")
37+
38+
self.QuitButton = QtWidgets.QPushButton(Form)
39+
self.QuitButton.setText("Quit")
40+
self.QuitButton.setGeometry(QtCore.QRect(395, 5, 100, 25))
41+
self.QuitButton.setObjectName("quit")
42+
43+
QtCore.QMetaObject.connectSlotsByName(Form)
44+
45+
def quit(self) :
46+
gr.emergencyclosegks()
47+
self.close()
48+
49+
def draw(self) :
50+
self.setStyleSheet("background-color:white;")
51+
52+
x = range(0, 128)
53+
y = range(0, 128)
54+
z = readfile(os.path.join(os.path.dirname(os.path.realpath(__file__)),
55+
"kws.dat"), separator='$')
56+
zrange = max(z) - min(z)
57+
h = [min(z) + i * 0.025 * zrange for i in range(0, 40)]
58+
59+
gr.clearws()
60+
gr.setwswindow(0, self.sizex, 0, self.sizey)
61+
gr.setviewport(0.075 * self.sizex, 0.95 * self.sizex, 0.075 * self.sizey, 0.95 * self.sizey)
62+
gr.setwindow(1, 128, 1, 128)
63+
gr.setspace(min(z), max(z), 0, 90)
64+
gr.setcharheight(0.018)
65+
gr.setcolormap(-3)
66+
gr.surface(x, y, z, 5)
67+
gr.contour(x, y, h, z, -1)
68+
gr.axes(5, 5, 1, 1, 2, 2, 0.0075)
69+
self.update()
70+
71+
def resizeEvent(self, event):
72+
self.w = event.size().width()
73+
self.h = event.size().height()
74+
if self.w > self.h:
75+
self.sizex = 1
76+
self.sizey = float(self.h)/self.w
77+
else:
78+
self.sizex = float(self.w)/self.h
79+
self.sizey = 1
80+
self.draw()
81+
82+
def paintEvent(self, ev) :
83+
self.painter = QtGui.QPainter()
84+
self.painter.begin(self)
85+
self.painter.drawText(15, 15, "Contour Example using PySide ...")
86+
os.environ['GKSconid'] = "%x!%x" % (int(Shiboken.getCppPointer(self)[0]), int(Shiboken.getCppPointer(self.painter)[0]))
87+
gr.updatews()
88+
self.painter.end()
89+
90+
def screenChangedEvent(self, event):
91+
gr.configurews()
92+
self.update()
93+
94+
app = QtWidgets.QApplication(sys.argv)
95+
if not sys.platform == "linux2" :
96+
app.setStyle('Windows')
97+
98+
w = GrWidget()
99+
w.show()
100+
101+
sys.exit(app.exec())

gr/pygr/mlab.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,7 +4619,8 @@ def _plot_args(args, fmt='xys'):
46194619
global _plt
46204620
args = list(args)
46214621
parsed_args = []
4622-
while args:
4622+
column = 0
4623+
while args or column > 0:
46234624
# Try to read x, y, z and c
46244625
x = y = z = c = None
46254626
if fmt == 'xyuv':
@@ -4655,20 +4656,32 @@ def _plot_args(args, fmt='xys'):
46554656
except TypeError:
46564657
x = y = z = c = None
46574658

4658-
if x is None:
4659-
a = _convert_to_array(args.pop(0), may_be_2d=True)
4659+
if x is None or column > 0:
4660+
if column == 0:
4661+
a = np.array(args[0])
46604662

4661-
if len(a.shape) == 2:
4662-
x, y = a[:, 0], a[:, 1]
4663+
if len(a.shape) == 2 and a.shape[0] == 2:
4664+
x, y = a[0, :], a[1, :]
4665+
args.pop(0)
46634666
else:
46644667
if fmt == 'xys':
4665-
try:
4666-
x = a
4667-
y = _convert_to_array(args[0], xvalues=x)
4668-
args.pop(0)
4669-
except (TypeError, IndexError):
4670-
y = a
4671-
x = np.arange(1, len(a) + 1)
4668+
if len(a.shape) == 2:
4669+
x = np.arange(1, a.shape[1] + 1)
4670+
y = a[column, :]
4671+
if column + 1 < a.shape[0]:
4672+
column += 1
4673+
else:
4674+
column = 0
4675+
break
4676+
else:
4677+
a = _convert_to_array(args.pop(0), may_be_2d=True)
4678+
try:
4679+
x = a
4680+
y = _convert_to_array(args[0], xvalues=x)
4681+
args.pop(0)
4682+
except (TypeError, IndexError):
4683+
y = a
4684+
x = np.arange(1, len(a) + 1)
46724685
elif fmt == 'y':
46734686
y = a
46744687
x = np.arange(1, len(a) + 1)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py38,py39,py310,py311,py312
2+
envlist = py38,py39,py310,py311,py312,py313
33
skipsdist = True
44
[testenv]
55
passenv = GR_TEST_BASE_PATH,GR_VERSION

0 commit comments

Comments
 (0)