#!/usr/bin/env python

"""
simple check of wxDC memory use:

Came about because a floatCanvs user discovered that memory use grew when
calling _draw with a Scaled TextBox cuased memory use to grow.

It appears to be a leak in DC.DrawTextList -- this is a test of that. 
"""

import random
import wx
import numpy as np

print(wx.version())


app = wx.App(False)
frame_1 = wx.Frame(None, wx.ID_ANY, "Test Frame", size=(500,500))


words = ['More', 'than', 'one', 'word']
positions = [(10,50), (60,80), (110,110), (160,140)]


def on_paint(evt):
    # print "on_paint called"
    dc = wx.PaintDC(frame_1)

    dc.Clear()

    dc.SetFont(wx.Font(40, wx.ROMAN, wx.NORMAL, wx.NORMAL))
    dc.SetTextForeground(wx.Colour(255, 0, 0))
    dc.SetBackgroundMode(wx.TRANSPARENT)
#    dc.DrawTextPoint("some text", (50,100))
    for i in range(100):
        positions = np.random.randint(0, 400, ( len(words), 2) )
        dc.DrawTextList( words, positions)
        #dc.DrawTextList( words, positions.tolist() )



frame_1.Bind(wx.EVT_PAINT, on_paint)  # call the on_timer function

frame_1.Show()

i = [-1]
def on_timer(evt):
    i[0] = i[0] + 1
    if i[0] % 100 == 0:
        print("{0} iterations".format(i[0]))
    frame_1.Refresh()
    frame_1.Update()

timer = wx.Timer(frame_1)
frame_1.Bind(wx.EVT_TIMER, on_timer, timer)  # call the on_timer function

timer.Start(1)  # x100 milliseconds

app.MainLoop()

