def _on_save(self, event): """SaveNew Polygon data to a file""" # --- Initialize Save File Dialog filters = 'All files (*.*)|*|Wx Poly files (*.wxp)|*.wxp' dialog = wx.FileDialog ( None, message = 'Save Polygon Data ....', wildcard = filters, style = wx.SAVE | wx.OVERWRITE_PROMPT, defaultFile = "New Poly.wxp", defaultDir=self.path) dialog.SetFilterIndex(1) icon1 = myicon.get_icon() dialog.SetIcon(icon1) # If ok was pressed write Polygon data if dialog.ShowModal() == wx.ID_OK: selection = dialog.GetPath() # Add extension if needed if selection[-4:] != ".wxp": selection += ".wxp" # --- Open File and write data # try to catch posssible IO errors self.path = str(os.path.dirname(selection)) poly_data = str(self.poly_data.vertices) + ", " + str(self.poly_data.scale) + ", "\ + str(self.poly_data.rotation) try: file_handle = open ( selection, 'w' ) try: file_handle.write (WX_POLY + "\n" ) file_handle.write (poly_data ) finally: file_handle.close() except IOError: sys.stderr.write( "wxpoly: IO Write Error" + str( selection) +"\n") # close dialog dialog.Destroy()
def __init__(self, parent, win_id, title, poly_data): wx.Dialog.__init__(self, parent, win_id, title, size=(235, 230)) icon1 = myicon.get_icon() self.parent = parent self.SetIcon(icon1) self.poly_data = poly_data wx.StaticBox(self, -1, 'Polyon data', (5, 5), size=(240, 170)) wx.StaticText(self, -1, 'N', (30, 55)) self.sn = wx.SpinCtrl(self, -1, str(poly_data.vertices), (92, 50), (60, -1), min=config.default_dict["vert_min"], max=config.default_dict["vert_max"]) wx.StaticText(self, -1, 'radius', (30, 90)) self.sr = wx.SpinCtrl(self, -1, str(poly_data.scale), (92, 85), (60, -1), min=config.default_dict["scale_min"], max=config.default_dict["scale_max"]) wx.StaticText(self, -1, 'angle', (30, 125)) dangle = round((poly_data.rotation*180)/math.pi) self.sa = wx.SpinCtrl(self, -1, str(dangle), (92, 120), (60, -1), min=0, max=359) wx.Button(self, 1, 'Ok', (92, 185), (60, -1)) wx.Button(self, 2, 'Wicca', (10, 185), (60, -1)) wx.Button(self, 3, 'Rnd', (175, 185), (60, -1)) self.Bind(wx.EVT_BUTTON, self.on_close, id=1) self.Bind(wx.EVT_BUTTON, self.on_wicca, id=2) self.Bind(wx.EVT_BUTTON, self.on_rnd, id=3) self.Centre() self.ShowModal() self.Destroy()
def _on_open(self, event): """Load New Polygon data from a file""" # --- Initialize Open File Dialog filters = 'All files (*.*)|*|Wx Poly files (*.wxp)|*.wxp' dialog = wx.FileDialog ( None, message = 'Open something....', wildcard = filters, style = wx.OPEN | wx.MULTIPLE , defaultDir=self.path) dialog.SetFilterIndex(1) icon1 = myicon.get_icon() dialog.SetIcon(icon1) # If ok was pressed read file and set Polygon data if dialog.ShowModal() == wx.ID_OK: # --- Open File and read data into a list # try to catch posssible IO errors selection = dialog.GetPath() self.path = str(os.path.dirname(selection)) data = [] try: file_handle = open(selection, 'r') try: for line in file_handle: for val in line.split(','): data.append(val) finally: file_handle.close() except IOError: sys.stderr.write( "wxpoly: IO Read Error" + str( selection) +"\n") # --- Save Old data in case we have to restore it old_n = self.poly_data.vertices old_scale = self.poly_data.scale old_rotation = self.poly_data.rotation # --- Set Ngon data to data read from file if data[0] == WX_POLY + "\n" and len(data) == 4: try: # Try to set Ngon data to new values # Incorrect values will raise ValueError self.poly_data.__init__(int(data[1]), 180*float(data[3])/math.pi, int(data[2])) except ValueError: # Invalid data type-- restore Ngon to old values sys.stderr.write( "wxpoly: Corrupt or invalid file" + str( selection) + "\n") self.poly_data.vertices = old_n self.poly_data.scale = old_scale self.poly_data.rotation = old_rotation self. _on_file_error() else: # File was not a wxpoly data file sys.stderr.write( "wxpoly: Invalid file" + str( selection) + "\n") self. _on_file_error() # some development tests to make sure polygon data is meaningful assert (config.default_dict["vert_max"] > self.poly_data.vertices >= config.default_dict["vert_min"]) assert (config.default_dict["scale_max"] > self.poly_data.scale >= config.default_dict["scale_min"]) # close dialog dialog.Destroy() self.Refresh()
def __init__(self, parent, id_num, title, default_poly): # initialize internal data self.poly_data = default_poly.poly_data self.path = default_poly.pathname self.view = default_poly.pref self.EXPORT_FLAG = False self.selection ="" # initialize window wx.Frame.__init__(self, parent, id_num, title, size=(config.WIN_WIDTH, config.WIN_HEIGHT)) icon1 = myicon.get_icon() self.SetIcon(icon1) create_menu_bar(self) self.statusbar = self.CreateStatusBar() self.Bind(wx.EVT_LEFT_DOWN, self._on_next) self.Bind(wx.EVT_RIGHT_DOWN, self._on_prev) self.Bind(wx.EVT_CLOSE, self._on_close_window) self.Bind(wx.EVT_PAINT, self._on_paint) # display window self.Centre() self.Show(True)
def _on_export_dialog(self): """Export current Polygon as an bitmap image """ # --- Initialize Export dialog filters = 'All files (*.*)|*|Image files (*.bmp)|*.bmp' dialog = wx.FileDialog ( None, message = 'Save as bitmap....', wildcard = filters, style = wx.SAVE | wx.OVERWRITE_PROMPT , defaultFile = "poly.bmp", defaultDir=self.path) icon1 = myicon.get_icon() dialog.SetIcon(icon1) dialog.SetFilterIndex(1) # set export flag and if ok was pressed set filename and path if dialog.ShowModal() == wx.ID_OK: self.selection = dialog.GetPath() self.path = str(os.path.dirname(self.selection)) self.EXPORT_FLAG = True else : self.EXPORT_FLAG = False # close dialog dialog.Destroy()
def __init__(self, parent, win_id, title, poly_pref): wx.Dialog.__init__(self, parent, win_id, title, size=(320, 370)) icon1 = myicon.get_icon() self.parent = parent self.SetIcon(icon1) wx.StaticBox(self, -1, 'Color Preferences', (5, 5), size=(310, 310)) # ---- Center Preferences Choice control self._ink_choice = [] wx.StaticText(self, -1, 'Center', (25, 55)) self._ink_choice.append(wx.Choice( self, -1, (125, 50), choices=myresource.color_names)) # --- Vertices Preferences Choice control wx.StaticText(self, -1, 'Vertices', (25, 90)) self._ink_choice.append(wx.Choice( self, -1, (125, 85), choices=myresource.color_names)) # --- Swin_ides Preferences Choice control wx.StaticText(self, -1, 'Sides', (25, 125)) self._ink_choice.append(wx.Choice( self, -1, (125, 120), choices=myresource.color_names)) # --- Diagonals Preferences Choice control wx.StaticText(self, -1, 'Diagonals', (25, 160)) self._ink_choice.append(wx.Choice( self, -1, (125, 155), choices=myresource.color_names)) # --- Circumscribe Circle Choice control wx.StaticText(self, -1, 'Circumscribe', (25, 195)) self._ink_choice.append(wx.Choice( self, -1, (125, 190), choices=myresource.color_names)) # --- Inscribe Circle Preferences Choice control wx.StaticText(self, -1, 'Inscribe', (25, 230)) self._ink_choice.append(wx.Choice( self, -1, (125, 225), choices=myresource.color_names)) # --- Axis Preferences Choice control wx.StaticText(self, -1, 'Axis', (25, 265)) self._ink_choice.append(wx.Choice( self, -1, (125, 260), choices=myresource.color_names)) # --- Set all choice controls to current Preferences self.set_choice_ctrls() # --- Restore and Ok buttons wx.Button(self, 1, 'Ok', (130, 330), (70, -1)) wx.Button(self, 2, 'Cancel', (240, 330), (70, -1)) wx.Button(self, 3, 'Restore', (15, 330), (70, -1)) self.Bind(wx.EVT_BUTTON, self.on_close, id=1) self.Bind(wx.EVT_BUTTON, self.on_cancel, id=2) self.Bind(wx.EVT_BUTTON, self.on_restore, id=3) self.Centre() self.ShowModal() self.Destroy()
def __init__(self, parent, win_id, title, poly_list): wx.Dialog.__init__(self, parent, win_id, title, size=(235, 130)) self.parent = parent self.poly_data = poly_list[0] self.field = poly_list[1] icon1 = myicon.get_icon() self.SetIcon(icon1) if self.field == "N": wx.StaticBox(self, -1, 'Set N', (5, 5), size=(240, 80)) wx.StaticText(self, -1, 'N', (30, 40)) self.sn = wx.SpinCtrl(self, -1, str( self.poly_data.vertices ), (92, 35), (60, -1), min=config.default_dict["vert_min"], max=config.default_dict["vert_max"]) elif self.field =="Radius": wx.StaticBox(self, -1, 'Set Radius', (5, 5), size=(240, 80)) wx.StaticText(self, -1, 'Radius', (30, 40)) self.sr = wx.SpinCtrl(self, -1, str(self.poly_data.scale), (92, 35), (60, -1), min=config.default_dict["scale_min"], max=config.default_dict["scale_max"]) elif self.field == "Angle": wx.StaticBox(self, -1, 'Set Angle', (5, 5), size=(240, 80)) wx.StaticText(self, -1, 'Angle', (30, 40)) dangle = round((self.poly_data.rotation * 180)/math.pi) self.sa = wx.SpinCtrl(self, -1, str(dangle), (92, 35), (60, -1), min=0, max=359) wx.Button(self, 1, 'Ok', (92, 95), (60, -1)) wx.Button(self, 2, 'Wicca', (10, 95), (60, -1)) wx.Button(self, 3, 'Rnd', (175, 95), (60, -1)) self.Bind(wx.EVT_BUTTON, self.on_close, id=1) self.Bind(wx.EVT_BUTTON, self.on_wicca, id=2) self.Bind(wx.EVT_BUTTON, self.on_rnd, id=3) self.Centre() self.ShowModal() self.Destroy()