X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4a340a90d161d86e27ba79a0463f2f96881dc6f6..f5766910b6731eb03e82371416e9778203396ce7:/wxPython/demo/MimeTypesManager.py diff --git a/wxPython/demo/MimeTypesManager.py b/wxPython/demo/MimeTypesManager.py index 4dc89e2571..7d3f1e9520 100644 --- a/wxPython/demo/MimeTypesManager.py +++ b/wxPython/demo/MimeTypesManager.py @@ -17,6 +17,13 @@ import pprint import wx import images + +# helper function to make sure we don't convert unicode objects to strings +# or vice versa when converting lists and None values to text. +convert = str +if 'unicode' in wx.PlatformInfo: + convert = unicode + #---------------------------------------------------------------------------- class MimeTypesDemoPanel(wx.Panel): @@ -43,7 +50,7 @@ class MimeTypesDemoPanel(wx.Panel): # Text control for ext / type entry plus label. t = wx.StaticText(self, -1, 'Extension / MIME type: ', style = wx.ALIGN_RIGHT ) t.SetFont(bfont) - usizer.Add(t, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL, 2) + usizer.Add(t, 0, wx.ALL | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL, 2) self.ext = wx.TextCtrl(self, -1, value="wav", style = wx.TE_PROCESS_ENTER ) usizer.Add(self.ext, 0, wx.ALL | wx.ALIGN_TOP, 4) @@ -85,13 +92,13 @@ class MimeTypesDemoPanel(wx.Panel): llsizer.Add(t, (0, 0), (1, 1), wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 2) self.icon = wx.StaticBitmap(self, -1, images.getNoIconBitmap()) - llsizer.Add(self.icon, (0, 1), (1, 1), wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 2) + llsizer.Add(self.icon, (0, 1), (1, 1), wx.ALL | wx.ALIGN_CENTER, 2) - self.iconsource = wx.TextCtrl(self, -1, value="", style = wx.TE_READONLY ) - llsizer.Add(self.iconsource, (0, 2), (1, 1), wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 2) + self.iconsource = wx.TextCtrl(self, -1, value="", size=(125, -1), style = wx.TE_READONLY ) + llsizer.Add(self.iconsource, (0, 2), (1, 1), wx.ALL | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 2) - self.iconoffset = wx.TextCtrl(self, -1, value="", style = wx.TE_READONLY ) - llsizer.Add(self.iconoffset, (0, 3), (1, 1), wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 2) + self.iconoffset = wx.TextCtrl(self, -1, value="", size=(25,-1), style = wx.TE_READONLY ) + llsizer.Add(self.iconoffset, (0, 3), (1, 1), wx.ALL | wx.ALIGN_CENTER_VERTICAL, 2) #------- MIME Type @@ -176,7 +183,7 @@ class MimeTypesDemoPanel(wx.Panel): lrsizer.Add(t, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 4) self.mimelist = wx.ListBox(self, -1, choices=[], style = wx.LB_SINGLE | wx.LB_SORT) - lrsizer.Add(self.mimelist, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 4) + lrsizer.Add(self.mimelist, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER | wx.FIXED_MINSIZE, 4) self.Bind(wx.EVT_LISTBOX, self.OnListbox, self.mimelist) #---------------------------------------------------------------------------- @@ -195,9 +202,20 @@ class MimeTypesDemoPanel(wx.Panel): tsizer.Fit(self) # Populate the Known MIME types list with what is in the database - mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() + try: + mtypes = wx.TheMimeTypesManager.EnumAllFileTypes() + except wx.PyAssertionError: + mtypes = [] + + # TODO: On wxMac, EnumAllFileTypes produces tons of dupes, which + # causes quirky behavior because the list control doesn't expect + # dupes, and simply wastes space. So remove the dupes for now, + # then remove this hack when we fix EnumAllFileTypes on Mac. + mimes = [] for mt in mtypes: - self.mimelist.Append(mt) + if mt not in mimes: + self.mimelist.Append(mt) + mimes.append(mt) # Do a lookup of *.wav for a starting position self.OnLookup() @@ -231,10 +249,10 @@ class MimeTypesDemoPanel(wx.Panel): # Select the entered value in the list if fileType: - if self.mimelist.FindString(str(fileType.GetMimeType())) != -1: + if self.mimelist.FindString(convert(fileType.GetMimeType())) != -1: # Using CallAfter to ensure that GUI is ready before trying to # select it (otherwise, it's selected but not visible) - wx.CallAfter(self.mimelist.SetSelection, self.mimelist.FindString(str(fileType.GetMimeType()))) + wx.CallAfter(self.mimelist.SetSelection, self.mimelist.FindString(convert(fileType.GetMimeType()))) if fileType is None: @@ -261,23 +279,23 @@ class MimeTypesDemoPanel(wx.Panel): bmp = images.getNoIconBitmap() self.icon.SetBitmap(bmp) self.iconsource.SetValue(file) - self.iconoffset.SetValue(str(idx)) + self.iconoffset.SetValue(convert(idx)) #------- MIME type - self.mimetype.SetValue(str(ft.GetMimeType())) + self.mimetype.SetValue(convert(ft.GetMimeType())) #------- MIME types - self.mimetypes.SetValue(str(ft.GetMimeTypes())) + self.mimetypes.SetValue(convert(ft.GetMimeTypes())) #------- Associated extensions - self.extensions.SetValue(str(ft.GetExtensions())) + self.extensions.SetValue(convert(ft.GetExtensions())) #------- Description of file type - self.description.SetValue(str(ft.GetDescription())) + self.description.SetValue(convert(ft.GetDescription())) #------- Prep a fake command line command extList = ft.GetExtensions() if extList: ext = extList[0] - if ext[0] == ".": ext = ext[1:] + if len(ext) > 0 and ext[0] == ".": ext = ext[1:] else: ext = "" @@ -286,11 +304,11 @@ class MimeTypesDemoPanel(wx.Panel): #------- OPEN command cmd = ft.GetOpenCommand(filename, mime) - self.opencommand.SetValue(str(cmd)) + self.opencommand.SetValue(convert(cmd)) #------- PRINT command cmd = ft.GetPrintCommand(filename, mime) - self.printcommand.SetValue(str(cmd)) + self.printcommand.SetValue(convert(cmd)) #------- All commands all = ft.GetAllCommands(filename, mime) @@ -339,4 +357,4 @@ For further information please consult the wxWindows documentation for if __name__ == '__main__': import sys,os import run - run.main(['', os.path.basename(sys.argv[0])]) + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])