Opened 4 years ago

Closed 3 years ago

#17293 closed defect (outdated)

GetSize() doesn't work without window

Reported by: stratodream Owned by:
Priority: blocker Milestone:
Component: AGW Version: 3.0.1
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

Debian Jessie 8.2
Python 2.7
wxPython 3.0.1

i'm trying to run the following script :

import wx
import wx.lib.agw.speedmeter as SM
from math import pi
class MyFrame(wx.Frame):

    def __init__(self, parent):

        wx.Frame.__init__(self, parent, -1, "SpeedMeter Demo")

        speed = SM.SpeedMeter(self, agwStyle=SM.SM_DRAW_HAND|SM.SM_DRAW_SECTORS|SM.SM_DRAW_MIDDLE_TEXT|SM.SM_DRAW_SECONDARY_TICKS)

        # Set The Region Of Existence Of SpeedMeter (Always In Radians!!!!)
        speed.SetAngleRange(-pi/6, 7*pi/6)

        # Create The Intervals That Will Divide Our SpeedMeter In Sectors
        intervals = range(0, 201, 20)
        speed.SetIntervals(intervals)

        # Assign The Same Colours To All Sectors (We Simulate A Car Control For Speed)
        # Usually This Is Black
        colours = [wx.BLACK]*10
        speed.SetIntervalColours(colours)

        # Assign The Ticks: Here They Are Simply The String Equivalent Of The Intervals
        ticks = [str(interval) for interval in intervals]
        speed.SetTicks(ticks)
        # Set The Ticks/Tick Markers Colour
        speed.SetTicksColour(wx.WHITE)
        # We Want To Draw 5 Secondary Ticks Between The Principal Ticks
        speed.SetNumberOfSecondaryTicks(5)

        # Set The Font For The Ticks Markers
        speed.SetTicksFont(wx.Font(7, wx.SWISS, wx.NORMAL, wx.NORMAL))

        # Set The Text In The Center Of SpeedMeter
        speed.SetMiddleText("Km/h")
        # Assign The Colour To The Center Text
        speed.SetMiddleTextColour(wx.WHITE)
        # Assign A Font To The Center Text
        speed.SetMiddleTextFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))

        # Set The Colour For The Hand Indicator
        speed.SetHandColour(wx.Colour(255, 50, 0))

        # Do Not Draw The External (Container) Arc. Drawing The External Arc May
        # Sometimes Create Uglier Controls. Try To Comment This Line And See It
        # For Yourself!
        speed.DrawExternalArc(False)

        # Set The Current Value For The SpeedMeter
        speed.SetSpeedValue(44)


# our normal wxApp-derived class, as usual

app = wx.App(0)

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()

when i run the script i named speedmeter.py i get the following output :

python speedmeter.py 
Traceback (most recent call last):
  File "speedmeter.py", line 58, in <module>
    frame = MyFrame(None)
  File "speedmeter.py", line 25, in __init__
    ticks = [str(interval) for interval in intervals]
wx._core.PyAssertionError: C++ assertion "m_window" failed at ../src/gtk/dcclient.cpp(2043) in DoGetSize(): GetSize() doesn't work without window

Have you a kind of fix or workaround to patch this bug ?

Best Regards.

Attachments (1)

speedmeter.py download (63.6 KB) - added by hansidude 4 years ago.
modified /usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by wbruhin

Works for me on Windows 8.1 with wxPython 2.9.5, what versions are you using?

comment:2 Changed 4 years ago by stratodream

The setup i listed at top of the ticket :

Debian Jessie 8.2
Python 2.7
wxPython 3.0.1

i tried also with another pc with debian and in both case also with Python 3.4 and i get the same output.

comment:3 Changed 4 years ago by wbruhin

Oops missed that.

I recall issues on Linux systems (really GTK) that the windows are created later.

See the use of "wx.EVT_WINDOW_CREATE" in e.g. https://github.com/wxWidgets/Phoenix/pull/10/files

A similar fix is in wx.lib.agw.speedmeter.py in the Phoenix branch.

comment:4 Changed 4 years ago by stratodream

When will it be fixed also in the Python-wxgtk ? I mean that available through the official repository !!!

comment:5 Changed 4 years ago by wbruhin

Sorry no idea.

comment:6 Changed 4 years ago by stratodream

I tried the wx Phoenix version of speedmeter.py and i get the following error :

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py", line 384, in OnSize
    self._Buffer = wx.Bitmap(self.Width, self.Height)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_gdi.py", line 639, in __init__
    _gdi_.Bitmap_swiginit(self,_gdi_.new_Bitmap(*args, **kwargs))
TypeError: String or Unicode type required
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py", line 341, in doSetWindowCreated
    self.OnSize(None)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py", line 384, in OnSize
    self._Buffer = wx.Bitmap(self.Width, self.Height)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_gdi.py", line 639, in __init__
    _gdi_.Bitmap_swiginit(self,_gdi_.new_Bitmap(*args, **kwargs))
TypeError: String or Unicode type required
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py", line 361, in OnPaint
    dc = wx.BufferedPaintDC(self, self._Buffer)
AttributeError: 'SpeedMeter' object has no attribute '_Buffer'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py", line 361, in OnPaint
    dc = wx.BufferedPaintDC(self, self._Buffer)
AttributeError: 'SpeedMeter' object has no attribute '_Buffer'

I would like to know if someone has a working debian environment.

Changed 4 years ago by hansidude

modified /usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/lib/agw/speedmeter.py

comment:7 Changed 3 years ago by robind

  • Resolution set to outdated
  • Status changed from new to closed

Closing old Phoenix tickets...

If this is still an issue in wxPython 4.0.0a1 then please open a new issue (or PR) at the wxPython-Phoenix project page on Github: https://github.com/wxWidgets/Phoenix

Note: See TracTickets for help on using tickets.