Merged wxPython 2.4.x to the 2.5 branch (Finally!!!)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19793 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -14,10 +14,10 @@
|
||||
# View "All Image" File Types as default filter
|
||||
# Sort the file list
|
||||
# Use newer "re" function for patterns
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
import os, sys, string
|
||||
import os, sys
|
||||
from wxPython.wx import *
|
||||
dir_path = os.getcwd()
|
||||
|
||||
@@ -29,8 +29,8 @@ def ConvertBMP(file_nm):
|
||||
|
||||
fl_fld = os.path.splitext(file_nm)
|
||||
ext = fl_fld[1]
|
||||
ext = string.lower(ext[1:])
|
||||
if ext == 'bmp':
|
||||
ext = ext[1:].lower()
|
||||
if ext == 'bmp':
|
||||
image = wxImage(file_nm, wxBITMAP_TYPE_BMP)
|
||||
elif ext == 'gif':
|
||||
image = wxImage(file_nm, wxBITMAP_TYPE_GIF)
|
||||
@@ -93,31 +93,31 @@ class ImageView(wxWindow):
|
||||
|
||||
def DrawImage(self, dc):
|
||||
try:
|
||||
image = self.image
|
||||
image = self.image
|
||||
except:
|
||||
return
|
||||
|
||||
self.DrawBorder(dc)
|
||||
if image is None:
|
||||
return
|
||||
|
||||
|
||||
bmp = image.ConvertToBitmap()
|
||||
|
||||
|
||||
iwidth = bmp.GetWidth() # dimensions of image file
|
||||
iheight = bmp.GetHeight()
|
||||
|
||||
|
||||
diffx = (self.image_sizex - iwidth)/2 # center calc
|
||||
if iwidth >= self.image_sizex -10: # if image width fits in window adjust
|
||||
diffx = 5
|
||||
iwidth = self.image_sizex - 10
|
||||
|
||||
|
||||
diffy = (self.image_sizey - iheight)/2 # center calc
|
||||
if iheight >= self.image_sizey - 10: # if image height fits in window adjust
|
||||
diffy = 5
|
||||
iheight = self.image_sizey - 10
|
||||
|
||||
image.Rescale(iwidth, iheight) # rescale to fit the window
|
||||
image.ConvertToBitmap()
|
||||
image.ConvertToBitmap()
|
||||
bmp = image.ConvertToBitmap()
|
||||
dc.DrawBitmap(bmp, diffx, diffy) # draw the image to window
|
||||
|
||||
@@ -125,40 +125,40 @@ class ImageView(wxWindow):
|
||||
class ImageDialog(wxDialog):
|
||||
def __init__(self, parent, set_dir = None):
|
||||
wxDialog.__init__(self, parent, -1, "Image Browser", wxPyDefaultPosition, wxSize(400, 400))
|
||||
|
||||
|
||||
self.x_pos = 30 # initial display positions
|
||||
self.y_pos = 20
|
||||
self.delta = 20
|
||||
self.delta = 20
|
||||
|
||||
size = wxSize(80, 25)
|
||||
|
||||
|
||||
self.set_dir = os.getcwd()
|
||||
|
||||
|
||||
if set_dir != None:
|
||||
if os.path.exists(set_dir): # set to working directory if nothing set
|
||||
self.set_dir = set_dir
|
||||
|
||||
|
||||
self.dir_x = self.x_pos
|
||||
self.dir_y = self.y_pos
|
||||
self.DisplayDir() # display the directory value
|
||||
|
||||
|
||||
self.y_pos = self.y_pos + self.delta
|
||||
|
||||
mID = NewId()
|
||||
mID = wxNewId()
|
||||
wxButton(self, mID, ' Set Directory ', wxPoint(self.x_pos, self.y_pos), size).SetDefault()
|
||||
EVT_BUTTON(self, mID, self.SetDirect)
|
||||
|
||||
self.type_posy = self.y_pos # save the y position for the image type combo
|
||||
self.type_posy = self.y_pos # save the y position for the image type combo
|
||||
|
||||
self.fl_ext = '*.bmp' # initial setting for file filtering
|
||||
self.GetFiles() # get the file list
|
||||
|
||||
|
||||
self.y_pos = self.y_pos + self.delta + 10
|
||||
|
||||
self.list_height = 150
|
||||
|
||||
|
||||
# List of Labels
|
||||
mID = NewId()
|
||||
mID = wxNewId()
|
||||
self.tb = tb = wxListBox(self, mID, wxPoint(self.x_pos, self.y_pos), wxSize(160, self.list_height), self.fl_list, wxLB_SINGLE)
|
||||
EVT_LISTBOX(self, mID, self.OnListClick)
|
||||
EVT_LISTBOX_DCLICK(self, mID, self.OnListDClick)
|
||||
@@ -170,13 +170,13 @@ class ImageDialog(wxDialog):
|
||||
image_sizey = self.list_height
|
||||
|
||||
self.fl_types = ["All Images", "Bmp", "Gif", "Png", "Jpg", "Ico", "Pnm", "Pcx", "Tif", "All Files"]
|
||||
self.fl_ext_types = { "All Images": "All", "Bmp": "*.bmp", "Gif": "*.gif", "Png": "*.png", "Jpg": "*.jpg",
|
||||
self.fl_ext_types = { "All Images": "All", "Bmp": "*.bmp", "Gif": "*.gif", "Png": "*.png", "Jpg": "*.jpg",
|
||||
"Ico": "*.ico", "Pnm": "*.pnm", "Pcx": "*.pcx", "Tif": "*.tif", "All Files": "*.*" }
|
||||
|
||||
|
||||
self.set_type = self.fl_types[0] # initial file filter setting
|
||||
self.fl_ext = self.fl_ext_types[self.set_type]
|
||||
|
||||
mID = NewId()
|
||||
|
||||
mID = wxNewId()
|
||||
self.sel_type = wxComboBox(self, mID, self.set_type, wxPoint(image_posx , self.type_posy), wxSize(150, -1), self.fl_types, wxCB_DROPDOWN)
|
||||
EVT_COMBOBOX(self, mID, self.OnSetType)
|
||||
|
||||
@@ -184,7 +184,7 @@ class ImageDialog(wxDialog):
|
||||
|
||||
self.y_pos = self.y_pos + height + 20
|
||||
|
||||
mID = NewId()
|
||||
mID = wxNewId()
|
||||
wxButton(self, mID, ' Select ', wxPoint(100, self.y_pos), size).SetDefault()
|
||||
EVT_BUTTON(self, mID, self.OnOk)
|
||||
|
||||
@@ -193,7 +193,7 @@ class ImageDialog(wxDialog):
|
||||
self.y_pos = self.y_pos + self.delta
|
||||
fsize = wxSize(400, self.y_pos + 50) # resize dialog for final vertical position
|
||||
self.SetSize(fsize)
|
||||
|
||||
|
||||
self.ResetFiles()
|
||||
|
||||
def GetFiles(self): # get the file list using directory and extension values
|
||||
@@ -204,7 +204,7 @@ class ImageDialog(wxDialog):
|
||||
self.fl_val = FindFiles(self, self.set_dir, filter)
|
||||
all_files = all_files + self.fl_val.files # add to list of files
|
||||
self.fl_list = all_files
|
||||
else:
|
||||
else:
|
||||
self.fl_val = FindFiles(self, self.set_dir, self.fl_ext)
|
||||
self.fl_list = self.fl_val.files
|
||||
|
||||
@@ -212,19 +212,19 @@ class ImageDialog(wxDialog):
|
||||
|
||||
def DisplayDir(self): # display the working directory
|
||||
wxStaticText(self, -1, self.set_dir, wxPoint(self.dir_x, self.dir_y), wxSize(250, -1))
|
||||
|
||||
|
||||
def OnSetType(self, event):
|
||||
val = event.GetString() # get file type value
|
||||
self.fl_ext = self.fl_ext_types[val]
|
||||
self.ResetFiles()
|
||||
|
||||
self.ResetFiles()
|
||||
|
||||
def OnListDClick(self, event):
|
||||
self.OnOk(0)
|
||||
|
||||
|
||||
def OnListClick(self, event):
|
||||
val = event.GetSelection()
|
||||
self.SetListValue(val)
|
||||
|
||||
|
||||
def SetListValue(self, val):
|
||||
file_nm = self.fl_list[val]
|
||||
self.set_file = file_val = os.path.join(self.set_dir, file_nm)
|
||||
@@ -237,7 +237,7 @@ class ImageDialog(wxDialog):
|
||||
self.set_dir = dlg.GetPath()
|
||||
self.ResetFiles()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def ResetFiles(self): # refresh the display with files and initial image
|
||||
self.DisplayDir()
|
||||
self.GetFiles()
|
||||
@@ -247,13 +247,13 @@ class ImageDialog(wxDialog):
|
||||
self.SetListValue(0)
|
||||
except:
|
||||
self.image_view.SetValue(None)
|
||||
|
||||
|
||||
def GetFile(self):
|
||||
return self.set_file
|
||||
|
||||
def GetDirectory(self):
|
||||
return self.set_dir
|
||||
|
||||
|
||||
def OnCancel(self, event):
|
||||
self.result = None
|
||||
self.EndModal(wxID_CANCEL)
|
||||
@@ -278,23 +278,23 @@ class FindFiles:
|
||||
dirlist = [".."]
|
||||
self.dir = dir
|
||||
self.file = ""
|
||||
mask = string.upper(mask)
|
||||
mask = mask.upper()
|
||||
pattern = self.MakeRegex(mask)
|
||||
for i in os.listdir(dir):
|
||||
if i == "." or i == "..":
|
||||
continue
|
||||
continue
|
||||
path = os.path.join(dir, i)
|
||||
path = string.upper(path)
|
||||
value = string.upper(i)
|
||||
path = path.upper()
|
||||
value = i.upper()
|
||||
|
||||
if pattern.match(value) != None:
|
||||
filelist.append(i)
|
||||
|
||||
self.files = filelist
|
||||
self.files = filelist
|
||||
|
||||
def MakeRegex(self, pattern):
|
||||
import re
|
||||
f = "" # Set up a regex for file names
|
||||
f = "" # Set up a regex for file names
|
||||
for ch in pattern:
|
||||
if ch == "*":
|
||||
f = f + ".*"
|
||||
|
Reference in New Issue
Block a user