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