wxPython wx.lib.plot.PlotCanvas error - python

I'm making a very straightforward plotting wxApp.
I've installed Python 2.7.9 and wxPython 3.0.2
Here is my code:
import wx
import wx.lib.plot as plot
class Pantalla(wx.Frame):
def __init__(self):
app = wx.App()
self.frame1 = wx.Frame(None, title = "GRAFICADOR", id = -1, size=(500,500))
self.panel1 = wx.Panel(self.frame1)
self.panel1.SetBackgroundColour("white")
plotter = plot.PlotCanvas(self.panel1, id=-1, pos = wx.Point(-1,-1), size = wx.Size(-1,-1), style = 0, name= 'plotCanvas')
data = [(1,2), (2,3), (4,6)]
line = plot.PolyLine(data, colour='red', width = 1)
gc = plot.PlotGraphics([line], 'Line', 'Eje x', 'Eje y')
plotter.Draw(gc, xAxis = (0,15), yAxis=(0,15))
self.frame1.Show(True)
app.MainLoop()
t = Pantalla()
However, whenever I test it, it throws me this error:
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
f = Pantalla()
File "<pyshell#25>", line 7, in __init__
plotter = plot.PlotCanvas(self.panel1, id=-1, pos = wx.Point(-1,-1), size = wx.Size(-1,-1), style = 0, name= 'plotCanvas')
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\lib\plot.py", line 598, in __init__
self.HandCursor = wx.Cursor(Hand.GetImage())
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_gdi.py", line 1547, in __init__
_gdi_.Cursor_swiginit(self,_gdi_.new_Cursor(*args, **kwargs))
TypeError: Required argument 'type' (pos 2) not found
I'm passing all parameters that the documentation of wx says.
What am I doing wrong?

Though this is an issue with wx 3.0.2 release, I tested your code and this issue does not exist in source for wx 3.0.3 'classic' nor with wx 3.0.3 'phoenix'.
You can checkout/build/install the repos for 3.0.3 'classic' from these sources:
https://github.com/wxWidgets/wxWidgets.git
https://github.com/wxWidgets/wxPython.git
Directions after checkout will be in wxPython/docs/BUILD.txt
Alternatively, use the 'phoenix' 3.0.3 with your project using this source:
https://github.com/wxWidgets/Phoenix.git
Directions after checkout will be in wxPython/README.rst

Related

Type Error: argument 1 has unexpected type 'QPushButton'

