-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgo_to_line_dialog.py
55 lines (44 loc) · 1.73 KB
/
go_to_line_dialog.py
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
import wx
from dialogs import dialogs
from dialog_util import bind_escape_key
class GoToLineDialog(wx.Dialog):
def __init__(self, parent, filename="", line="", details=None):
title = "Go To Line"
if filename:
title += " [%s]" % filename
wx.Dialog.__init__(self, parent, title=title)
self.text = wx.TextCtrl(self, value=str(line), size=(100, -1))
self.text.SetFocus()
flags = wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTRE_VERTICAL
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.text, 0, flags | wx.LEFT, 5)
btn_ok = wx.Button(self, wx.ID_OK)
btn_ok.SetDefault()
sizer.Add(btn_ok, 0, flags, 5)
self.SetSizer(sizer)
self.Fit()
# Position in bottom-right corner
pos = parent.Parent.ClientToScreen(parent.Position)
self.SetPosition((
pos.x + (parent.Size.width - self.Size.width) - 20,
pos.y + (parent.Size.height - self.Size.height) - 20))
self.Bind(wx.EVT_BUTTON, self.OnOK, id=wx.ID_OK)
self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateOK, id=wx.ID_OK)
self.text.Bind(wx.EVT_CHAR, self.OnTextChar)
bind_escape_key(self)
def OnOK(self, evt):
if self.GetLineNumber() is not None:
evt.Skip()
def OnUpdateOK(self, evt):
evt.Enable(self.GetLineNumber() is not None)
def OnTextChar(self, evt):
key = evt.GetKeyCode()
if ord('0') <= key <= ord('9') or key < ord(' ') or key >= 0x7F:
evt.Skip()
def GetLineNumber(self):
try:
linenum = int(self.text.GetValue())
if linenum >= 0:
return max(linenum - 1, 0)
except ValueError:
pass