| 11 | from _development.helpers_locale import GetPath, GetUnicodePath |
| 12 | |
| 13 | class MyForm(wx.Frame): |
| 14 | # ---------------------------------------------------------------------- |
| 15 | def __init__(self): |
| 16 | wx.Frame.__init__(self, None, wx.ID_ANY, "CTRL-O to open, CTRL-S to save", size=(500, 500)) |
| 17 | |
| 18 | # Add a panel so it looks the correct on all platforms |
| 19 | panel = wx.Panel(self, wx.ID_ANY) |
| 20 | |
| 21 | SAVE_FILE_ID = wx.NewId() |
| 22 | self.Bind(wx.EVT_MENU, self.saveFile, id=SAVE_FILE_ID) |
| 23 | |
| 24 | LOAD_FILE_ID = wx.NewId() |
| 25 | self.Bind(wx.EVT_MENU, self.loadFile, id=LOAD_FILE_ID) |
| 26 | |
| 27 | accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('O'), LOAD_FILE_ID), |
| 28 | (wx.ACCEL_CTRL, ord('S'), SAVE_FILE_ID)] |
| 29 | ) |
| 30 | self.SetAcceleratorTable(accel_tbl) |
| 31 | |
| 32 | # ---------------------------------------------------------------------- |
| 33 | def loadFile(self, event): |
| 34 | with wx.FileDialog( |
| 35 | self, "Open", "", "", |
| 36 | "Python files (*.py)|*.py", |
| 37 | wx.FD_OPEN | wx.FD_FILE_MUST_EXIST |
| 38 | ) as dlg: |
| 39 | dlg.ShowModal() |
| 40 | path = dlg.GetPath() |
| 41 | try: |
| 42 | os_walk_without_codec = GetPath(path) |
| 43 | except (UnicodeEncodeError, UnicodeTranslateError, UnicodeError, UnicodeDecodeError, UnicodeWarning, TypeError) as e: |
| 44 | os_walk_without_codec = e |
| 45 | |
| 46 | try: |
| 47 | os_walk_with_system_codec = GetPath(path, None, sys.getdefaultencoding()) |
| 48 | except (UnicodeEncodeError, UnicodeTranslateError, UnicodeError, UnicodeDecodeError, UnicodeWarning, TypeError) as e: |
| 49 | os_walk_with_system_codec = e |
| 50 | |
| 51 | try: |
| 52 | os_walk_unicode_without_codec = GetUnicodePath(path) |
| 53 | except (UnicodeEncodeError, UnicodeTranslateError, UnicodeError, UnicodeDecodeError, UnicodeWarning, TypeError) as e: |
| 54 | os_walk_unicode_without_codec = e |
| 55 | |
| 56 | try: |
| 57 | os_walk_unicode_with_system_codec = GetUnicodePath(path, None, sys.getdefaultencoding()) |
| 58 | except (UnicodeEncodeError, UnicodeTranslateError, UnicodeError, UnicodeDecodeError, UnicodeWarning, TypeError) as e: |
| 59 | os_walk_unicode_with_system_codec = e |
| 60 | |
| 61 | print("Simple print:") |
| 62 | print(path) |
| 63 | |
| 64 | print("Type:") |
| 65 | print((type(path))) |
| 66 | |
| 67 | print("OS Walk: No Codec:") |
| 68 | print(os_walk_without_codec) |
| 69 | |
| 70 | print("OS Walk: Default System Codec:") |