I wrote this codes:
import sys
import os
from PyQt5 import QtWidgets
class Notepad(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.yazi_alani = QtWidgets.QTextEdit()
self.temizle = QtWidgets.QPushButton("Temizle")
self.kaydet = QtWidgets.QPushButton("Kaydet")
self.dosya_ac = QtWidgets.QPushButton("Dosya Aç")
v_box = QtWidgets.QVBoxLayout()
v_box.addWidget(self.yazi_alani)
v_box.addWidget(self.temizle)
v_box.addWidget(self.kaydet)
v_box.addWidget(self.dosya_ac)
self.setLayout(v_box)
self.setWindowTitle("Barış'ın Notepad Programı")
self.setGeometry(200,200,800,600)
self.temizle.clicked.connect(self.temizle)
self.kaydet.clicked.connect(self.kaydet)
self.dosya_ac.clicked.connect(self.dosya_ac)
self.show()
def temizle(self):
self.yazi_alani.clear()
def kaydet(self):
dosya_ismi = QtWidgets.QFileDialog.getSaveFileName(self,"Dosya Kaydet",os.getenv("HOME"))
with open (dosya_ismi[0],"w",encoding="utf-8") as file:
file.write(self.yazi_alani.toPlainText())
def dosya_ac(self):
dosya_ismi = QtWidgets.QFileDialog(self, "Dosya Aç", os.getenv("HOME"))
with open(dosya_ismi[0],"r",encoding="utf-8") as file:
self.yazi_alani.setText(file.read())
app = QtWidgets.QApplication(sys.argv)
pencere = Notepad()
sys.exit(app.exec())
I got this error:
Traceback (most recent call last):
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 41, in <module>
pencere = Pencere()
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 8, in __init__
self.init_ui()
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 28, in init_ui
self.temizle.clicked.connect(self.temizle)
TypeError: argument 1 has unexpected type 'QPushButton'
How can I solve this error?
It may be good if you answer fast...
pythonerrors
python
error
errors
errorrr
python3-x
You should rename your buttons or funcions.
You've got here method Notepad.temizle() AND button Notepad.temizle
So when you expect to send a message, instead you send a button, which is typeError
Also I can see the same error with other methods

AttributeError: 'AxesSubplot' object has no attribute 'set_canvas'

Good morning,
I am using tkinter with matplotlib but I am facing a problem which I will write down.
I tried many solution but nothing worked, so if you had faced the problem before or if you just know it help me please with it.
Here is my code:
import matplotlib
matplotlib.use('TkAgg')
from tkinter import *
import tkinter.simpledialog
import matplotlib.pyplot as plt
import datetime
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
root = Tk()
root.geometry('1000x600')
middle = Frame(root)
middle.pack()
payments = {'.':0}
m = datetime.datetime.now()
def digram1():
global m
purpose = list(payments.keys())
amounts = list(payments.values())
plt.plot((purpose),(amounts))
plt.xlabel('Purpose')
plt.ylabel('Amounts')
plt.title('Outgoings for the '+ str(m.month)+'th month\n'+str(datetime.date.today()))
plt.show
fig = Figure(figsize=(5,5),dpi = 100)
ex = fig.add_subplot(111)
canvas = FigureCanvasTkAgg(ex,master=root)
canvas.show()
canvas.get_tk_widget().pack(side =tk.top,fill=tk.Both, expand = True)
digram1m = Button(middle,text='1st digram',command=digram1, height = 5,width =15 , fg ='green')
digram1m.grid(row = 5 , column = 6 ,sticky=E)
root.mainloop()
and here is the output:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\A\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "<ipython-input-1-6c5b0c8eaae5>", line 33, in digram1
canvas = FigureCanvasTkAgg(ex,master=root)
File "C:\Users\A\Anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 173, in __init__
FigureCanvasAgg.__init__(self, figure)
File "C:\Users\A\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 1780, in __init__
figure.set_canvas(self)
AttributeError: 'AxesSubplot' object has no attribute 'set_canvas'
I am using Jupyter notebook 5.4.0.
Thank you for your time..

Python timed subprocess.Popen

I have the following code which gets data from a webscrape.
I only just learnt how to use the
subprocess.Popen
and i am trying to ouse my initiative along with other answers to similar questions on how to use the
subprocess.Popen
to execute the script below to get the webscrape data into my insert field updated every 30 seconds or so. But it is not working. Please could you point me in the right direction?
import xlrd
import subprocess
from Tkinter import *
import urllib2
from ttk import *
import Tkinter as tk
class Application(Frame):
"""GUI to display results of 'equity get'"""
def __init__(self, master):
"""initialise the Frame"""
Frame.__init__(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
"""Create button, text and entry Widget"""
"""what it is i.e. label"""
url = "https://......."
request= urllib2.Request(url)
handle = urllib2.urlopen(request)
content = handle.read()
splitted_page = content.split("<.......">", 1);
splitted_page = splitted_page24[1].split("</.......>", 1)
self.data = Label(self, text ="Data")
self.data1 = Entry(self, width = 10)
self.data1.insert(0,splitted_page[0])
self.data.grid(column = 1, row = 1)
self.data1.grid(column = 2, row = 1)
self.data1.grid(column = 3, row = 1)
a = 0
while a < 10:
a += 1
time.sleep(15)
while True:
out = subprocess.Popen(["C:\Users\.....\Desktop\Py\python.exe","C:\Users\.....\Desktop\..\Python27\.....\tester.py"])
app = Application(root)
root.title("reload test")
root.geometry("700x300")
root.mainloop()
the error i get is
error no 22: invalid syntax referring to the script between the
(["C:\Users\.....\Desktop\Py\python.exe","C:\Users\.....\Desktop\..\Python27\.....\tester.py"])
then multiple command line windows open displaying the same error and i have to shut down the computer to stop it!
i amended the reference to my file with the 'r' prefix as follows:
([r"C:\Users\.....\Desktop\..\Python27\.....\tester.py"])
but removed the python.exe call as it just calling up the command line window. Now, i receive the following error message:
Traceback (most recent call last):
File "C:\Users\....\Desktop\Py\Python27\.....\tester.py", line 46, in <module>
app = Application(root)
File "C:\Users\......\Desktop\Py\Python27\.....\tester.py", line 18, in __init__
self.create_widgets()
File "C:\Users\.....\Desktop\Py\Python27\......\tester.py", line 44, in create_widgets
out = subprocess.Popen([r"C:\Users\Isaac\Desktop\Py\Python27\.....\tester.py"])
File "C:\Users\.....\Desktop\Py\lib\subprocess.py", line 672, in __init__
errread, errwrite)
File "C:\Users\.....\Desktop\Py\lib\subprocess.py", line 882, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application
Python uses backslash to quote characters, like \n = newline and \t = tab.
Use an r prefix to make a raw string literal, like a Windows file path:
out = subprocess.Popen([r"C:\Users\.....\Desktop\Py\python.exe", r"C:\Users\.....\Desktop\..\Python27\.....\tester.py"])

Python does not detect soundtouch elements (bpmdetect and pitch) in gst-plugins-bad

I have installed gstreamer, gst-plugins-bad and its python bindings.
The following code selects a song from a given directory and plays it.
import pygst
pygst.require("0.10")
import gst
import pygtk
import gtk
import os
class Main:
def __init__(self):
self.pipeline = gst.Pipeline("mypipeline")
self.musicFiles = os.listdir("musicFiles")
self.currentSong = self.musicFiles[0]
self.findFile = gst.element_factory_make("filesrc", "file")
self.findFile.set_property("location", "musicFiles/" + self.currentSong)
self.pipeline.add(self.findFile)
self.mad = gst.element_factory_make("mad", "mad")
self.pipeline.add(self.mad)
self.findFile.link(self.mad)
self.audioconvert = gst.element_factory_make("audioconvert", "convert")
self.pipeline.add(self.audioconvert)
self.mad.link(self.audioconvert)
self.audioresample = gst.element_factory_make("audioresample", "resample")
self.pipeline.add(self.audioresample)
self.audioconvert.link(self.audioresample)
self.getbpm = gst.element_factory_make("bpmdetect", "bpm")
self.pipeline.add(self.getbpm)
self.audioresample.link(self.getbpm)
self.sink = gst.element_factory_make("playsink", "sink")
self.pipeline.add(self.sink)
self.audioresample.link(self.sink)
self.pipeline.set_state(gst.STATE_PLAYING)
start=Main()
gtk.main()
However, when I try to create the bpmdetect element, it gives the following error:
Traceback (most recent call last):
File "/Users/shubhitsingh/Desktop/Stuff/COLLEGE/US/Carnegie Mellon/Fall '12/15-112/Term Project/Practice/gstreamertutorial-1.py", line 49, in <module>
start=Main()
File "/Users/shubhitsingh/Desktop/Stuff/COLLEGE/US/Carnegie Mellon/Fall '12/15-112/Term Project/Practice/gstreamertutorial-1.py", line 37, in __init__
self.getbpm = gst.element_factory_make("bpmdetect", "bpm")
ElementNotFoundError: bpmdetect
Other elements from gst-plugins-bad can be created without problems. Its just the two elements under soundtouch (bpmdetect and pitch) that cannot be created. Help?

Placing a Button in UltimateListCtrl using wxPython

I'm new to Pythong and I have been trying to get a button within UltimateListCtrl. I still can't figure out what I'm doing wrong. Here is my code:
try:
from agw import ultimatelistctrl as ULC
except ImportError: # if it's not there locally, try the wxPython lib.
from wx.lib.agw import ultimatelistctrl as ULC
self.table = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT|
ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
self.table.InsertColumn(0, "Name")
self.table.InsertColumn(1, "Size")
self.table.InsertColumn(2, "Download")
for i in range(0, len(masterlist)):
pos = self.table.InsertStringItem(i,str(masterlist[i]['name']))
self.table.SetStringItem(pos, 1,str(masterlist[i]['size']))
button = wx.Button(self, id=i, label="Download")
self.table.SetItemWindow(pos, col=2, wnd=button, expand=True)
masterlist is a list of download items.
I get this traceback:
Traceback (most recent call last):
File "E:\TestApp.py", line 67, in Display
self.table.SetItemWindow(pos, col=5, wnd=button, expand=True)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 12961, in SetItemWindow
return self._mainWin.SetItemWindow(item, wnd, expand)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 9021, in SetItemWindow
item.SetWindow(wnd, expand)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 1863, in SetWindow
mainWin = listCtrl._mainWin
AttributeError: 'MainWindow' object has no attribute '_mainWin'
button's parent should be your ULC i.e self.table
So change this line:
button = wx.Button(self, id=wx.ID_ANY, label="Download")
to this:
button = wx.Button(self.table, id=wx.ID_ANY, label="Download")
Update in response to comment:
For some reason it doesn't seem to be possible to delete all items in a ULC with the
DeleteAllItems() method if any of the items contain widgets so instead use DeleteItem().
def emptyList(self)
itemCount = self.list.GetItemCount()
for item in xrange(itemCount):
self.list.DeleteItem(0)

Categories

Resources