2001-10-30 01:43:54 -05:00
|
|
|
|
2001-10-30 01:58:52 -05:00
|
|
|
import pprint, string, os
|
2001-10-30 01:43:54 -05:00
|
|
|
from wxPython.wx import *
|
|
|
|
from mimetypes_wdr import *
|
2002-01-23 20:24:39 -05:00
|
|
|
from Main import opj
|
2001-10-30 01:43:54 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# WDR: classes
|
|
|
|
|
|
|
|
class MimeTypesTestPanel(wxPanel):
|
|
|
|
def __init__(self, parent, id,
|
|
|
|
pos = wxPyDefaultPosition, size = wxPyDefaultSize,
|
|
|
|
style = wxTAB_TRAVERSAL ):
|
|
|
|
wxPanel.__init__(self, parent, id, pos, size, style)
|
|
|
|
|
2003-03-25 01:35:27 -05:00
|
|
|
MakeMimeTypesTestPanel( self, True )
|
2001-10-30 01:43:54 -05:00
|
|
|
|
|
|
|
# WDR: handler declarations for MimeTypesTestPanel
|
|
|
|
EVT_LISTBOX(self, ID_LISTBOX, self.OnListbox)
|
|
|
|
EVT_BUTTON(self, ID_LOOKUP_BTN, self.OnLookup)
|
|
|
|
|
2001-10-30 01:58:52 -05:00
|
|
|
self.GetInputText().SetValue("wav")
|
2001-10-30 01:43:54 -05:00
|
|
|
self.OnLookup()
|
|
|
|
|
|
|
|
mimetypes = wxTheMimeTypesManager.EnumAllFileTypes()
|
|
|
|
for mt in mimetypes:
|
|
|
|
self.GetListbox().Append(mt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# WDR: handler implementations for MimeTypesTestPanel
|
|
|
|
|
|
|
|
def OnListbox(self, event):
|
|
|
|
mimetype = event.GetString()
|
|
|
|
self.GetInputText().SetValue(mimetype)
|
2003-03-25 01:35:27 -05:00
|
|
|
self.GetMimeBtn().SetValue(True)
|
|
|
|
self.GetExtensionBtn().SetValue(False)
|
2001-10-30 01:43:54 -05:00
|
|
|
self.OnLookup()
|
|
|
|
|
|
|
|
|
|
|
|
def OnLookup(self, event=None):
|
|
|
|
txt = self.GetInputText().GetValue()
|
|
|
|
if self.GetMimeBtn().GetValue():
|
|
|
|
fileType = wxTheMimeTypesManager.GetFileTypeFromMimeType(txt)
|
|
|
|
msg = "Mime type"
|
|
|
|
else:
|
|
|
|
fileType = wxTheMimeTypesManager.GetFileTypeFromExtension(txt)
|
|
|
|
msg = "File extension"
|
|
|
|
if fileType is None:
|
|
|
|
wxMessageBox(msg + " not found.", "Oops!")
|
|
|
|
else:
|
|
|
|
self.Update(fileType)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Update(self, ft):
|
|
|
|
#icon = ft.GetIcon()
|
|
|
|
info = ft.GetIconInfo()
|
|
|
|
if info is None:
|
|
|
|
bmp = MyBitmapsFunc(0)
|
|
|
|
##print bmp.Ok(), bmp.GetWidth(), bmp.GetHeight()
|
|
|
|
self.GetIconBmp().SetBitmap(bmp)
|
|
|
|
self.GetIconFileTxt().SetValue("")
|
|
|
|
self.GetIconIndexTxt().SetValue("")
|
|
|
|
else:
|
|
|
|
icon, file, idx = info
|
|
|
|
#bmp = wxBitmapFromIcon(icon)
|
|
|
|
#self.GetIconBmp().SetBitmap(bmp)
|
|
|
|
self.GetIconBmp().SetIcon(icon)
|
|
|
|
self.GetIconFileTxt().SetValue(file)
|
|
|
|
self.GetIconIndexTxt().SetValue(str(idx))
|
|
|
|
|
|
|
|
self.GetMimeTypeTxt().SetValue(str(ft.GetMimeType()))
|
|
|
|
self.GetMimeTypesTxt().SetValue(str(ft.GetMimeTypes()))
|
|
|
|
self.GetExtensionsTxt().SetValue(str(ft.GetExtensions()))
|
|
|
|
self.GetDescriptionTxt().SetValue(str(ft.GetDescription()))
|
|
|
|
|
2001-11-12 19:32:39 -05:00
|
|
|
extList = ft.GetExtensions()
|
|
|
|
if extList:
|
|
|
|
ext = extList[0]
|
|
|
|
if ext[0] == ".": ext = ext[1:]
|
|
|
|
else:
|
|
|
|
ext = ""
|
2001-10-30 02:03:33 -05:00
|
|
|
filename = "SPAM" + "." + ext
|
2001-10-30 01:43:54 -05:00
|
|
|
mime = ft.GetMimeType() or ""
|
2001-10-30 01:58:52 -05:00
|
|
|
cmd = ft.GetOpenCommand(filename, mime)
|
2001-10-30 01:43:54 -05:00
|
|
|
self.GetOpenCmdTxt().SetValue(str(cmd))
|
|
|
|
|
2001-10-30 01:58:52 -05:00
|
|
|
cmd = ft.GetPrintCommand(filename, mime)
|
2001-10-30 01:43:54 -05:00
|
|
|
self.GetPrintCmdTxt().SetValue(str(cmd))
|
|
|
|
|
2001-10-30 01:58:52 -05:00
|
|
|
all = ft.GetAllCommands(filename, mime)
|
2001-10-30 01:43:54 -05:00
|
|
|
if all is None:
|
|
|
|
self.GetAllCmdsTxt().SetValue("")
|
|
|
|
else:
|
|
|
|
verbs, commands = all
|
|
|
|
text = pprint.pformat(map(None, verbs, commands))
|
|
|
|
self.GetAllCmdsTxt().SetValue(text)
|
|
|
|
|
|
|
|
|
|
|
|
# WDR: methods for MimeTypesTestPanel
|
|
|
|
|
|
|
|
def GetListbox(self):
|
|
|
|
return wxPyTypeCast( self.FindWindowById(ID_LISTBOX), "wxListBox" )
|
|
|
|
|
|
|
|
def GetIconIndexTxt(self):
|
|
|
|
return self.FindWindowById(ID_ICON_INDEX_TXT)
|
|
|
|
|
|
|
|
def GetIconFileTxt(self):
|
|
|
|
return self.FindWindowById(ID_ICON_FILE_TXT)
|
|
|
|
|
|
|
|
def GetMimeBtn(self):
|
|
|
|
return self.FindWindowById(ID_MIME_BTN)
|
|
|
|
|
|
|
|
def GetExtensionBtn(self):
|
|
|
|
return self.FindWindowById(ID_EXTENSION_Btn)
|
|
|
|
|
|
|
|
def GetAllCmdsTxt(self):
|
|
|
|
return self.FindWindowById(ID_ALL_CMDS_TXT)
|
|
|
|
|
|
|
|
def GetPrintCmdTxt(self):
|
|
|
|
return self.FindWindowById(ID_PRINT_CMD_TXT)
|
|
|
|
|
|
|
|
def GetOpenCmdTxt(self):
|
|
|
|
return self.FindWindowById(ID_OPEN_CMD_TXT)
|
|
|
|
|
|
|
|
def GetDescriptionTxt(self):
|
|
|
|
return self.FindWindowById(ID_DESCRIPTION_TXT)
|
|
|
|
|
|
|
|
def GetExtensionsTxt(self):
|
|
|
|
return self.FindWindowById(ID_EXTENSIONS_TXT)
|
|
|
|
|
|
|
|
def GetMimeTypesTxt(self):
|
|
|
|
return self.FindWindowById(ID_MIME_TYPES_TXT)
|
|
|
|
|
|
|
|
def GetMimeTypeTxt(self):
|
|
|
|
return self.FindWindowById(ID_MIME_TYPE_TXT)
|
|
|
|
|
|
|
|
def GetIconBmp(self):
|
|
|
|
return self.FindWindowById(ID_ICON_BMP)
|
|
|
|
|
|
|
|
def GetInputText(self):
|
|
|
|
return self.FindWindowById(ID_INPUT_TEXT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = MimeTypesTestPanel(nb, -1)
|
|
|
|
return win
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """\
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import mimetypes_wdr
|
2002-02-26 17:35:10 -05:00
|
|
|
import images
|
2001-10-30 01:43:54 -05:00
|
|
|
|
|
|
|
def MyBitmapsFunc( index ):
|
2002-02-26 17:35:10 -05:00
|
|
|
return images.getNoIconBitmap()
|
2001-10-30 01:43:54 -05:00
|
|
|
|
|
|
|
mimetypes_wdr.MyBitmapsFunc = MyBitmapsFunc
|
|
|
|
|
|
|
|
|
2003-07-02 19:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])])
|