]> git.saurik.com Git - wxWidgets.git/blob - wxPython/misc/wxprojview.py
fixing 'id' objc.h collisions
[wxWidgets.git] / wxPython / misc / wxprojview.py
1 #!/usr/bin/env python
2 #----------------------------------------------------------------------
3 #
4 # A little app I use on my system to help me remember which version of
5 # wx I am corrently working on. I don't expect this to work for anybody
6 # else as it uses things that are specific to my setup.
7 #
8 #----------------------------------------------------------------------
9
10 import wx
11 import wx.lib.stattext as st
12 import os
13 import sys
14
15 class MyFrame(wx.Frame):
16 def __init__(self, style=0):
17 wx.Frame.__init__(self, None, title="wx Active Project",
18 style=wx.FRAME_NO_TASKBAR | style
19 ,name="wxprojview"
20 )
21 p = wx.Panel(self)
22
23 p.SetBackgroundColour("sky blue")
24 self.label = st.GenStaticText(p, -1, "wx XXX")
25 self.label.SetBackgroundColour("sky blue")
26 self.label.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
27 sizer = wx.BoxSizer(wx.VERTICAL)
28 sizer.Add(self.label, 1, wx.ALIGN_CENTER|wx.ALL, 2)
29 p.SetSizerAndFit(sizer)
30 self.SetClientSize(p.GetSize())
31
32 for obj in [p, self.label]:
33 obj.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
34 obj.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
35 obj.Bind(wx.EVT_MOTION, self.OnMouseMove)
36 obj.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
37
38 cfg = wx.Config.Get()
39 cfg.SetPath("/")
40 if cfg.Exists("Pos"):
41 pos = eval(cfg.Read("Pos"))
42 # TODO: ensure this position is on-screen
43 self.SetPosition(pos)
44
45 self.Bind(wx.EVT_CLOSE, self.OnClose)
46 self.Bind(wx.EVT_TIMER, self.OnUpdateVersion)
47 self.timer = wx.Timer(self)
48 self.timer.Start(5000)
49 self.OnUpdateVersion(None)
50
51
52 def OnUpdateVersion(self, evt):
53 ver = '?.?'
54 if 'wxMSW' in wx.PlatformInfo:
55 info = open("c:/wxcurenv").read()
56 p1 = info.find("WXCUR=") + 6
57 p2 = info.find("\n", p1)
58 ver = info[p1:p2]
59 else:
60 link = '/opt/wx/current'
61 if os.path.islink(link):
62 rp = os.path.realpath(link)
63 ver = os.path.split(rp)[1]
64 label = 'wx %s' % ver
65 if label != self.label.GetLabel():
66 self.label.SetLabel(label)
67 self.label.GetContainingSizer().Layout()
68
69
70 def OnClose(self, evt):
71 cfg = wx.Config.Get()
72 cfg.SetPath("/")
73 cfg.Write("Pos", str(self.GetPosition().Get()))
74 self.timer.Stop()
75 evt.Skip()
76
77
78
79 def OnLeftDown(self, evt):
80 win = evt.GetEventObject()
81 win.CaptureMouse()
82 self.capture = win
83 pos = win.ClientToScreen(evt.GetPosition())
84 origin = self.GetPosition()
85 dx = pos.x - origin.x
86 dy = pos.y - origin.y
87 self.delta = wx.Point(dx, dy)
88
89 def OnLeftUp(self, evt):
90 if self.capture.HasCapture():
91 self.capture.ReleaseMouse()
92
93 def OnMouseMove(self, evt):
94 if evt.Dragging() and evt.LeftIsDown():
95 win = evt.GetEventObject()
96 pos = win.ClientToScreen(evt.GetPosition())
97 fp = (pos.x - self.delta.x, pos.y - self.delta.y)
98 self.Move(fp)
99
100 def OnRightUp(self, evt):
101 self.Close()
102
103
104
105 app = wx.PySimpleApp()
106 app.SetAppName("wxprojview")
107 app.SetVendorName("Robin Dunn")
108 style = wx.STAY_ON_TOP
109 if len(sys.argv) > 1 and sys.argv[1] == 'nostayontop':
110 style=0
111 frm = MyFrame(style)
112 frm.Show()
113 app.MainLoop()