Oct-10-2017, 03:36 AM
Thank-you folks, I went with the buffered paint DC and everything is smooth and solid.
Just guessing what was going wrong...
A) repainting an image every second and making a new dc probably jammed up the garbage collector ?
B) maybe the system tried to paint the image while it was being redrawn ?
Still a learning project in progress.....
Just guessing what was going wrong...
A) repainting an image every second and making a new dc probably jammed up the garbage collector ?
B) maybe the system tried to paint the image while it was being redrawn ?
Still a learning project in progress.....
###ClockProps.py # -*- coding: utf-8 -*- import wx import DClockPane # may not need to import BackgroundColor=wx.BLACK TextColor=wx.CYAN Draw_Frame=True #False frame=wx.Rect(0,0,0,0) frame_color=wx.GREEN FontSize=100 FontFamily=wx.FONTFAMILY_DEFAULT Show_Seconds=True Show_Blink=False # annoyint, but could be useful as a flag Time_sep=':' Time_blink='.' # if Show_Blink then every half second Time_sep='.' TimeFormat_hour=24 # might never use this, but it should be an option # optional 'features' Shadow_Effect=True Shadow_color=wx.LIGHT_GREY Shadow_x=3 Shadow_y=3
### DClockPane # -*- coding: utf-8 -*- import wx import time import ClockProps def fix(n): N=repr(n) if n<10: N="0"+N return N def ts(c=':'): b=" " t=time.localtime() h=fix(t[3]) m=fix(t[4]) s=fix(t[5]) return b+h+c+m+c+s+b class DClockPane(wx.Window): def __init__(self, p): super(DClockPane, self).__init__(p) font=self.GetFont() font.SetPointSize(ClockProps.FontSize) self.SetFont(font) self.SetBackgroundColour(ClockProps.BackgroundColor) w,h=self.textSize(font) print ("text size="+ repr([w,h] )) self.SetSize(wx.Size(w,h)) self.drawFrame=ClockProps.Draw_Frame self.Box=None if self.drawFrame: ClockProps.frame=wx.Rect(0,0,w,h) self.Box=ClockProps.frame self.showSecs=ClockProps.Show_Seconds self.textColor=ClockProps.TextColor self.BLINK=ClockProps.Time_blink self.DELAY=1000 if self.BLINK: self.DELAY=500 self.TOCK=False self.SHADOW=ClockProps.Shadow_Effect self.Bind(wx.EVT_PAINT, self.OnPaint) self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER,self.run,self.timer ) self.timer.Start(self.DELAY) def draw(self, dc): dc.SetBackground(wx.Brush(self.GetBackgroundColour())) dc.Clear() #dc.SetFont(wx.Font(30, wx.SWISS, wx.NORMAL, wx.NORMAL)) c=':' if self.BLINK: self.TOCK= not self.TOCK if self.TOCK: c='.' st=ts(c) tw, th = dc.GetTextExtent(st) w,h =self.GetSize() x=(w-tw)/2 y=(h-th)/2 if self.drawFrame: dc.SetPen(wx.Pen( ClockProps.frame_color )) dc.DrawRectanglePointSize( wx.Point(x,y), self.Box.GetSize()) if self.SHADOW: dc.SetTextForeground(ClockProps.Shadow_color) dc.DrawText(st, x+ClockProps.Shadow_x, y+ClockProps.Shadow_y) dc.SetTextForeground(wx.CYAN) #(wx.Brush(wx.CYAN, wx.SOLID)) dc.DrawText(st, x, y) def run(self,e): dc = wx.BufferedDC(wx.ClientDC(self)) self.draw(dc) def OnPaint(self, e): """ paint the buffer """ dc = wx.BufferedPaintDC(self) self.draw(dc) def textSize(self, font): if font==None: font=self.GetFont() #z=font.GetSize() dc=wx.ClientDC(self) x,y=dc.GetTextExtent(" 88:88:88 ") return wx.Size(x,y)
#__init__.py import wx from DClockPane import DClockPane class ClockFrame(wx.Frame): def __init__(self,p): super(ClockFrame, self).__init__(None) self.SetTitle("Steve's Clock") self.clock=DClockPane(self) sizer=wx.BoxSizer(wx.VERTICAL) sizer.Add(self.clock,1,wx.EXPAND,wx.ALL) self.SetBackgroundColour(wx.CYAN) self.SetSizer(sizer) class DClock(wx.App): def __init__(self): super(DClock, self).__init__() cf=ClockFrame(None) cf.Show() if __name__=='__main__': app=DClock() app.MainLoop()