def __init__(self, items):
self.items = items
self.newitems = []
style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT
CS = win32con.WS_CHILD | win32con.WS_VISIBLE
tmp = [ ["Grep Parameters", (0, 0, 205, 100), style, None, (8, "MS Sans Serif")], ]
tmp.append([LISTBOX, '', 107, (7, 7, 150, 72), CS | win32con.LBS_MULTIPLESEL| win32con.LBS_STANDARD | win32con.LBS_HASSTRINGS | win32con.WS_TABSTOP | win32con.LBS_NOTIFY])
tmp.append([BUTTON,'OK', win32con.IDOK, (167, 7, 32, 12), CS | win32con.BS_DEFPUSHBUTTON| win32con.WS_TABSTOP])
tmp.append([BUTTON,'Cancel', win32con.IDCANCEL, (167,23, 32, 12), CS | win32con.BS_PUSHBUTTON| win32con.WS_TABSTOP])
tmp.append([STATIC,'New:', -1, (2, 83, 15, 12), CS])
tmp.append([EDIT, '', 108, (18, 83, 139, 12), CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER])
tmp.append([BUTTON,'Add', 109, (167,83, 32, 12), CS | win32con.BS_PUSHBUTTON| win32con.WS_TABSTOP])
dialog.Dialog.__init__(self, tmp)
self.HookCommand(self.OnAddItem, 109)
self.HookCommand(self.OnListDoubleClick, 107)
python类WS_BORDER的实例源码
def __init__(self, dp, fp, gp, cs, r, v):
style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT
CS = win32con.WS_CHILD | win32con.WS_VISIBLE
tmp = [ ["Pychecker Run", (0, 0, 210, 90), style, None, (8, "MS Sans Serif")], ]
tmp.append([STATIC, "Files:", -1, (7, 7, 50, 9), CS ])
tmp.append([EDIT, gp, 103, (52, 7, 144, 11), CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER])
tmp.append([STATIC, "Directories:", -1, (7, 20, 50, 9), CS ])
tmp.append([EDIT, dp, 102, (52, 20, 128, 11), CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER])
tmp.append([BUTTON, '...', 110, (182,20, 16, 11), CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP])
tmp.append([STATIC, "Options:", -1, (7, 33, 50, 9), CS ])
tmp.append([EDIT, fp, 101, (52, 33, 128, 11), CS | win32con.WS_TABSTOP | win32con.ES_AUTOHSCROLL | win32con.WS_BORDER ])
tmp.append([BUTTON, '...', 111, (182,33, 16, 11), CS | win32con.BS_PUSHBUTTON | win32con.WS_TABSTOP])
#tmp.append([BUTTON,'Case sensitive', 104, (7, 45, 72, 9), CS | win32con.BS_AUTOCHECKBOX | win32con.BS_LEFTTEXT| win32con.WS_TABSTOP])
#tmp.append([BUTTON,'Subdirectories', 105, (7, 56, 72, 9), CS | win32con.BS_AUTOCHECKBOX | win32con.BS_LEFTTEXT| win32con.WS_TABSTOP])
#tmp.append([BUTTON,'Verbose', 106, (7, 67, 72, 9), CS | win32con.BS_AUTOCHECKBOX | win32con.BS_LEFTTEXT| win32con.WS_TABSTOP])
tmp.append([BUTTON,'OK', win32con.IDOK, (166,53, 32, 12), CS | win32con.BS_DEFPUSHBUTTON| win32con.WS_TABSTOP])
tmp.append([BUTTON,'Cancel', win32con.IDCANCEL, (166,67, 32, 12), CS | win32con.BS_PUSHBUTTON| win32con.WS_TABSTOP])
dialog.Dialog.__init__(self, tmp)
self.AddDDX(101,'greppattern')
self.AddDDX(102,'dirpattern')
self.AddDDX(103,'filpattern')
#self.AddDDX(104,'casesensitive')
#self.AddDDX(105,'recursive')
#self.AddDDX(106,'verbose')
self._obj_.data['greppattern'] = gp
self._obj_.data['dirpattern'] = dp
self._obj_.data['filpattern'] = fp
#self._obj_.data['casesensitive'] = cs
#self._obj_.data['recursive'] = r
#self._obj_.data['verbose'] = v
self.HookCommand(self.OnMoreDirectories, 110)
self.HookCommand(self.OnMoreFiles, 111)
def CreateWindow(self, parent):
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | commctrl.TVS_HASLINES | commctrl.TVS_LINESATROOT | commctrl.TVS_HASBUTTONS
self._obj_.CreateWindow(style, self.GetDefRect(), parent, win32ui.IDC_LIST1)
self.HookMessage(self.OnKeyDown, win32con.WM_KEYDOWN)
self.HookMessage(self.OnKeyDown, win32con.WM_SYSKEYDOWN)
self.list.HierInit (parent, self)
self.listOK = 0 # delayed setup
#self.list.Setup()
def EditCreator(parent):
d = win32ui.CreateEdit()
es = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | win32con.ES_MULTILINE | win32con.ES_WANTRETURN
d.CreateWindow( es, (0,0,150,150), parent, 1000)
return d
def DockableBrowserCreator(parent):
root = HLIRoot()
hl = hierlist.HierListWithItems (
root,
win32ui.IDB_BROWSER_HIER
)
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | commctrl.TVS_HASLINES | commctrl.TVS_LINESATROOT | commctrl.TVS_HASBUTTONS
control = win32ui.CreateTreeCtrl()
control.CreateWindow(style, (0, 0, 150, 300), parent, win32ui.IDC_LIST1)
list = hl.HierInit (parent, control)
return control
def GetTemplate(self):
"Return the template used to create this dialog"
w = 152 # Dialog width
h = 122 # Dialog height
SS_STD = win32con.WS_CHILD | win32con.WS_VISIBLE
FRAMEDLG_STD = win32con.WS_CAPTION | win32con.WS_SYSMENU
style = FRAMEDLG_STD | win32con.WS_VISIBLE | win32con.DS_SETFONT | win32con.WS_MINIMIZEBOX
template = [[self.caption, (0, 0, w, h), style, None, (8, 'Helv')], ]
lvStyle = SS_STD | commctrl.LVS_EDITLABELS | commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE | commctrl.LVS_ALIGNLEFT | win32con.WS_BORDER | win32con.WS_TABSTOP
template.append(["SysListView32", "", self.IDC_LISTVIEW, (10, 10, 185, 100), lvStyle])
return template
def _GetDialogTemplate(self, dlgClassName):
style = win32con.WS_THICKFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT | win32con.WS_MINIMIZEBOX
cs = win32con.WS_CHILD | win32con.WS_VISIBLE
title = "Dynamic Dialog Demo"
# Window frame and title
dlg = [ [title, (0, 0, 210, 250), style, None, (8, "MS Sans Serif"), None, dlgClassName], ]
# ID label and text box
dlg.append([130, "Enter something", -1, (5, 5, 200, 9), cs | win32con.SS_LEFT])
s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
dlg.append(['EDIT', None, IDC_SEARCHTEXT, (5, 15, 200, 12), s])
# Search/Display Buttons
# (x positions don't matter here)
s = cs | win32con.WS_TABSTOP
dlg.append([128, "Fill List", IDC_BUTTON_SEARCH, (5, 35, 50, 14), s | win32con.BS_DEFPUSHBUTTON])
s = win32con.BS_PUSHBUTTON | s
dlg.append([128, "Display", IDC_BUTTON_DISPLAY, (100, 35, 50, 14), s])
# List control.
# Can't make this work :(
## s = cs | win32con.WS_TABSTOP
## dlg.append(['SysListView32', "Title", IDC_LISTBOX, (5, 505, 200, 200), s])
return dlg
def _SetupList(self):
child_style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | win32con.WS_HSCROLL | win32con.WS_VSCROLL
child_style |= commctrl.LVS_SINGLESEL | commctrl.LVS_SHOWSELALWAYS | commctrl.LVS_REPORT
self.hwndList = win32gui.CreateWindow("SysListView32", None, child_style, 0, 0, 100, 100, self.hwnd, IDC_LISTBOX, self.hinst, None)
child_ex_style = win32gui.SendMessage(self.hwndList, commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
child_ex_style |= commctrl.LVS_EX_FULLROWSELECT
win32gui.SendMessage(self.hwndList, commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, child_ex_style)
# Add an image list - use the builtin shell folder icon - this
# demonstrates the problem with alpha-blending of icons on XP if
# winxpgui is not used in place of win32gui.
il = win32gui.ImageList_Create(
win32api.GetSystemMetrics(win32con.SM_CXSMICON),
win32api.GetSystemMetrics(win32con.SM_CYSMICON),
commctrl.ILC_COLOR32 | commctrl.ILC_MASK,
1, # initial size
0) # cGrow
shell_dll = os.path.join(win32api.GetSystemDirectory(), "shell32.dll")
large, small = win32gui.ExtractIconEx(shell_dll, 4, 1)
win32gui.ImageList_ReplaceIcon(il, -1, small[0])
win32gui.DestroyIcon(small[0])
win32gui.DestroyIcon(large[0])
win32gui.SendMessage(self.hwndList, commctrl.LVM_SETIMAGELIST,
commctrl.LVSIL_SMALL, il)
# Setup the list control columns.
lvc = LVCOLUMN(mask = commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM)
lvc.fmt = commctrl.LVCFMT_LEFT
lvc.iSubItem = 1
lvc.text = "Title"
lvc.cx = 200
win32gui.SendMessage(self.hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())
lvc.iSubItem = 0
lvc.text = "Order"
lvc.cx = 50
win32gui.SendMessage(self.hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())
win32gui.UpdateWindow(self.hwnd)
def _CreateChildWindow(self, prev):
# Creates the list view window.
assert self.hwnd_child is None, "already have a window"
assert self.cur_foldersettings is not None, "no settings"
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | \
commctrl.LVS_SHAREIMAGELISTS | commctrl.LVS_EDITLABELS
view_mode, view_flags = self.cur_foldersettings
if view_mode==shellcon.FVM_ICON:
style |= commctrl.LVS_ICON | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_SMALLICON:
style |= commctrl.LVS_SMALLICON | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_LIST:
style |= commctrl.LVS_LIST | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_DETAILS:
style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
else:
# XP 'thumbnails' etc
view_mode = shellcon.FVM_DETAILS
# Default to 'report'
style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
for f_flag, l_flag in [
(shellcon.FWF_SINGLESEL, commctrl.LVS_SINGLESEL),
(shellcon.FWF_ALIGNLEFT, commctrl.LVS_ALIGNLEFT),
(shellcon.FWF_SHOWSELALWAYS, commctrl.LVS_SHOWSELALWAYS),
]:
if view_flags & f_flag:
style |= l_flag
self.hwnd_child = win32gui.CreateWindowEx(
win32con.WS_EX_CLIENTEDGE,
"SysListView32", None, style,
0, 0, 0, 0,
self.hwnd, 1000, 0, None)
cr = win32gui.GetClientRect(self.hwnd)
win32gui.MoveWindow(self.hwnd_child,
0, 0, cr[2]-cr[0], cr[3]-cr[1],
True)
# Setup the columns for the view.
lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_LEFT,
subItem=1,
text='Name',
cx=300)
win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
0, lvc)
lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_RIGHT,
subItem=1,
text='Exists',
cx=50)
win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
1, lvc)
# and fill it with the content
self.Refresh()
def _CreateChildWindow(self, prev):
# Creates the list view window.
assert self.hwnd_child is None, "already have a window"
assert self.cur_foldersettings is not None, "no settings"
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | \
commctrl.LVS_SHAREIMAGELISTS | commctrl.LVS_EDITLABELS
view_mode, view_flags = self.cur_foldersettings
if view_mode==shellcon.FVM_ICON:
style |= commctrl.LVS_ICON | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_SMALLICON:
style |= commctrl.LVS_SMALLICON | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_LIST:
style |= commctrl.LVS_LIST | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_DETAILS:
style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
else:
# XP 'thumbnails' etc
view_mode = shellcon.FVM_DETAILS
# Default to 'report'
style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
for f_flag, l_flag in [
(shellcon.FWF_SINGLESEL, commctrl.LVS_SINGLESEL),
(shellcon.FWF_ALIGNLEFT, commctrl.LVS_ALIGNLEFT),
(shellcon.FWF_SHOWSELALWAYS, commctrl.LVS_SHOWSELALWAYS),
]:
if view_flags & f_flag:
style |= l_flag
self.hwnd_child = win32gui.CreateWindowEx(
win32con.WS_EX_CLIENTEDGE,
"SysListView32", None, style,
0, 0, 0, 0,
self.hwnd, 1000, 0, None)
cr = win32gui.GetClientRect(self.hwnd)
win32gui.MoveWindow(self.hwnd_child,
0, 0, cr[2]-cr[0], cr[3]-cr[1],
True)
# Setup the columns for the view.
lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_LEFT,
subItem=1,
text='Name',
cx=300)
win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
0, lvc)
lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_RIGHT,
subItem=1,
text='Exists',
cx=50)
win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
1, lvc)
# and fill it with the content
self.Refresh()
def _CreateChildWindow(self, prev):
# Creates the list view window.
assert self.hwnd_child is None, "already have a window"
assert self.cur_foldersettings is not None, "no settings"
style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | \
commctrl.LVS_SHAREIMAGELISTS | commctrl.LVS_EDITLABELS
view_mode, view_flags = self.cur_foldersettings
if view_mode==shellcon.FVM_ICON:
style |= commctrl.LVS_ICON | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_SMALLICON:
style |= commctrl.LVS_SMALLICON | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_LIST:
style |= commctrl.LVS_LIST | commctrl.LVS_AUTOARRANGE
elif view_mode==shellcon.FVM_DETAILS:
style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
else:
# XP 'thumbnails' etc
view_mode = shellcon.FVM_DETAILS
# Default to 'report'
style |= commctrl.LVS_REPORT | commctrl.LVS_AUTOARRANGE
for f_flag, l_flag in [
(shellcon.FWF_SINGLESEL, commctrl.LVS_SINGLESEL),
(shellcon.FWF_ALIGNLEFT, commctrl.LVS_ALIGNLEFT),
(shellcon.FWF_SHOWSELALWAYS, commctrl.LVS_SHOWSELALWAYS),
]:
if view_flags & f_flag:
style |= l_flag
self.hwnd_child = win32gui.CreateWindowEx(
win32con.WS_EX_CLIENTEDGE,
"SysListView32", None, style,
0, 0, 0, 0,
self.hwnd, 1000, 0, None)
cr = win32gui.GetClientRect(self.hwnd)
win32gui.MoveWindow(self.hwnd_child,
0, 0, cr[2]-cr[0], cr[3]-cr[1],
True)
# Setup the columns for the view.
lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_LEFT,
subItem=1,
text='Name',
cx=300)
win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
0, lvc)
lvc, extras = win32gui_struct.PackLVCOLUMN(fmt=commctrl.LVCFMT_RIGHT,
subItem=1,
text='Exists',
cx=50)
win32gui.SendMessage(self.hwnd_child, commctrl.LVM_INSERTCOLUMN,
1, lvc)
# and fill it with the content
self.Refresh()