home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / lib / site-packages / cgkit / GUI / mainwin.py < prev    next >
Encoding:
Python Source  |  2007-01-11  |  4.5 KB  |  129 lines

  1. # ***** BEGIN LICENSE BLOCK *****
  2. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. #
  4. # The contents of this file are subject to the Mozilla Public License Version
  5. # 1.1 (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. # http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS IS" basis,
  10. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. # for the specific language governing rights and limitations under the
  12. # License.
  13. #
  14. # The Original Code is the Python Computer Graphics Kit.
  15. #
  16. # The Initial Developer of the Original Code is Matthias Baas.
  17. # Portions created by the Initial Developer are Copyright (C) 2004
  18. # the Initial Developer. All Rights Reserved.
  19. #
  20. # Contributor(s):
  21. #
  22. # Alternatively, the contents of this file may be used under the terms of
  23. # either the GNU General Public License Version 2 or later (the "GPL"), or
  24. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  25. # in which case the provisions of the GPL or the LGPL are applicable instead
  26. # of those above. If you wish to allow use of your version of this file only
  27. # under the terms of either the GPL or the LGPL, and not to allow others to
  28. # use your version of this file under the terms of the MPL, indicate your
  29. # decision by deleting the provisions above and replace them with the notice
  30. # and other provisions required by the GPL or the LGPL. If you do not delete
  31. # the provisions above, a recipient may use your version of this file under
  32. # the terms of any one of the MPL, the GPL or the LGPL.
  33. #
  34. # ***** END LICENSE BLOCK *****
  35. # $Id: mainwin.py,v 1.2 2006/01/27 07:52:40 mbaas Exp $
  36.  
  37. import wx
  38. import window
  39. #from cgkit import getApp
  40. from menu import *
  41. from panels import Panels, LayoutNode, PanelNode, PanelWidget, HORIZONTAL, VERTICAL
  42. from toolbars import ToolBarPalette
  43.  
  44. # MainWin
  45. class MainWindow(window.Window):
  46.     def __init__(self):
  47.         window.Window.__init__(self)
  48.  
  49.         # Create menu
  50.         file = Menu("&File", name="file", items=
  51.                     [("&New"),
  52.                      ("&Open..."),
  53.                      ("&Save"),
  54.                      ("Save &as...", None),
  55.                      ("&Close"),
  56.                      MenuItem("---",name="sep1"),
  57.                      ("&Exit", None)
  58.                      ])
  59.  
  60.         self.menu = Menu(items=[file])
  61.  
  62.  
  63.         # ToolBar palette
  64.         self.toolbars = ToolBarPalette(self.wx, self._menu_id_manager)
  65.  
  66.         # Create panels
  67.         self.panels = Panels(self.wx)
  68.         self.panels.layout = PanelNode(name="Dummy")
  69.  
  70.  
  71.         self.mainlayout = wx.BoxSizer(wx.VERTICAL)
  72.         self.mainlayout.AddSizer(self.toolbars.sizer, 0, wx.EXPAND, 0)
  73.         self.mainlayout.Add(self.panels.wx, 1, wx.EXPAND, 0)
  74.         self.wx.SetSizer(self.mainlayout)
  75.  
  76.  
  77. #        views = LayoutNode(splittertype=VERTICAL, name="splitter1")
  78.  
  79. #        self.btn = wx.Button(parent, -1, "Button", wx.Point(0,0))
  80. #        front = PanelNode(name="front", activatable=True,
  81. #                          widget=PanelWidget(wx=self.btn))
  82.  
  83. #        dict = globals()
  84. #        dict["app"]=getApp()
  85. #        self.shell = wx.py.shell.Shell(parent, -1, locals=dict)
  86. #        shell = PanelNode(name="shell", widget=PanelWidget(wx=self.shell))
  87.         
  88. #        views.setChildren((front, shell))
  89. #        self.panels.layout = views
  90. #        front.makeCurrent()
  91.  
  92. #        self.panels.updateLayout()
  93.  
  94.         if "mainwin.geometry" in getApp().prefs:
  95.             x,y,w,h = getApp().prefs["mainwin.geometry"]
  96.             print "set",x,y,w,h
  97.             self.SetDimensions(x,y,w,h)
  98.             if getApp().prefs["mainwin.maximized"]:
  99.                 self.Maximize(True)
  100.            
  101.         wx.EVT_SIZE(self, self.onResize)
  102.         wx.EVT_MOVE(self, self.onMove)
  103.         return
  104.  
  105.     def onMove(self, event):
  106.         app = getApp()
  107.         if "mainwin.geometry" in app.prefs:
  108.             x,y,w,h = app.prefs["mainwin.geometry"]
  109.         else:
  110.             w,h = self.GetSizeTuple()
  111.         x,y = self.GetPosition()
  112.         if not self.IsMaximized():
  113.             app.prefs["mainwin.geometry"] = [x,y,w,h]
  114.  
  115.     def onResize(self, event):
  116.         app = getApp()
  117.         if "mainwin.geometry" in app.prefs:
  118.             x,y,w,h = app.prefs["mainwin.geometry"]
  119.         else:
  120.             x,y = self.GetPositionTuple()
  121.         w,h = self.GetSize()
  122.         if self.IsMaximized():
  123.             app.prefs["mainwin.maximized"] = True
  124.         else:
  125.             app.prefs["mainwin.maximized"] = False
  126.             app.prefs["mainwin.geometry"] = [x,y,w,h]
  127.         event.Skip()
  128.  
  129.