Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

65 linhas
2.3 KiB

  1. import wx
  2. from ..data import Position
  3. from ..i18n import _
  4. class PositionWindow(wx.Dialog):
  5. position: Position
  6. def __init__(self, parent, position: Position = None):
  7. super(PositionWindow, self).__init__(parent, title=_('Set position'), style=wx.DEFAULT_DIALOG_STYLE ^ wx.CLOSE_BOX)
  8. self.position = position
  9. latitude_lbl = wx.StaticText(self, label=_('Latitude:'))
  10. self._latitude_input = wx.SpinCtrlDouble(self, initial=position.latitude if position is not None else 0,
  11. min=-90, max=90)
  12. self._latitude_input.SetDigits(4)
  13. longitude_lbl = wx.StaticText(self, label=_('Longitude:'))
  14. self._longitude_input = wx.SpinCtrlDouble(self, initial=position.longitude if position is not None else 0,
  15. min=-180, max=180)
  16. self._longitude_input.SetDigits(4)
  17. ok_button = wx.Button(self, label=_('OK'))
  18. cancel_button = wx.Button(self, label=_('Cancel'))
  19. self.Bind(wx.EVT_BUTTON, self.on_ok, ok_button)
  20. self.Bind(wx.EVT_BUTTON, self.on_cancel, cancel_button)
  21. btn_sizer = wx.GridSizer(1, 2, 5, 5)
  22. btn_sizer.AddMany([(ok_button, 0, wx.EXPAND),
  23. (cancel_button, 0, wx.EXPAND)])
  24. sizer = wx.FlexGridSizer(2, 5, 5)
  25. sizer.AddGrowableCol(0, 2)
  26. sizer.AddMany([(latitude_lbl, 0, wx.EXPAND | wx.ALL, 5),
  27. (self._latitude_input, 0, wx.EXPAND | wx.ALL, 5),
  28. (longitude_lbl, 0, wx.EXPAND | wx.ALL, 5),
  29. (self._longitude_input, 0, wx.EXPAND | wx.ALL, 5),
  30. (wx.StaticText(self), 0, wx.EXPAND | wx.ALL, 5),
  31. (btn_sizer, 0, wx.EXPAND | wx.ALL, 5)])
  32. self.SetSizer(sizer)
  33. self.Fit()
  34. self.Center()
  35. self.Bind(wx.EVT_CHAR_HOOK, self.on_key_down)
  36. def on_cancel(self, _=None):
  37. self.Close()
  38. def on_ok(self, _=None):
  39. self.position = Position(self._latitude_input.GetValue(), self._longitude_input.GetValue())
  40. self.Close()
  41. def on_key_down(self, event):
  42. key = event.GetKeyCode()
  43. if key == wx.WXK_ESCAPE:
  44. self.on_cancel()
  45. elif key in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]:
  46. self.on_ok()
  47. else:
  48. event.Skip()