Python Forum
[WxPython] TypeError: request for something already fulfilled? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [WxPython] TypeError: request for something already fulfilled? (/thread-1318.html)

Pages: 1 2


TypeError: request for something already fulfilled? - merlem - Dec-23-2016

When using wxpython, I frequently get TypeErrors about something that is - as far as I can see - already fulfilled.
Examples:


# -*- coding: cp1252 -*-

import wx, wx.grid, wx.lib.scrolledpanel


class tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        #self.tirogrid = tirogrid(self, id)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add((50, 50))
        #hbox.Add(self.tirogrid, 0, wx.EXPAND)
        
        self.SetSizerAndFit(hbox)
        
        self.SetupScrolling(self)

        
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ######
#                  Mainframe-Fenster aufbauen                                #
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ###### 


class Mainframe(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size = (1200, 900))
        
        self.tiropanel = tiropanel(self, id)
        
        vbox = wx.BoxSizer(wx.VERTICAL) 
        vbox.Add(self.tiropanel, 0, wx.EXPAND)
        
        self.SetSizer(vbox)

        self.Show()



#########################################################################
#     #     #     #     #     #     #     #     #     #     #     #     #
#########################################################################
###########            Hauptprogramm                           ##########
#########################################################################
#     #     #     #     #     #     #     #     #     #     #     #     #
#########################################################################


if __name__ == "__main__": 
    app = wx.App(0)
    Mainframe(None, -1, "Mainframe")
    app.MainLoop()    
gives
Error:
Traceback (most recent call last):   File "TypeErrorExpl02.py", line 51, in <module>     Mainframe(None, -1, "Mainframe")   File "TypeErrorExpl02.py", line 29, in __init__     self.tiropanel = tiropanel(self, id)   File "TypeErrorExpl02.py", line 17, in __init__     self.SetupScrolling(self)   File "pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\scrolledpanel.py", line 71, in SetupScrolling     self.SetScrollRate(rate_x, rate_y)   File "pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 179, in SetScrollRate     return _windows_.ScrolledWindow_SetScrollRate(*args, **kwargs) TypeError: in method 'ScrolledWindow_SetScrollRate', expected argument 1 of type 'wxScrolledWindow *'
SetupScrolling gets 'self', that is tiropanel(wx.lib.scrolledpanel.ScrolledPanel), and as ScrolledPanel, it should be of the Type wxScrolledWindow.

Another one:
# -*- coding: cp1252 -*-

import wx, wx.grid, wx.lib.scrolledpanel

class Linkespanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        self.Eckpanel = Eckpanel(self, id)
        self.tiropanel = tiropanel(self, id)

        hbox = wx.BoxSizer(wx.HORIZONTAL) 
        #hbox.Add(Eckpanel, 0, wx.EXPAND)
        hbox.Add((200, 50))
        hbox.Add(tiropanel, 0, wx.EXPAND)

        self.SetSizerAndFit(hbox)


class tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        #self.tirogrid = tirogrid(self, id)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hbox.Add((50, 50))
        #hbox.Add(self.tirogrid, 0, wx.EXPAND)
        
        self.SetSizerAndFit(hbox)
        
        #self.SetupScrolling(self)


class Eckpanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        #ticosize = ticolgrid.GeSize()
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizerAndFit(hbox)
        
        self.SetMinSize((200, 50))


        
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ######
#                  Mainframe-Fenster aufbauen                                #
##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ###### 


class Mainframe(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size = (1200, 900))
        
        self.Linkespanel = Linkespanel(self, id)
        
        vbox = wx.BoxSizer(wx.VERTICAL) 
        vbox.Add(self.Linkespanel, 0, wx.EXPAND)
        
        self.SetSizer(vbox)

        self.Show()



#########################################################################
#     #     #     #     #     #     #     #     #     #     #     #     #
#########################################################################
###########            Hauptprogramm                           ##########
#########################################################################
#     #     #     #     #     #     #     #     #     #     #     #     #
#########################################################################


if __name__ == "__main__": 
    app = wx.App(0)
    Mainframe(None, -1, "
gives
Error:
Traceback (most recent call last):   File "TypeErrorExpl01.py", line 77, in <module>     Mainframe(None, -1, "Mainframe")   File "TypeErrorExpl01.py", line 55, in __init__     self.Linkespanel = Linkespanel(self, id)   File "TypeErrorExpl01.py", line 15, in __init__     hbox.Add(tiropanel, 0, wx.EXPAND)   File "pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 12697, in Add     return _core_.Sizer_Add(*args, **kwargs) TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item
Even a ScrolledPanel should be in some way a wx.Window, so the requirement of being that is already fulfilled... as far as I can see.

Am I missing something about 'Types' in python, something about the 'item' in question, or may the Error Message just be misleading?


RE: TypeError: request for something already fulfilled? - Yoriz - Dec-23-2016

In the first example, a wx panel's init method is called
class tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
it should be a scrolledpanel's init method that's called
class tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
    def __init__(self, parent, id):
        wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, id)
