]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxMimeTypesManager.py
d&d implementation and checklistbox enabled
[wxWidgets.git] / wxPython / demo / wxMimeTypesManager.py
1
2 import pprint, string, os
3 from wxPython.wx import *
4 from mimetypes_wdr import *
5
6 #----------------------------------------------------------------------------
7
8 # WDR: classes
9
10 class MimeTypesTestPanel(wxPanel):
11 def __init__(self, parent, id,
12 pos = wxPyDefaultPosition, size = wxPyDefaultSize,
13 style = wxTAB_TRAVERSAL ):
14 wxPanel.__init__(self, parent, id, pos, size, style)
15
16 MakeMimeTypesTestPanel( self, true )
17
18 # WDR: handler declarations for MimeTypesTestPanel
19 EVT_LISTBOX(self, ID_LISTBOX, self.OnListbox)
20 EVT_BUTTON(self, ID_LOOKUP_BTN, self.OnLookup)
21
22 self.GetInputText().SetValue("wav")
23 self.OnLookup()
24
25 mimetypes = wxTheMimeTypesManager.EnumAllFileTypes()
26 for mt in mimetypes:
27 self.GetListbox().Append(mt)
28
29
30
31 # WDR: handler implementations for MimeTypesTestPanel
32
33 def OnListbox(self, event):
34 mimetype = event.GetString()
35 self.GetInputText().SetValue(mimetype)
36 self.GetMimeBtn().SetValue(TRUE)
37 self.GetExtensionBtn().SetValue(FALSE)
38 self.OnLookup()
39
40
41 def OnLookup(self, event=None):
42 txt = self.GetInputText().GetValue()
43 if self.GetMimeBtn().GetValue():
44 fileType = wxTheMimeTypesManager.GetFileTypeFromMimeType(txt)
45 msg = "Mime type"
46 else:
47 fileType = wxTheMimeTypesManager.GetFileTypeFromExtension(txt)
48 msg = "File extension"
49 if fileType is None:
50 wxMessageBox(msg + " not found.", "Oops!")
51 else:
52 self.Update(fileType)
53
54
55
56 def Update(self, ft):
57 #icon = ft.GetIcon()
58 info = ft.GetIconInfo()
59 if info is None:
60 bmp = MyBitmapsFunc(0)
61 ##print bmp.Ok(), bmp.GetWidth(), bmp.GetHeight()
62 self.GetIconBmp().SetBitmap(bmp)
63 self.GetIconFileTxt().SetValue("")
64 self.GetIconIndexTxt().SetValue("")
65 else:
66 icon, file, idx = info
67 #bmp = wxBitmapFromIcon(icon)
68 #self.GetIconBmp().SetBitmap(bmp)
69 self.GetIconBmp().SetIcon(icon)
70 self.GetIconFileTxt().SetValue(file)
71 self.GetIconIndexTxt().SetValue(str(idx))
72
73 self.GetMimeTypeTxt().SetValue(str(ft.GetMimeType()))
74 self.GetMimeTypesTxt().SetValue(str(ft.GetMimeTypes()))
75 self.GetExtensionsTxt().SetValue(str(ft.GetExtensions()))
76 self.GetDescriptionTxt().SetValue(str(ft.GetDescription()))
77
78 extList = ft.GetExtensions()
79 if extList:
80 ext = extList[0]
81 if ext[0] == ".": ext = ext[1:]
82 else:
83 ext = ""
84 filename = "SPAM" + "." + ext
85 mime = ft.GetMimeType() or ""
86 cmd = ft.GetOpenCommand(filename, mime)
87 self.GetOpenCmdTxt().SetValue(str(cmd))
88
89 cmd = ft.GetPrintCommand(filename, mime)
90 self.GetPrintCmdTxt().SetValue(str(cmd))
91
92 all = ft.GetAllCommands(filename, mime)
93 if all is None:
94 self.GetAllCmdsTxt().SetValue("")
95 else:
96 verbs, commands = all
97 text = pprint.pformat(map(None, verbs, commands))
98 self.GetAllCmdsTxt().SetValue(text)
99
100
101 # WDR: methods for MimeTypesTestPanel
102
103 def GetListbox(self):
104 return wxPyTypeCast( self.FindWindowById(ID_LISTBOX), "wxListBox" )
105
106 def GetIconIndexTxt(self):
107 return self.FindWindowById(ID_ICON_INDEX_TXT)
108
109 def GetIconFileTxt(self):
110 return self.FindWindowById(ID_ICON_FILE_TXT)
111
112 def GetMimeBtn(self):
113 return self.FindWindowById(ID_MIME_BTN)
114
115 def GetExtensionBtn(self):
116 return self.FindWindowById(ID_EXTENSION_Btn)
117
118 def GetAllCmdsTxt(self):
119 return self.FindWindowById(ID_ALL_CMDS_TXT)
120
121 def GetPrintCmdTxt(self):
122 return self.FindWindowById(ID_PRINT_CMD_TXT)
123
124 def GetOpenCmdTxt(self):
125 return self.FindWindowById(ID_OPEN_CMD_TXT)
126
127 def GetDescriptionTxt(self):
128 return self.FindWindowById(ID_DESCRIPTION_TXT)
129
130 def GetExtensionsTxt(self):
131 return self.FindWindowById(ID_EXTENSIONS_TXT)
132
133 def GetMimeTypesTxt(self):
134 return self.FindWindowById(ID_MIME_TYPES_TXT)
135
136 def GetMimeTypeTxt(self):
137 return self.FindWindowById(ID_MIME_TYPE_TXT)
138
139 def GetIconBmp(self):
140 return self.FindWindowById(ID_ICON_BMP)
141
142 def GetInputText(self):
143 return self.FindWindowById(ID_INPUT_TEXT)
144
145
146
147
148
149 #----------------------------------------------------------------------
150
151 def runTest(frame, nb, log):
152 win = MimeTypesTestPanel(nb, -1)
153 return win
154
155
156 #----------------------------------------------------------------------
157
158
159
160 overview = """\
161 """
162
163
164
165
166 import mimetypes_wdr
167
168 def MyBitmapsFunc( index ):
169 return wxImage( "bitmaps/noicon.png", wxBITMAP_TYPE_PNG ).ConvertToBitmap()
170
171 mimetypes_wdr.MyBitmapsFunc = MyBitmapsFunc
172
173