]> git.saurik.com Git - wxWidgets.git/blob - wxPython/misc/wxprojview.py
5b002df75e18b1b242714f81553dec8e28618a46
[wxWidgets.git] / wxPython / misc / wxprojview.py
1 #!/usr/bin/env python
2
3 import wx
4 import wx.lib.stattext as st
5 import os
6
7 class MyFrame(wx.Frame):
8 def __init__(self):
9 wx.Frame.__init__(self, None, title="wx Active Project",
10 style=wx.FRAME_NO_TASKBAR|wx.STAY_ON_TOP,
11 name="wxprojview"
12 )
13 p = wx.Panel(self)#, style=wx.SIMPLE_BORDER)
14
15 p.SetBackgroundColour("sky blue")
16 self.label = st.GenStaticText(p, -1, "wx XXX")
17 self.label.SetBackgroundColour("sky blue")
18 self.label.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD))
19 sizer = wx.BoxSizer(wx.VERTICAL)
20 sizer.Add(self.label, 1, wx.ALIGN_CENTER|wx.ALL, 2)
21 p.SetSizerAndFit(sizer)
22 self.SetClientSize(p.GetSize())
23
24 for obj in [p, self.label]:
25 obj.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
26 obj.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
27 obj.Bind(wx.EVT_MOTION, self.OnMouseMove)
28 obj.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
29
30 cfg = wx.Config.Get()
31 cfg.SetPath("/")
32 if cfg.Exists("Pos"):
33 pos = eval(cfg.Read("Pos"))
34 # TODO: ensure this position is on-screen
35 self.SetPosition(pos)
36
37 self.Bind(wx.EVT_CLOSE, self.OnClose)
38 self.Bind(wx.EVT_TIMER, self.OnUpdateVersion)
39 self.timer = wx.Timer(self)
40 self.timer.Start(5000)
41 self.OnUpdateVersion(None)
42
43
44 def OnUpdateVersion(self, evt):
45 ver = '??'
46 if 'wxMSW' in wx.PlatformInfo:
47 pass
48 else:
49 link = '/opt/wx/current'
50 if os.path.islink(link):
51 rp = os.path.realpath(link)
52 ver = os.path.split(rp)[1]
53 label = 'wx %s' % ver
54 if label != self.label.GetLabel():
55 self.label.SetLabel(label)
56 self.label.GetContainingSizer().Layout()
57
58
59 def OnClose(self, evt):
60 cfg = wx.Config.Get()
61 cfg.SetPath("/")
62 cfg.Write("Pos", str(self.GetPosition().Get()))
63 self.timer.Stop()
64 evt.Skip()
65
66
67
68 def OnLeftDown(self, evt):
69 win = evt.GetEventObject()
70 win.CaptureMouse()
71 self.capture = win
72 pos = win.ClientToScreen(evt.GetPosition())
73 origin = self.GetPosition()
74 dx = pos.x - origin.x
75 dy = pos.y - origin.y
76 self.delta = wx.Point(dx, dy)
77
78 def OnLeftUp(self, evt):
79 if self.capture.HasCapture():
80 self.capture.ReleaseMouse()
81
82 def OnMouseMove(self, evt):
83 if evt.Dragging() and evt.LeftIsDown():
84 win = evt.GetEventObject()
85 pos = win.ClientToScreen(evt.GetPosition())
86 fp = (pos.x - self.delta.x, pos.y - self.delta.y)
87 self.Move(fp)
88
89 def OnRightUp(self, evt):
90 self.Close()
91
92
93
94 app = wx.PySimpleApp()
95 app.SetAppName("wxprojview")
96 app.SetVendorName("Robin Dunn")
97 frm = MyFrame()
98 frm.Show()
99 app.MainLoop()