Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1044505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:50:20+00:00 2026-05-16T15:50:20+00:00

I’ve just repackaged my program. Previously all modules lived under the whyteboard package, with

  • 0

I’ve just repackaged my program. Previously all modules lived under the “whyteboard” package, with a “fakewidgets” package containing a bunch of dummy GUI test objects.

Now, all my modules are in packages, e.g. whyteboard.gui, whyteboard.misc, whyteboard.test – which is where fakewidgets now lives.

Now, when running my tests, I get an exception,

  File "/home/steve/Documents/whyteboard/whyteboard/gui/canvas.py", line 77, in __init__
    wx.ScrolledWindow.__init__(self, tab, style=wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN)
TypeError: unbound method __init__() must be called with ScrolledWindow instance as first argument (got Canvas instance instead)

here’s
the class in question

class Canvas(wx.ScrolledWindow):
    def __init__(self, tab, gui, area):
        wx.ScrolledWindow.__init__(self, tab, style=wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN)

However, my program loads and runs correctly, except from unit tests. The code is the same, just the code for my tests’ imports are different to pull in from the new packages.

Before:

import os
import wx

import fakewidgets
import gui
import lib.mock as mock

from canvas import Canvas, RIGHT, DIAGONAL, BOTTOM
from fakewidgets.core import Bitmap, Event, Colour

from lib.configobj import ConfigObj
from lib.pubsub import pub
from lib.validate import Validator

now:

import os
import wx

import whyteboard.test
import whyteboard.gui.frame as gui

from whyteboard.lib import ConfigObj, mock, pub, Validator
from whyteboard.gui.canvas import Canvas, RIGHT, DIAGONAL, BOTTOM
from whyteboard.test.fakewidgets.core import Bitmap, Event, Colour, PySimpleApp

It may be worth noting that the fakewidgets package does some trickery into make my program think it’s using wxPython classes, even though they’re mocks.
This is from a module that’s imported by whyteboard.test.fakewidgets’ __init__

class Window(object):
    def __init__(self, parent, *args, **kwds):
        self.parent = parent
        self.Enabled = True
        self.calls = []
        self.size = (0, 0)
        self.captured = False

    def GetClientSizeTuple(self):
        return (0, 0)
        self.captured = True

    def GetId(self):
        pass

    def Fit(self):
        pass

    def SetFocus(self):
        pass

    def PrepareDC(self, dc):
        pass

    def Destroy(self):
        pass

...


class ScrolledWindow(Window):
    def SetVirtualSize(self, *size):
        pass

    def SetVirtualSizeHints(self, *size):
        pass

import wx
wx.__dict__.update(locals())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:50:21+00:00Added an answer on May 16, 2026 at 3:50 pm

    when you import whyteboard.test, does that automatically run whyteboard.test.fakewidgets.core? I think the problem is that Canvas is being created before the mocking code runs. This explains the switchup.

    >>> import wx
    >>> class Test1(wx.Window):
    ...    pass
    ... 
    >>> wx.Window = object
    >>> class Test2(wx.Window):
    ...    pass
    ... 
    >>> dir(Test1)[:10]
    ['AcceleratorTable', 'AcceptsFocus', 'AcceptsFocusFromKeyboard', 
     'AddChild', 'AddPendingEvent', 'AdjustForLayoutDirection', 
     'AssociateHandle', 'AutoLayout', 'BackgroundColour', 'BackgroundStyle']
    >>> dir(Test2)[:10]
    ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', 
     '__getattribute__', '__hash__', '__init__', '__module__', '__new__']
    

    In the old file that you posted, fakewidgets was imported before canvas.

    If that doesn’t work, place this code directly after import wx before any other imports:

    import inspect
    
    class DummyMeta(type):
        def __new__(meta, clsname, bases, clsdict):
            if clsname == 'Canvas':
                lineno = inspect.stack()[1][2]
                print "creating Canvas with mro: {0}".format(inspect.getmro(bases[0]))
                print "file:{0}:{1}".format(__file__, lineno)
            return super(DummyMeta, meta).__new__(meta, clsname, bases, clsdict)
    
    class ScrolledWindowDummy(wx.Window):
        __metaclass__ = DummyMeta
    
    wx.ScrolledWindow = ScrolledWindowDummy
    

    This will show that a Canvas class is being created before mocking is in place and will give you the file and line number where this occurs. essentially, for MRO, you shouldn’t see anything from wx. If I am wrong, then you wont see anything at all because you will have replaced the ScrolledWindowDummy with a class that doesn’t have type DummyMeta before any class named ‘Canvas’ is created.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.