]>
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 *
6 #----------------------------------------------------------------------------
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
)
16 MakeMimeTypesTestPanel( self
, true
)
18 # WDR: handler declarations for MimeTypesTestPanel
19 EVT_LISTBOX(self
, ID_LISTBOX
, self
.OnListbox
)
20 EVT_BUTTON(self
, ID_LOOKUP_BTN
, self
.OnLookup
)
22 self
.GetInputText().SetValue("wav")
25 mimetypes
= wxTheMimeTypesManager
.EnumAllFileTypes()
27 self
.GetListbox().Append(mt
)
31 # WDR: handler implementations for MimeTypesTestPanel
33 def OnListbox(self
, event
):
34 mimetype
= event
.GetString()
35 self
.GetInputText().SetValue(mimetype
)
36 self
.GetMimeBtn().SetValue(TRUE
)
37 self
.GetExtensionBtn().SetValue(FALSE
)
41 def OnLookup(self
, event
=None):
42 txt
= self
.GetInputText().GetValue()
43 if self
.GetMimeBtn().GetValue():
44 fileType
= wxTheMimeTypesManager
.GetFileTypeFromMimeType(txt
)
47 fileType
= wxTheMimeTypesManager
.GetFileTypeFromExtension(txt
)
48 msg
= "File extension"
50 wxMessageBox(msg
+ " not found.", "Oops!")
58 info
= ft
.GetIconInfo()
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("")
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
))
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()))
78 extList
= ft
.GetExtensions()
81 if ext
[0] == ".": ext
= ext
[1:]
84 filename
= "SPAM" + "." + ext
85 mime
= ft
.GetMimeType() or ""
86 cmd
= ft
.GetOpenCommand(filename
, mime
)
87 self
.GetOpenCmdTxt().SetValue(str(cmd
))
89 cmd
= ft
.GetPrintCommand(filename
, mime
)
90 self
.GetPrintCmdTxt().SetValue(str(cmd
))
92 all
= ft
.GetAllCommands(filename
, mime
)
94 self
.GetAllCmdsTxt().SetValue("")
97 text
= pprint
.pformat(map(None, verbs
, commands
))
98 self
.GetAllCmdsTxt().SetValue(text
)
101 # WDR: methods for MimeTypesTestPanel
103 def GetListbox(self
):
104 return wxPyTypeCast( self
.FindWindowById(ID_LISTBOX
), "wxListBox" )
106 def GetIconIndexTxt(self
):
107 return self
.FindWindowById(ID_ICON_INDEX_TXT
)
109 def GetIconFileTxt(self
):
110 return self
.FindWindowById(ID_ICON_FILE_TXT
)
112 def GetMimeBtn(self
):
113 return self
.FindWindowById(ID_MIME_BTN
)
115 def GetExtensionBtn(self
):
116 return self
.FindWindowById(ID_EXTENSION_Btn
)
118 def GetAllCmdsTxt(self
):
119 return self
.FindWindowById(ID_ALL_CMDS_TXT
)
121 def GetPrintCmdTxt(self
):
122 return self
.FindWindowById(ID_PRINT_CMD_TXT
)
124 def GetOpenCmdTxt(self
):
125 return self
.FindWindowById(ID_OPEN_CMD_TXT
)
127 def GetDescriptionTxt(self
):
128 return self
.FindWindowById(ID_DESCRIPTION_TXT
)
130 def GetExtensionsTxt(self
):
131 return self
.FindWindowById(ID_EXTENSIONS_TXT
)
133 def GetMimeTypesTxt(self
):
134 return self
.FindWindowById(ID_MIME_TYPES_TXT
)
136 def GetMimeTypeTxt(self
):
137 return self
.FindWindowById(ID_MIME_TYPE_TXT
)
139 def GetIconBmp(self
):
140 return self
.FindWindowById(ID_ICON_BMP
)
142 def GetInputText(self
):
143 return self
.FindWindowById(ID_INPUT_TEXT
)
149 #----------------------------------------------------------------------
151 def runTest(frame
, nb
, log
):
152 win
= MimeTypesTestPanel(nb
, -1)
156 #----------------------------------------------------------------------
168 def MyBitmapsFunc( index
):
169 return wxImage( "bitmaps/noicon.png", wxBITMAP_TYPE_PNG
).ConvertToBitmap()
171 mimetypes_wdr
.MyBitmapsFunc
= MyBitmapsFunc