Не могу добавить текст из Qtextedit в "stickynote" matplotlib
Я пытаюсь добавить текст для заметки в сюжет matplotlib, и я хочу получить этот текст из QTextEdit
, который находится в QDialog
это всплывает с кнопкой на панели инструментов.
Это мой код до сих пор:
class TextoMatplotlib(QDialog): def __init__(self): QDialog.__init__(self) uic.loadUi("insertartextoenMatplotlib.ui", self) # Created in QtDesigner #Matplotlib figure fig = plt.figure(1, figsize=(5,5)) fig.clf() ax = fig.add_subplot(111) ax.plot() self.connect(self.textEdit, SIGNAL("returnPressed()"),self.InsertText)
Вот метод, который я хочу соединить с QTextEdit
(это все в одном классе):
def InsertText(self):
nota.insertPlainText(self.textEdit.text())
nota.setText('')
notes = ax.annotate(nota, xy=(), bbox = dict(facecolor="red"))
listadenotas = []
for note in notes:
nota = DraggableNote(note)
nota.connect()
listadenotas.append(nota)
class DraggableNote:
def __init__(self, note):
self.note = nota
self.press = None
def connect(self):
self.cidpress = self.note.figure.canvas.mpl_connect(
"button_pressed_event", self.on_press)
self.cidrelease = self.note.figure.canvas.mpl_connect(
"button_release_event", self.on_release)
self.cidmotion = self.note.figure.canvas.mpl_connect(
"motion_notify_event", self.on_motion)
def on_press(self, event):
if event.inaxes != self.note.axes:
return
contains, attrd = self.note.contains(event)
if not contains:
return
x0, y0 = self.note.xy
self.press = x0, y0, event.xdata, event.ydata
def on_motion(self, event):
if self.press is None:
return
if event.inaxes != self.note.axes:
return
x0, y0, xpress, ypress = self.press
dx = event.xdata - xpress
dy = event.ydata - ypress
self.note.set_x(x0+dx)
self.note.set_y(y0+dy)
self.note.figure.canvas.draw()
def on_release(self, event):
self.press = None
self.note.figure.canvas.draw()
def disconnect(self):
self.note.figure.canvas.mpl_disconnect(self.cidpress)
self.note.figure.canvas.mpl_disconnect(self.cidrelease)
self.note.figure.canvas.mpl_disconnect(self.cidmotion)
Я получил класс "DraggableNote" из примера в документации Matplotlib.
Я не знаю, где проблема. Я мог бы скопировать / вставить это неправильно здесь, но отступ правильный. Извините, если есть ошибка такого рода.
Я надеюсь, что вы можете мне помочь. Спасибо за ответ.
------------------------------ РЕДАКТИРОВАТЬ------------------- -----------------------
Я пытался сделать это проще. Это то, что я сделал:
class TextoMatplotlib(QDialog):
def __init__(self):
QDialog.__init__(self)
uic.loadUi("insertartextoenMatplotlib2.ui", self)
self.setWindowTitle("Insertar Nota")
self.setMinimumSize(250, 120)
self.setMaximumSize(250, 120)
self.label.setText("Insertar texto: ")
x = np.arange(0, 5, 0.1);
y = np.sin(x)
fig, ax = plt.subplots()
ax.plot(x,y)
nota = self.textEdit.toPlainText()
self.connect(self.textEdit, SIGNAL("returnPressed()"), self.insertText)
def insertText(self):
note = ax.annotate(nota, xy=(2, 0), bbox=dict(facecolor='yellow'))
note.draggable()
Это все еще не работает. Я действительно не знаю, что мне здесь не хватает