]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxMimeTypesManager.py
2 import pprint
, string
, os
3 from wxPython
.wx
import *
4 from mimetypes_wdr
import *
7 #----------------------------------------------------------------------------
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
)
17 MakeMimeTypesTestPanel( self
, true
)
19 # WDR: handler declarations for MimeTypesTestPanel
20 EVT_LISTBOX(self
, ID_LISTBOX
, self
.OnListbox
)
21 EVT_BUTTON(self
, ID_LOOKUP_BTN
, self
.OnLookup
)
23 self
.GetInputText().SetValue("wav")
26 mimetypes
= wxTheMimeTypesManager
.EnumAllFileTypes()
28 self
.GetListbox().Append(mt
)
32 # WDR: handler implementations for MimeTypesTestPanel
34 def OnListbox(self
, event
):
35 mimetype
= event
.GetString()
36 self
.GetInputText().SetValue(mimetype
)
37 self
.GetMimeBtn().SetValue(TRUE
)
38 self
.GetExtensionBtn().SetValue(FALSE
)
42 def OnLookup(self
, event
=None):
43 txt
= self
.GetInputText().GetValue()
44 if self
.GetMimeBtn().GetValue():
45 fileType
= wxTheMimeTypesManager
.GetFileTypeFromMimeType(txt
)
48 fileType
= wxTheMimeTypesManager
.GetFileTypeFromExtension(txt
)
49 msg
= "File extension"
51 wxMessageBox(msg
+ " not found.", "Oops!")
59 info
= ft
.GetIconInfo()
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("")
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
))
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()))
79 extList
= ft
.GetExtensions()
82 if ext
[0] == ".": ext
= ext
[1:]
85 filename
= "SPAM" + "." + ext
86 mime
= ft
.GetMimeType() or ""
87 cmd
= ft
.GetOpenCommand(filename
, mime
)
88 self
.GetOpenCmdTxt().SetValue(str(cmd
))
90 cmd
= ft
.GetPrintCommand(filename
, mime
)
91 self
.GetPrintCmdTxt().SetValue(str(cmd
))
93 all
= ft
.GetAllCommands(filename
, mime
)
95 self
.GetAllCmdsTxt().SetValue("")
98 text
= pprint
.pformat(map(None, verbs
, commands
))
99 self
.GetAllCmdsTxt().SetValue(text
)
102 # WDR: methods for MimeTypesTestPanel
104 def GetListbox(self
):
105 return wxPyTypeCast( self
.FindWindowById(ID_LISTBOX
), "wxListBox" )
107 def GetIconIndexTxt(self
):
108 return self
.FindWindowById(ID_ICON_INDEX_TXT
)
110 def GetIconFileTxt(self
):
111 return self
.FindWindowById(ID_ICON_FILE_TXT
)
113 def GetMimeBtn(self
):
114 return self
.FindWindowById(ID_MIME_BTN
)
116 def GetExtensionBtn(self
):
117 return self
.FindWindowById(ID_EXTENSION_Btn
)
119 def GetAllCmdsTxt(self
):
120 return self
.FindWindowById(ID_ALL_CMDS_TXT
)
122 def GetPrintCmdTxt(self
):
123 return self
.FindWindowById(ID_PRINT_CMD_TXT
)
125 def GetOpenCmdTxt(self
):
126 return self
.FindWindowById(ID_OPEN_CMD_TXT
)
128 def GetDescriptionTxt(self
):
129 return self
.FindWindowById(ID_DESCRIPTION_TXT
)
131 def GetExtensionsTxt(self
):
132 return self
.FindWindowById(ID_EXTENSIONS_TXT
)
134 def GetMimeTypesTxt(self
):
135 return self
.FindWindowById(ID_MIME_TYPES_TXT
)
137 def GetMimeTypeTxt(self
):
138 return self
.FindWindowById(ID_MIME_TYPE_TXT
)
140 def GetIconBmp(self
):
141 return self
.FindWindowById(ID_ICON_BMP
)
143 def GetInputText(self
):
144 return self
.FindWindowById(ID_INPUT_TEXT
)
150 #----------------------------------------------------------------------
152 def runTest(frame
, nb
, log
):
153 win
= MimeTypesTestPanel(nb
, -1)
157 #----------------------------------------------------------------------
170 def MyBitmapsFunc( index
):
171 return images
.getNoIconBitmap()
173 mimetypes_wdr
.MyBitmapsFunc
= MyBitmapsFunc