File: demo02.py

package info (click to toggle)
python-wpy 0.53-0.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 832 kB
  • ctags: 1,991
  • sloc: python: 8,624; makefile: 57; sh: 24
file content (59 lines) | stat: -rwxr-xr-x 1,937 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/local/bin/python
# This program will run unchanged on any system which has a "wpy.py".

from wpy import *

class my_frame(CFrameWnd):
  def __init__(self):
    CFrameWnd.__init__(self)
    self.wpySizeX = self.wpyScreenSizeX / 2
    self.wpySizeY = self.wpyScreenSizeY / 2

class my_view(CScrollView):
  t1 = "Please press OK again to change the size of the window."
  t2 = "Please press OK to change the size of the window."
  t3 = "  Try changing the size with the window decorations too."
  def OnCreate(self, event):
    self.button1 = CPushButton(self, "OK")
    self.button2 = CPushButton(self, "Quit")
    self.WpyMakeEqualSize(self.button1, self.button2)
    self.button1.Create()
    self.button2.Create()
    self.msg = CMessage(self, self.t2 + self.t3)
    self.msg.Create()
    self.toggle = 0
  def make_msg(self):	# Toggle message text.
    if self.toggle:
      self.msg.SetWindowText(self.t1)
    else:
      self.msg.SetWindowText(self.t2 + self.t3)
  def OnSize(self, rect):
    self.button1.WpyPlace(rect, 0.3333, 0.70, "center")
    self.button2.WpyPlace(rect, 0.6667, 0.70, "center")
    self.msg.WpyPlace(rect, 0.5, 0.1, "n")
  def OnButtonOK(self, control):
# An "OK" button: Toggles between two window sizes.
    frame = self.wpyParent
    rect = frame.GetWindowRect()
    frame.wpySizeY = rect.wpySizeY	# Keep same Y size
    msg_size = self.msg.wpySizeX
    if self.toggle:
      self.toggle = 0
      frame.wpySizeX = msg_size * 1.5	# Change X size
    else:
      self.toggle = 1
      frame.wpySizeX = msg_size * 2
    self.make_msg()			# Change message
    frame.MoveWindowSize()
    
class MyApp(CWinApp):
  def InitInstance(self):
    templ = CSingleDocTemplate(CDocument, my_frame, my_view)
    templ.wpyText = "Usual Hello World Demo"
    self.AddDocTemplate(templ)
    self.FileNew()
  def OnButtonQuit(self, control):
    self.Exit()

# Start the application, respond to events.
app = MyApp()