wxScheduler.py :  » Project-Management » Task-Coach » TaskCoach-1.0.3 » taskcoachlib » thirdparty » calendar » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Project Management » Task Coach 
Task Coach » TaskCoach 1.0.3 » taskcoachlib » thirdparty » calendar » wxScheduler.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from wxSchedulerCore import *
import wx.lib.scrolledpanel as scrolled


class wxScheduler( wxSchedulerCore, scrolled.ScrolledPanel ):

  def __init__( self, *args, **kwds ):
    kwds[ "style" ] = wx.TAB_TRAVERSAL|wx.FULL_REPAINT_ON_RESIZE

    super( wxScheduler, self ).__init__( *args, **kwds )

    timerId = wx.NewId()
    self._sizeTimer = wx.Timer(self, timerId)

    self._frozen = False
    self._dirty = False

    self.Bind( wx.EVT_PAINT, self.OnPaint )
    self.Bind( wx.EVT_LEFT_DOWN, self.OnClick )
    self.Bind( wx.EVT_RIGHT_DOWN, self.OnRightClick )
    self.Bind( wx.EVT_LEFT_DCLICK, self.OnDClick )
    self.Bind( wx.EVT_SIZE, self.OnSize )
    self.Bind( wx.EVT_TIMER, self.OnSizeTimer, id=timerId )

    self.SetScrollRate(10, 10)

  # Events
  def OnClick( self, evt ):
    self._doClickControl( self._getEventCoordinates( evt ) )

  def OnRightClick( self, evt ):
    self._doRightClickControl( self._getEventCoordinates( evt ) )

  def OnDClick( self, evt ):
    self._doDClickControl( self._getEventCoordinates( evt ) )

  def OnSize( self, evt ):
    self._sizeTimer.Start(250, True)
    evt.Skip()

  def OnSizeTimer( self, evt ):
    self.InvalidateMinSize()
    self.Refresh()

  def Add( self, *args, **kwds ):
    wxSchedulerCore.Add( self, *args, **kwds )
    self._controlBindSchedules()
    
  def Refresh(self):
    if self._frozen:
      self._dirty = True
    else:
      self.DrawBuffer()
      self.GetSizer().FitInside(self)
      super(wxScheduler, self).Refresh()
      self._dirty = False

  def Freeze(self):
    self._frozen = True

  def Thaw(self):
    self._frozen = False
    if self._dirty:
      self.Refresh()

  def SetResizable( self, value ):
    """
    Call derived method and force wxDC refresh
    """
    super(wxScheduler, self).SetResizable(value)
    self.InvalidateMinSize()
    self.Refresh()

  def OnScheduleChanged( self, event ):
    if self._frozen:
      self._dirty = True
    else:
      if event.layoutNeeded:
        self.InvalidateMinSize()
        self.Refresh()
      else:
        self.RefreshSchedule(event.schedule)

  def _controlBindSchedules( self ):
    """
    Control if all the schedules into self._schedules
    have its EVT_SCHEDULE_CHANGE binded
    """
    currentSc = set( self._schedules )
    bindSc = set( self._schBind )
    
    for sc in ( currentSc - bindSc ):
      sc.Bind( EVT_SCHEDULE_CHANGE, self.OnScheduleChanged )
      self._schBind.append( sc )

  def _getEventCoordinates( self, event ):
    """ 
    Return the coordinates associated with the given mouse event.

    The coordinates have to be adjusted to allow for the current scroll
    position.
    """
    originX, originY = self.GetViewStart()
    unitX, unitY = self.GetScrollPixelsPerUnit()
    
    coords = wx.Point( 
      event.GetX() + ( originX * unitX ),
      event.GetY() + ( originY * unitY ) 
        )
    
    return coords

  def SetViewType( self, view=None ):
    super(wxScheduler, self).SetViewType(view)
    self.InvalidateMinSize()
    self.Refresh()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.