Viewer.py
changeset 667 baab9eb5b8ad
parent 666 d4bb66691248
child 669 4d02a5f4e766
equal deleted inserted replaced
666:d4bb66691248 667:baab9eb5b8ad
    21 #You should have received a copy of the GNU General Public
    21 #You should have received a copy of the GNU General Public
    22 #License along with this library; if not, write to the Free Software
    22 #License along with this library; if not, write to the Free Software
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24 
    24 
    25 import math
    25 import math
       
    26 import time
    26 from types import TupleType
    27 from types import TupleType
    27 from threading import Lock
    28 from threading import Lock
    28 
    29 
    29 import wx
    30 import wx
    30 
    31 
   540         self.TagName = tagname
   541         self.TagName = tagname
   541         self.Highlights = []
   542         self.Highlights = []
   542         self.InstancePath = instancepath
   543         self.InstancePath = instancepath
   543         self.StartMousePos = None
   544         self.StartMousePos = None
   544         self.StartScreenPos = None
   545         self.StartScreenPos = None
       
   546         self.Buffering = False
   545         
   547         
   546         # Initialize Cursors
   548         # Initialize Cursors
   547         ResetCursors()
   549         ResetCursors()
   548         self.CurrentCursor = 0
   550         self.CurrentCursor = 0
   549         
   551         
   879         return self.ParentWindow.GetDrawingMode()
   881         return self.ParentWindow.GetDrawingMode()
   880     
   882     
   881     # Buffer the last model state
   883     # Buffer the last model state
   882     def RefreshBuffer(self):
   884     def RefreshBuffer(self):
   883         self.Controler.BufferProject()
   885         self.Controler.BufferProject()
   884         self.ParentWindow.RefreshTitle()
   886         if self.ParentWindow:
   885         self.ParentWindow.RefreshFileMenu()
   887             self.ParentWindow.RefreshTitle()
   886         self.ParentWindow.RefreshEditMenu()
   888             self.ParentWindow.RefreshFileMenu()
       
   889             self.ParentWindow.RefreshEditMenu()
       
   890     
       
   891     def StartBuffering(self):
       
   892         if not self.Buffering:
       
   893             self.Buffering = True
       
   894             self.Controler.StartBuffering()
       
   895             if self.ParentWindow:
       
   896                 self.ParentWindow.RefreshTitle()
       
   897                 self.ParentWindow.RefreshFileMenu()
       
   898                 self.ParentWindow.RefreshEditMenu()
       
   899     
       
   900     def ResetBuffer(self):
       
   901         if self.Buffering:
       
   902             self.Controler.EndBuffering()
       
   903             self.Buffering = False
   887     
   904     
   888     def GetBufferState(self):
   905     def GetBufferState(self):
   889         if not self.Debug:
   906         if not self.Debug:
   890             return self.Controler.GetBufferState()
   907             return self.Controler.GetBufferState()
   891         return False, False
   908         return False, False
   974         self.Inhibit(True)
   991         self.Inhibit(True)
   975         self.current_id = 0
   992         self.current_id = 0
   976         # Start by reseting Viewer
   993         # Start by reseting Viewer
   977         self.Flush()
   994         self.Flush()
   978         self.ResetView()
   995         self.ResetView()
       
   996         self.ResetBuffer()
   979         instance = {}
   997         instance = {}
   980         # List of ids of already loaded blocks
   998         # List of ids of already loaded blocks
   981         ids = []
   999         ids = []
   982         # Load Blocks until they are all loaded
  1000         # Load Blocks until they are all loaded
   983         while instance is not None:
  1001         while instance is not None:
  1437 #                          Mouse event functions
  1455 #                          Mouse event functions
  1438 #-------------------------------------------------------------------------------
  1456 #-------------------------------------------------------------------------------
  1439 
  1457 
  1440     def OnViewerMouseEvent(self, event):
  1458     def OnViewerMouseEvent(self, event):
  1441         if not event.Entering():
  1459         if not event.Entering():
       
  1460             self.ResetBuffer()
  1442             element = None
  1461             element = None
  1443             if not event.Leaving() and not event.LeftUp() and not event.LeftDClick():
  1462             if not event.Leaving() and not event.LeftUp() and not event.LeftDClick():
  1444                 element = self.FindElement(event, True, False)
  1463                 element = self.FindElement(event, True, False)
  1445             if self.ToolTipElement is not None:
  1464             if self.ToolTipElement is not None:
  1446                 self.ToolTipElement.ClearToolTip()
  1465                 self.ToolTipElement.ClearToolTip()
  1806 
  1825 
  1807 #-------------------------------------------------------------------------------
  1826 #-------------------------------------------------------------------------------
  1808 #                          Keyboard event functions
  1827 #                          Keyboard event functions
  1809 #-------------------------------------------------------------------------------
  1828 #-------------------------------------------------------------------------------
  1810 
  1829 
       
  1830     ARROW_KEY_MOVE = {
       
  1831         wx.WXK_LEFT: (-1, 0),
       
  1832         wx.WXK_RIGHT: (1, 0),
       
  1833         wx.WXK_UP: (0, -1),
       
  1834         wx.WXK_DOWN: (0, 1),
       
  1835     }
       
  1836 
  1811     def OnChar(self, event):
  1837     def OnChar(self, event):
  1812         xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
  1838         xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
  1813         xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
  1839         xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
  1814         ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
  1840         ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
  1815         keycode = event.GetKeyCode()
  1841         keycode = event.GetKeyCode()
  1825             self.RefreshScrollBars()
  1851             self.RefreshScrollBars()
  1826             wx.CallAfter(self.SetCurrentCursor, 0)
  1852             wx.CallAfter(self.SetCurrentCursor, 0)
  1827             self.RefreshRect(self.GetScrolledRect(rect), False)
  1853             self.RefreshRect(self.GetScrolledRect(rect), False)
  1828         elif not self.Debug and keycode == wx.WXK_RETURN and self.SelectedElement is not None:
  1854         elif not self.Debug and keycode == wx.WXK_RETURN and self.SelectedElement is not None:
  1829             self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
  1855             self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
  1830         elif keycode == wx.WXK_LEFT:
  1856         elif self.ARROW_KEY_MOVE.has_key(keycode):
       
  1857             move = self.ARROW_KEY_MOVE[keycode]
  1831             if event.ControlDown() and event.ShiftDown():
  1858             if event.ControlDown() and event.ShiftDown():
  1832                 self.Scroll(0, ypos)
  1859                 self.Scroll({-1: 0, 0: xpos, 1: xmax}[move[0]],
       
  1860                             {-1: 0, 0: ypos, 1: ymax}[move[1]])
  1833                 self.RefreshVisibleElements()
  1861                 self.RefreshVisibleElements()
  1834             elif event.ControlDown():
  1862             elif event.ControlDown():
  1835                 self.Scroll(xpos - 1, ypos)
  1863                 self.Scroll(xpos + move[0], ypos + move[1])
  1836                 self.RefreshScrollBars()
  1864                 self.RefreshScrollBars()
  1837                 self.RefreshVisibleElements()
  1865                 self.RefreshVisibleElements()
  1838             elif not self.Debug and self.SelectedElement is not None:
  1866             elif not self.Debug and self.SelectedElement is not None:
  1839                 self.SelectedElement.Move(-scaling[0], 0)
  1867                 movex, movey = move
       
  1868                 if not event.AltDown() or event.ShiftDown():
       
  1869                     movex *= scaling[0]
       
  1870                     movey *= scaling[1] 
       
  1871                     if event.ShiftDown() and not event.AltDown():
       
  1872                         movex *= 10
       
  1873                         movey *= 10
       
  1874                 self.SelectedElement.Move(movex, movey)
       
  1875                 self.StartBuffering()
  1840                 self.SelectedElement.RefreshModel()
  1876                 self.SelectedElement.RefreshModel()
  1841                 self.RefreshBuffer()
       
  1842                 self.RefreshScrollBars()
  1877                 self.RefreshScrollBars()
  1843                 self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False)
  1878                 self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
  1844         elif keycode == wx.WXK_RIGHT:
       
  1845             if event.ControlDown() and event.ShiftDown():
       
  1846                 self.Scroll(xmax, ypos)
       
  1847                 self.RefreshVisibleElements()
       
  1848             elif event.ControlDown():
       
  1849                 self.RefreshScrollBars(width_incr=max(0, xpos + 1 - xmax))
       
  1850                 self.Scroll(xpos + 1, ypos)
       
  1851                 self.RefreshVisibleElements()
       
  1852             elif not self.Debug and self.SelectedElement is not None:
       
  1853                 self.SelectedElement.Move(scaling[0], 0)
       
  1854                 self.SelectedElement.RefreshModel()
       
  1855                 self.RefreshBuffer()
       
  1856                 self.RefreshScrollBars()
       
  1857                 self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False)
       
  1858         elif keycode == wx.WXK_UP:
       
  1859             if event.ControlDown() and event.ShiftDown():
       
  1860                 self.Scroll(xpos, 0)
       
  1861                 self.RefreshVisibleElements()
       
  1862             elif event.ControlDown():
       
  1863                 self.Scroll(xpos, ypos - 1)
       
  1864                 self.RefreshScrollBars()
       
  1865                 self.RefreshVisibleElements()
       
  1866             elif not self.Debug and self.SelectedElement is not None:
       
  1867                 self.SelectedElement.Move(0, -scaling[1])
       
  1868                 self.SelectedElement.RefreshModel()
       
  1869                 self.RefreshBuffer()
       
  1870                 self.RefreshScrollBars()
       
  1871                 self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False)
       
  1872         elif keycode == wx.WXK_DOWN:
       
  1873             if event.ControlDown() and event.ShiftDown():
       
  1874                 self.Scroll(xpos, ymax)
       
  1875                 self.RefreshVisibleElements()
       
  1876             elif event.ControlDown():
       
  1877                 self.RefreshScrollBars(height_incr=max(0, ypos + 1 - ymax))
       
  1878                 self.Scroll(xpos, ypos + 1)
       
  1879                 self.RefreshVisibleElements()
       
  1880             elif not self.Debug and self.SelectedElement is not None:
       
  1881                 self.SelectedElement.Move(0, scaling[1])
       
  1882                 self.SelectedElement.RefreshModel()
       
  1883                 self.RefreshBuffer()
       
  1884                 self.RefreshScrollBars()
       
  1885                 self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False)
       
  1886         elif not self.Debug and keycode == wx.WXK_SPACE and self.SelectedElement is not None and self.SelectedElement.Dragging:
  1879         elif not self.Debug and keycode == wx.WXK_SPACE and self.SelectedElement is not None and self.SelectedElement.Dragging:
  1887             if self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement):
  1880             if self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement):
  1888                 block = self.CopyBlock(self.SelectedElement, wx.Point(*self.SelectedElement.GetPosition()))
  1881                 block = self.CopyBlock(self.SelectedElement, wx.Point(*self.SelectedElement.GetPosition()))
  1889                 event = wx.MouseEvent()
  1882                 event = wx.MouseEvent()
  1890                 event.m_x, event.m_y = self.Editor.ScreenToClient(wx.GetMousePosition())
  1883                 event.m_x, event.m_y = self.Editor.ScreenToClient(wx.GetMousePosition())