#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
svg2rlg is a tool to convert from SVG to reportlab graphics.

License : BSD

version 0.3
"""
import sys
import os
import time
import glob
import tempfile

import wx

from svg2rlg import svg2rlg

#import svglib
USESVGLIB = False


class Log(wx.PyLog):
    """
    Class to send information to the statusbar.
    The statusbar text is reseted afther a delay when
    no pos is used in write method.
    """
    def __init__(self, target, pos = 0, delay = 5000):
        wx.PyLog.__init__(self)

        # Do we have a statusbar or normal controll
        self.statusbar = False
        if isinstance(target, wx.StatusBar):
            self.statusbar = True

        self.target = target
        self.pos = pos
        self.delay = delay

        # Timer to clear text
        self.timer = wx.Timer(self.target, id=1)
        wx.EVT_TIMER(self.target, self.timer.GetId(), self.clear)

    def DoLogString(self, message, timeStamp):
        # This is called with wx.LogMessage etc.
        self.Write(message)

    def Write(self, text, pos = None):
        if self.statusbar:
            # Statusbar widget
            if pos is None:
                self.target.SetStatusText(text, self.pos)

                if self.timer.IsRunning():
                    self.timer.Stop()

                self.timer.Start(self.delay, oneShot=True)

            else:
                self.target.SetStatusText(text, pos)
        else:
            # Normal controll
            self.target.SetLabel(_("Message: %s") % text)

            if self.timer.IsRunning():
                self.timer.Stop()

            self.timer.Start(self.delay, oneShot=True)

    def clear(self, event = None):
        if self.statusbar:
            # Statusbar widget
            self.target.SetStatusText("", self.pos)
        else:
            # Normal controll
            self.target.SetLabel("")

TIMEOUT = 450
SCALELIM = 10

class Image(wx.Panel):