Merge two pieces of code
-
@mrjj I have just tried it. It prints "PRESS"!
But again if I move the rubberband methods under MyMplCanvas and these:
super().__init__(parent) self.rubberBand = None self.origin = None
again the initial error...!!!
-
This post is deleted!
-
Ok that's good news so it is a QWidget. Then there is hope :)
It reacted to the mousepress!What error ?
the set_canvas one ?
-
@mrjj :-)
Traceback (most recent call last): File "code.py", line 653, in <module> window = OrthoView() File "code.py", line 279, in __init__ self.plotCanvas = MyMplCanvas(self) File "code.py", line 109, in __init__ super().__init__(parent) File "/home/john/Desktop/test/venv/lib/python3.8/site-packages/matplotlib/backends/backend_qt5agg.py", line 21, in __init__ super().__init__(figure=figure) File "/home/john/Desktop/test/venv/lib/python3.8/site-packages/matplotlib/backends/backend_qt5.py", line 214, in __init__ super().__init__(figure=figure) File "/home/john/Desktop/test/venv/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 1722, in __init__ figure.set_canvas(self) AttributeError: 'OrthoView' object has no attribute 'set_canvas'
-
You do realize that your OrthoView does not have such a method ? That its base class (QMainWindow) does not either ?
Therefore since you are taking your code from another project, you might want to check the code of said project for that method.
-
@john_hobbyist said in Merge two pieces of code:
set_canvas
But this is not related to the RubberBand thing. ?
if i look in the ORG project
https://github.com/kklmn/OrthoView/blob/master/OrthoView.pythere is no such method?
So did you add it or where does it come from ? -
-
@john_hobbyist
Hi
the
'MyMplCanvas' object has no attribute 'rubberBand'
or the
object has no attribute 'set_canvas' -
Hi, sorry, what should I do?
-
hi
fix the error.
Tell what line number and what it says. -
@mrjj Hi, for the posted source code above...this is the error:
Traceback (most recent call last): File "code.py", line 513, in <module> window = OrthoView() File "code.py", line 279, in __init__ self.plotCanvas = MyMplCanvas(self) File "code.py", line 113, in __init__ super().__init__(parent) File "/home/john/Desktop/test/venv/lib/python3.8/site-packages/matplotlib/backends/backend_qt5agg.py", line 21, in __init__ super().__init__(figure=figure) File "/home/john/Desktop/test/venv/lib/python3.8/site-packages/matplotlib/backends/backend_qt5.py", line 214, in __init__ super().__init__(figure=figure) File "/home/john/Desktop/test/venv/lib/python3.8/site-packages/matplotlib/backend_bases.py", line 1722, in __init__ figure.set_canvas(self) AttributeError: 'OrthoView' object has no attribute 'set_canvas'
-
Hi
Ok so it has NOTHING to do with the rubberband at all.
Even before you try to insert that, the app was not working.So it complains about
figure.set_canvas(self)So perhaps you didnt copy the figure class etc ?
-
@mrjj I have copied everything from the github repository. The only small modification I did in rubberband code is that I changed this part:
import sys from PySide2.QtCore import QRect from PySide2.QtCore import QSize from PySide2.QtWidgets import QWidget from PySide2.QtWidgets import QRubberBand from PySide2.QtWidgets import QApplication
to this one:
import rubberband import sys from PyQt5 import QtWidgets from PyQt5 import QtCore from PyQt5.QtWidgets import * from PyQt5 import QtCore, QtGui from PyQt5.QtGui import * from PyQt5.QtCore import *
Could this be the source of the strange errors?
-
Rather than just copying it, did you try to run the application from the repo as is ?
-
Then compare it to your version and see where the difference lies.
-
@john_hobbyist
I don't think so, rubber band is the right way to do it. Even if there were another way, like just clicking, I presume you would face the same issues getting it right as you are now for rubber band. -
I try for many hours to incorporate another code in the code from the github repository. I have fixed some errors (because it was written basically for PyQt4). But I cannot fix this error:
Traceback (most recent call last): File "code_2.py", line 333, in <module> screen_pixmap = QtGui.QPixmap.grabWidget(app.desktop()) NameError: name 'QtGui' is not defined Segmentation fault (core dumped)
I change the QtWidgets to QtGui and I get this error:
Traceback (most recent call last): File "code_2.py", line 333, in <module> screen_pixmap = QtWidgets.QPixmap.grabWidget(app.desktop()) AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QPixmap' Segmentation fault (core dumped)
Any ideas??
-
Hi
Are you using Qtpy5 ?I think its
from PyQt5.QtGui import QPixmaphttps://www.pythonguis.com/faq/adding-images-to-pyqt5-applications/