Hi all,
Firstly I’m new to python and wxpython and wxwidgets, have a small error and cant figure it out and the documentation is very sparse from what ihave googled, thus far.
i am working with the SpeedMeter module, python 2.8 and wxgtk 2.8, i am trying to make a gauge that has the icon in the center, when i run the demo it works when i use the code from the demo it breaks giving this error:
···
TBCC-DELL-Mobile1:~/python$ python GKPCM
Traceback (most recent call last):
File “GKPCM”, line 173, in
frame=MyFrame(None)
File “GKPCM”, line 136, in init
AIR = SM.SpeedMeter(AIRpanel, agwStyle=SM.SM_DRAW_HAND|SM.SM_DRAW_PARTIAL_SECTORS|SM.SM_DRAW_MIDDLE_ICON,bufferedstyle=SM.SM_BUFFERED_DC, pos=(0, 0), size=(240, 240))
File “/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/agw/speedmeter.py”, line 465, in init
bufferedstyle=bufferedstyle)
File “/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/agw/speedmeter.py”, line 272, in init
self.OnSize(None)
File “/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/agw/speedmeter.py”, line 323, in OnSize
self.UpdateDrawing()
File “/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/agw/speedmeter.py”, line 337, in UpdateDrawing
self.Draw(dc)
File “/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/agw/speedmeter.py”, line 972, in Draw
middleicon = self.GetMiddleIcon()
File “/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/lib/agw/speedmeter.py”, line 1500, in GetMiddleIcon
return self._middleicon
AttributeError: ‘SpeedMeter’ object has no attribute ‘_middleicon’
Can anyone tell me what i have done wrong? it wont let me attache the code so here is the code;
import wx
import os
import wx.lib.agw.speedmeter as SM
import sys
import math
import wx.gizmos as gizmos
from wx.lib.colourdb import getColourList
import wx.lib.buttons
from math import pi, sqrt
try:
dirName = os.path.dirname(os.path.abspath(file))
except:
dirName = os.path.dirname(os.path.abspath(sys.argv[0]))
bitmapDir = os.path.join(dirName, ‘bitmaps’)
sys.path.append(os.path.split(dirName)[0])
class MyFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,"test",pos=(3, 3),size=(480, 320))
SPEEDOpanel = wx.Panel(self, -1,style=wx.NO_BORDER, pos=(240, 0), size=(240, 240))
TACHpanel = wx.Panel(self, -1, pos=(0, 0), size=(240, 240))
ODOpanel = wx.Panel(self, -1, pos=(125, 200), size=(125, 30), style=wx.NO_BORDER)
AIRpanel = wx.Panel(self, -1, pos=(0, 240), size=(240, 240), style=wx.NO_BORDER)
OILpanel = wx.Panel(self, -1, pos=(120, 240), size=(80, 80), style=wx.NO_BORDER)
FUELpanel = wx.Panel(self, -1, pos=(240, 240), size=(80, 80), style=wx.NO_BORDER)
ENGpanel = wx.Panel(self, -1, pos=(360, 240), size=(80, 80), style=wx.NO_BORDER)
SPEEDOpanel.SetBackgroundColour(wx.BLACK)
TACHpanel.SetBackgroundColour(wx.BLUE)
ODOpanel.SetBackgroundColour(wx.RED)
AIRpanel.SetBackgroundColour(wx.BLUE)
OILpanel.SetBackgroundColour(wx.CYAN)
FUELpanel.SetBackgroundColour(wx.BLACK)
ENGpanel.SetBackgroundColour(wx.BLUE)
#SPEEDOMETER----------------------------------------------------------------------------------------------------------
SPEEDO = SM.SpeedMeter(SPEEDOpanel, agwStyle=SM.SM_DRAW_HAND|SM.SM_DRAW_SECTORS|SM.SM_DRAW_MIDDLE_TEXT|SM.SM_DRAW_SECONDARY_TICKS, pos=(0, 0), size=(240, 240))
# Set The Region Of Existence Of SpeedMeter
SPEEDO.SetAngleRange(-7.25, -2)
# SpeedMeter In Sectors
intervals = range(0, 260, 20)
SPEEDO.SetIntervals(intervals)
# Assign The Same Colours To All Sectors
# Usually This Is Black
colours = [wx.BLACK]*12
SPEEDO.SetIntervalColours(colours)
# Assign The Ticks
ticks = [str(interval) for interval in intervals]
SPEEDO.SetTicks(ticks)
# Set The Ticks/Tick Markers Colour
SPEEDO.SetTicksColour(wx.RED)
# We Want To Draw 5 Secondary Ticks Between The Principal Ticks
SPEEDO.SetNumberOfSecondaryTicks(10)
# Set The Font For The Ticks Markers
SPEEDO.SetTicksFont(wx.Font(7, wx.SWISS, wx.NORMAL, wx.NORMAL))
# Set The Text In The Center Of SpeedMeter
SPEEDO.SetMiddleText("MPH")
# Assign The Colour To The Center Text
SPEEDO.SetMiddleTextColour(wx.WHITE)
# Assign A Font To The Center Text
SPEEDO.SetMiddleTextFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))
# Set The Colour For The Hand Indicator
SPEEDO.SetHandColour(wx.Colour(255, 255, 0))
# Set The Colour For The Gauge Background
SPEEDO.SetSpeedBackground(wx.BLACK)
# Do Not Draw The External (CONTAINER) Arc
SPEEDO.DrawExternalArc(False)
SPEEDO.SetSpeedValue(0)
#TACHOMETER----------------------------------------------------------------------------------------------------------
TACH = SM.SpeedMeter(TACHpanel, agwStyle=SM.SM_DRAW_HAND|SM.SM_DRAW_SECTORS|SM.SM_DRAW_MIDDLE_TEXT|SM.SM_DRAW_SECONDARY_TICKS, pos=(0, 0), size=(240, 240))
# Set The Region Of Existence Of SpeedMeter
TACH.SetAngleRange(-6, -2)
# SpeedMeter In Sectors
intervals = range(0, 15, 1)
TACH.SetIntervals(intervals)
# Assign The Same Colours To All Sectors
# Usually This Is Black
colours = [wx.BLACK]*14
TACH.SetIntervalColours(colours)
# Assign The Ticks
ticks = [str(interval) for interval in intervals]
TACH.SetTicks(ticks)
# Set The Ticks/Tick Markers Colour
TACH.SetTicksColour(wx.RED)
# We Want To Draw 5 Secondary Ticks Between The Principal Ticks
TACH.SetNumberOfSecondaryTicks(1)
# Set The Font For The Ticks Markers
TACH.SetTicksFont(wx.Font(7, wx.SWISS, wx.NORMAL, wx.NORMAL))
# Set The Text In The Center Of SpeedMeter
TACH.SetMiddleText("RPM")
# Assign The Colour To The Center Text
TACH.SetMiddleTextColour(wx.WHITE)
# Assign A Font To The Center Text
TACH.SetMiddleTextFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))
# Set The Colour For The Hand Indicator
TACH.SetHandColour(wx.Colour(255, 255, 0))
# Set The Colour For The Gauge Background
TACH.SetSpeedBackground(wx.BLACK)
# Do Not Draw The External (CONTAINER) Arc
TACH.DrawExternalArc(False)
TACH.SetSpeedValue(0)
#ODOMETER--------------------------------------------------------------------------------------------------------------
DECIMAL1=wx.gizmos.LEDNumberCtrl(ODOpanel,-1, pos=wx.Point(0, 0), size=wx.Size(125, 30), style=wx.gizmos.LED_ALIGN_LEFT)
DECIMAL1.SetBackgroundColour(“BLACK”)
DECIMAL1.SetForegroundColour(“RED”)
DECIMAL1.SetValue(“192768”)
#AIRTEMP---------------------------------------------------------------------------------------------------------------
AIR = SM.SpeedMeter(AIRpanel, agwStyle=SM.SM_DRAW_HAND|SM.SM_DRAW_PARTIAL_SECTORS|SM.SM_DRAW_MIDDLE_ICON,bufferedstyle=SM.SM_BUFFERED_DC, pos=(0, 0), size=(240, 240))
# Air Temp Control
AIR.SetAngleRange(5,7.25)
intervals = range(0, 5)
AIR.SetIntervals(intervals)
colours = [wx.BLACK]*3
colours.append(wx.RED)
AIR.SetIntervalColours(colours)
ticks = ["140", "", "210", "", "280"]
AIR.SetTicks(ticks)
AIR.SetTicksColour(wx.RED)
AIR.SetHandColour(wx.Colour(255, 255, 0))
# Define The Icon We Want
icon = wx.Icon("temp.ico", wx.BITMAP_TYPE_ICO)
icon.SetWidth(16)
icon.SetHeight(16)
# Draw The Icon In The Center Of SpeedMeter
AIR.SetMiddleIcon(icon)
AIR.SetSpeedBackground(wx.WHITE)
#AIR.SetArcColour(wx.RED)
AIR.SetSpeedValue(0)
AIR.SetDirection("Reverse")
APP=wx.App(0)
frame=MyFrame(None)
APP.SetTopWindow(frame)
frame.Show()
APP.MainLoop()
All help is appreciated