]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxMimeTypesManager.py
Updated timer demo (again ;-)
[wxWidgets.git] / wxPython / demo / wxMimeTypesManager.py
CommitLineData
b37c7e1d 1
ee707cb7 2import pprint, string, os
b37c7e1d
RD
3from wxPython.wx import *
4from mimetypes_wdr import *
5
6#----------------------------------------------------------------------------
7
8# WDR: classes
9
10class 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
ee707cb7 22 self.GetInputText().SetValue("wav")
b37c7e1d
RD
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
4c3b4ed0
RD
78 ext = ft.GetExtensions()[0]
79 if ext[0] == ".": ext = ext[1:]
80 filename = "SPAM" + "." + ext
b37c7e1d 81 mime = ft.GetMimeType() or ""
ee707cb7 82 cmd = ft.GetOpenCommand(filename, mime)
b37c7e1d
RD
83 self.GetOpenCmdTxt().SetValue(str(cmd))
84
ee707cb7 85 cmd = ft.GetPrintCommand(filename, mime)
b37c7e1d
RD
86 self.GetPrintCmdTxt().SetValue(str(cmd))
87
ee707cb7 88 all = ft.GetAllCommands(filename, mime)
b37c7e1d
RD
89 if all is None:
90 self.GetAllCmdsTxt().SetValue("")
91 else:
92 verbs, commands = all
93 text = pprint.pformat(map(None, verbs, commands))
94 self.GetAllCmdsTxt().SetValue(text)
95
96
97 # WDR: methods for MimeTypesTestPanel
98
99 def GetListbox(self):
100 return wxPyTypeCast( self.FindWindowById(ID_LISTBOX), "wxListBox" )
101
102 def GetIconIndexTxt(self):
103 return self.FindWindowById(ID_ICON_INDEX_TXT)
104
105 def GetIconFileTxt(self):
106 return self.FindWindowById(ID_ICON_FILE_TXT)
107
108 def GetMimeBtn(self):
109 return self.FindWindowById(ID_MIME_BTN)
110
111 def GetExtensionBtn(self):
112 return self.FindWindowById(ID_EXTENSION_Btn)
113
114 def GetAllCmdsTxt(self):
115 return self.FindWindowById(ID_ALL_CMDS_TXT)
116
117 def GetPrintCmdTxt(self):
118 return self.FindWindowById(ID_PRINT_CMD_TXT)
119
120 def GetOpenCmdTxt(self):
121 return self.FindWindowById(ID_OPEN_CMD_TXT)
122
123 def GetDescriptionTxt(self):
124 return self.FindWindowById(ID_DESCRIPTION_TXT)
125
126 def GetExtensionsTxt(self):
127 return self.FindWindowById(ID_EXTENSIONS_TXT)
128
129 def GetMimeTypesTxt(self):
130 return self.FindWindowById(ID_MIME_TYPES_TXT)
131
132 def GetMimeTypeTxt(self):
133 return self.FindWindowById(ID_MIME_TYPE_TXT)
134
135 def GetIconBmp(self):
136 return self.FindWindowById(ID_ICON_BMP)
137
138 def GetInputText(self):
139 return self.FindWindowById(ID_INPUT_TEXT)
140
141
142
143
144
145#----------------------------------------------------------------------
146
147def runTest(frame, nb, log):
148 win = MimeTypesTestPanel(nb, -1)
149 return win
150
151
152#----------------------------------------------------------------------
153
154
155
156overview = """\
157"""
158
159
160
161
162import mimetypes_wdr
163
164def MyBitmapsFunc( index ):
165 return wxImage( "bitmaps/noicon.png", wxBITMAP_TYPE_PNG ).ConvertToBitmap()
166
167mimetypes_wdr.MyBitmapsFunc = MyBitmapsFunc
168
169