and when calling setupscrolling don't pass self, the first parameter is scroll_x which is a Boolean True to allow horizontal scrolling, False otherwise.
self.SetupScrolling(self)
if you don't want to pass any arguments don't pass anything
self.SetupScrolling()

In the second example the same init error occurs
class tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
should be
class tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
   def __init__(self, parent, id):
       wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, id)
There is also an error in the linkspanel class
hbox.Add(tiropanel, 0, wx.EXPAND)
should be
hbox.Add(self.tiropanel, 0, wx.EXPAND)
as you had not capitolized the tiropanel class its trying to add that instead.


Note I generally use super instead for calling baseclass init method
class Tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
   def __init__(self, parent, id):
        wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent, id)
can be replaced with
class Tiropanel(wx.lib.scrolledpanel.ScrolledPanel):
   def __init__(self, parent, id):
       super(Tiropanel, self).__init__(parent, id)



RE: TypeError: request for something already fulfilled? - merlem - Dec-23-2016

Ah, yes... I see it now :-o ! Thank you very much.

However, I have the same problem with
class Eckpanel(wx.Panel):
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        self.SetSizerAndFit(hbox)
        
        self.SetMinSize((200, 50))
leading to
Error:
Traceback (most recent call last):   File "datenspal02f.py", line 646, in <module>     Mainframe(None, -1, "Mainframe")   File "datenspal02f.py", line 614, in __init__     self.Mittpanel = Mittpanel(self, id)   File "datenspal02f.py", line 508, in __init__     self.Linkespanel = Linkespanel(self, id)   File "datenspal02f.py", line 526, in __init__     hbox.Add(Eckpanel, 0, wx.EXPAND)   File "\pythonxy\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 12697, in Add     return _core_.Sizer_Add(*args, **kwargs) TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item
There, I have a simple panel, and still it causes an TypeError?

About the usage of 'super', I don't really understand what it does (and therefore, how to use), so I eschew it until now.


RE: TypeError: request for something already fulfilled? - Yoriz - Dec-23-2016

This is not the same error, the error shows that your code has the following
hbox.Add(Eckpanel, 0, wx.EXPAND)
which is trying to add the class Eckpanel which should be an instance of Eckpanel.
you need to create the instance of Eckpanel passing it the parent and id arguments and add the result of that call to hbox's add method.


RE: TypeError: request for something already fulfilled? - merlem - Dec-23-2016

Thank you very much oncemore! I think I understand bit by bit...


RE: TypeError: request for something already fulfilled? - merlem - Feb-23-2017

One case more in these things...

import wx

gridcontent = [["1", "2", "3", "4"],
               ["5", "6", "7", "8"]]

class Mainframe(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        self.grid = wx.GridBagSizer()
        for rownum, gridcontentrow in enumerate(gridcontent):
            for colnum, string in enumerate(gridcontentrow):
                pos = (rownum, colnum)
                print pos
                self.grid.Add(string, pos)
                
        self.SetSizer(self.grid)
        
if __name__ == "__main__": 

    app = wx.App(0)
    preframe = Mainframe(None, -1, "Datenanzeige")   
    app.MainLoop() 
gives

Error:
Traceback (most recent call last):   File "...Gridbagsizerpos01a.py", line 20, in <module>     preframe = Mainframe(None, -1, "Datenanzeige")   File "...Gridbagsizerpos01a.py", line 15, in __init__     self.grid.Add(string, pos)   File "...Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14086, in Add     return _core_.GridBagSizer_Add(*args, **kwargs) TypeError: wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item
The wxpython docs claim: "wxPython has typemaps that will automatically convert from a 2-element sequence of integers to a wx.GBPosition, so you can use the more pythonic representation of the position nearly transparently in Python code."
Then why does (0, 0) not fullfill the requirements of (w,h) or the requirement of being a position respectively, as is needed by GridBagSizer.Add(self, item, pos, span=DefaultSpan, flag=0, border=0, userData=None)?


RE: TypeError: request for something already fulfilled? - Yoriz - Feb-23-2017

The first argument you passed to it string is not one of the types shown in the type error it's a str.


RE: TypeError: request for something already fulfilled? - merlem - Feb-23-2017

Yes. That's the 'item'. The 'pos' is the second argument.


RE: TypeError: request for something already fulfilled? - Yoriz - Feb-23-2017

Yes item is the error not pos.


RE: TypeError: request for something already fulfilled? - merlem - Feb-23-2017

Oh. Unfortunately, 'item' is nowhere explained in the docs (as far as I can say).
How do I make one, then?

Edit:
I checked the tutorials
https://wiki.wxpython.org/GridBagSizerTutorial
https://github.com/wxWidgets/wxPython/blob/master/demo/GridBagSizer.py
https://www.tutorialspoint.com/wxpython/wx_gridbagsizer.htm
http://zetcode.com/wxpython/layout/

and none gives a binding information about what an 'item' might be in this case, except one small piece of information from the last one: "Item is a widget that you insert into the grid."

Well, for 'widget' again the wypyrhon docs offer no reference, not to mention a binding defintion. (At least I can't find any.)
Left to guesswork oncemore... but at least 'widget' sound a bit more 'qualificatory' then 'item' what I assumed to be a quite wide range of beings...