Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SaveAsOziWaypointFileDialog(wx.Dialog):
- def __init__(self, parent, document, path):
- wx.Dialog.__init__(self, parent, -1, 'Save as Ozi waypoint file',
- style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
- self.document = document
- self.path = path
- self.initialize_ui()
- # Increase the width of the dialog and centre it on the screen.
- self.SetSizeWH(600, -1)
- self.CenterOnScreen()
- self.Bind(wx.EVT_BUTTON, self.on_button)
- self.Bind(wx.EVT_RADIOBUTTON, self.on_radio_button)
- def _column_picker_row(self, parent, grid, row_index, label):
- # The label.
- grid.Add(
- wx.StaticText(parent, -1, label), (row_index, 0),
- (1, 1), wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL
- )
- # The text control.
- tc = wx.TextCtrl(parent, -1)
- tc.Font = wx.Font(*const.FONT_FIXEDWIDTH)
- grid.Add(
- tc, (row_index, 1), (1, 1),
- wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND
- )
- # The "add column" button.
- add_btn = wx.Button(parent, -1, '+', style=wx.BU_EXACTFIT)
- self.Bind(
- wx.EVT_BUTTON, partial(self.on_add_to_tc, tc), source=add_btn
- )
- grid.Add(add_btn, (row_index, 2), (1, 1), wx.ALIGN_CENTER_VERTICAL)
- # Tie the add button to the text control for future use.
- tc.add_column_button = add_btn
- return tc
- def initialize_ui(self):
- # Create a main sizer to get padding from the edges of the window, and
- # create a layout sizer inside it for positioning controls.
- main_sizer = wx.BoxSizer(wx.VERTICAL)
- # Add the text controls for the waypoint info.
- waypoint_info_box = wx.StaticBox(self, -1, 'Waypoint info')
- waypoint_info_box_sizer = wx.StaticBoxSizer(waypoint_info_box)
- waypoint_info_layout = wx.GridBagSizer(5, 5)
- self.tc_wpname = self._column_picker_row(
- waypoint_info_box, waypoint_info_layout, 0, 'Waypoint name'
- )
- self.tc_wpdescr = self._column_picker_row(
- waypoint_info_box, waypoint_info_layout, 1, 'Waypoint description'
- )
- waypoint_info_layout.AddGrowableCol(1)
- waypoint_info_box_sizer.Add(
- waypoint_info_layout, 1, wx.ALL | wx.EXPAND, 10
- )
- main_sizer.Add(
- waypoint_info_box_sizer, 0, flag=wx.ALL | wx.EXPAND, border=10
- )
- # Add the controls for waypoint coordinates.
- coords_box = wx.StaticBox(self, -1, 'Waypoint coordinates')
- coords_box_sizer = wx.StaticBoxSizer(coords_box,
- wx.HORIZONTAL)
- waypoint_coords_layout = wx.GridBagSizer(5, 5)
- wgs84_sizer = wx.GridBagSizer(5, 5)
- # The WGS 84 radio button.
- self.rb_wgs84 = wx.RadioButton(coords_box, -1, 'WGS 84 decimals')
- self.rb_wgs84.Value = True
- wgs84_sizer.Add(self.rb_wgs84, (0, 0), (1, 2), wx.BOTTOM, 10)
- # The column WGS 84 column pickers.
- self.tc_lat = self._column_picker_row(
- coords_box, wgs84_sizer, 1, 'Latitude'
- )
- self.tc_lng = self._column_picker_row(
- coords_box, wgs84_sizer, 2, 'Longitude'
- )
- wgs84_sizer.AddGrowableCol(1)
- # The UTM coordinate radio button and column pickers.
- utm_sizer = wx.GridBagSizer(5, 5)
- self.rb_utm = wx.RadioButton(coords_box, -1, 'UTM')
- utm_sizer.Add(self.rb_utm, (0, 0), (1, 2), wx.BOTTOM, 10)
- self.tc_utmz = self._column_picker_row(
- coords_box, utm_sizer, 1, 'Zone'
- )
- self.tc_utmx = self._column_picker_row(
- coords_box, utm_sizer, 2, 'Northing'
- )
- self.tc_utmy = self._column_picker_row(
- coords_box, utm_sizer, 3, 'Easting'
- )
- utm_sizer.AddGrowableCol(1)
- # Disable the UTM controls initially.
- for tc in [self.tc_utmz, self.tc_utmx, self.tc_utmy]:
- tc.Disable()
- tc.add_column_button.Disable()
- coords_box_sizer.Add(wgs84_sizer, 1, wx.EXPAND | wx.ALL, 10)
- coords_box_sizer.Add(utm_sizer, 1, wx.EXPAND | wx.ALL, 10)
- main_sizer.Add(coords_box_sizer, 0, wx.ALL | wx.EXPAND, border=10)
- # Add the save and cancel buttons.
- button_sizer = wx.BoxSizer(wx.HORIZONTAL)
- button_sizer.Add(wx.Button(self, wx.ID_OK, 'Save'), 0, wx.RIGHT, 5)
- button_sizer.Add(wx.Button(self, wx.ID_CANCEL, 'Cancel'), 0)
- main_sizer.AddStretchSpacer()
- main_sizer.Add(wx.StaticLine(self, -1), flag=wx.EXPAND | wx.ALL,
- border=5)
- main_sizer.Add(button_sizer, flag=wx.ALIGN_RIGHT | wx.ALL,
- border=5)
- # Set the OK button to the default button.
- self.FindWindowById(wx.ID_OK).SetDefault()
- self.SetSizerAndFit(main_sizer)
- def on_add_to_tc(self, tc, event):
- """Event handler for the small + buttons."""
- # Give the user a list of column headers to choose from.
- headers = self.document.table.column_headers
- dialog = wx.SingleChoiceDialog(
- self, 'Which column would you like to add?', 'Choose a column',
- headers, wx.CHOICEDLG_STYLE
- )
- if dialog.ShowModal() == wx.ID_OK:
- choice = dialog.StringSelection
- tc.AppendText('{{{}}}'.format(choice))
- def on_button(self, event):
- # Validate input when OK is clicked. If there are any errors, inform
- # the user and stop the dialog from closing.
- if event.Id == wx.ID_OK:
- pass
- else:
- event.Skip()
- def on_radio_button(self, event):
- source = self.FindWindowById(event.Id)
- wgs84_checked = source is self.rb_wgs84 and event.Checked()
- utm_checked = not wgs84_checked
- # Set the control states.
- for tc in [self.tc_lat, self.tc_lng]:
- tc.Enable(wgs84_checked)
- tc.add_column_button.Enable(wgs84_checked)
- for tc in [self.tc_utmz, self.tc_utmx, self.tc_utmy]:
- tc.Enable(utm_checked)
- tc.add_column_button.Enable(utm_checked)
Advertisement
Add Comment
Please, Sign In to add comment