def selectListboxItem(hwnd, item):
'''Selects a specified item in a list box control.
Arguments:
hwnd Window handle of the required list box.
item The reqired item. Either an index, of the text of the
required item.
Usage example: TODO
'''
try: # item is an index Use this to select
0 + item
win32gui.SendMessage(hwnd, win32con.LB_SETCURSEL, item, 0)
_sendNotifyMessage(hwnd, win32con.LBN_SELCHANGE)
except TypeError: # Item is a string - find the index, and use that
items = getListboxItems(hwnd)
itemIndex = items.index(item)
selectListboxItem(hwnd, itemIndex)
python类LBN_SELCHANGE的实例源码
winGuiAuto_bak.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
winGuiAuto.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def selectListboxItem(hwnd, item):
'''Selects a specified item in a list box control.
Arguments:
hwnd Window handle of the required list box.
item The reqired item. Either an index, of the text of the
required item.
Usage example: TODO
'''
try: # item is an index Use this to select
0 + item
win32gui.SendMessage(hwnd, win32con.LB_SETCURSEL, item, 0)
_sendNotifyMessage(hwnd, win32con.LBN_SELCHANGE)
except TypeError: # Item is a string - find the index, and use that
items = getListboxItems(hwnd)
itemIndex = items.index(item)
selectListboxItem(hwnd, itemIndex)
def selectListboxItem(hwnd, item):
'''Selects a specified item in a list box control.
Arguments:
hwnd Window handle of the required list box.
item The reqired item. Either an index, of the text of the
required item.
Usage example: TODO
'''
try: # item is an index Use this to select
0 + item
win32gui.SendMessage(hwnd, win32con.LB_SETCURSEL, item, 0)
_sendNotifyMessage(hwnd, win32con.LBN_SELCHANGE)
except TypeError: # Item is a string - find the index, and use that
items = getListboxItems(hwnd)
itemIndex = items.index(item)
selectListboxItem(hwnd, itemIndex)
def CmdTypeListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
pos = self.typelb.GetCurSel()
if pos >= 0:
self.memberlb.ResetContent()
self.typeinfo = self.tlb.GetTypeInfo(pos)
self.attr = self.typeinfo.GetTypeAttr()
for i in range(self.attr[7]):
id = self.typeinfo.GetVarDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
for i in range(self.attr[6]):
id = self.typeinfo.GetFuncDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
self.SetupAllInfoTypes()
return 1
def CmdMemberListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
self.paramlb.ResetContent()
pos = self.memberlb.GetCurSel()
realPos, isMethod = self._GetRealMemberPos(pos)
if isMethod:
id = self.typeinfo.GetFuncDesc(realPos)[0]
names = self.typeinfo.GetNames(id)
for i in range(len(names)):
if i > 0:
self.paramlb.AddString(names[i])
self.SetupAllInfoTypes()
return 1
def CmdTypeListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
pos = self.typelb.GetCurSel()
if pos >= 0:
self.memberlb.ResetContent()
self.typeinfo = self.tlb.GetTypeInfo(pos)
self.attr = self.typeinfo.GetTypeAttr()
for i in range(self.attr[7]):
id = self.typeinfo.GetVarDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
for i in range(self.attr[6]):
id = self.typeinfo.GetFuncDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
self.SetupAllInfoTypes()
return 1
def CmdMemberListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
self.paramlb.ResetContent()
pos = self.memberlb.GetCurSel()
realPos, isMethod = self._GetRealMemberPos(pos)
if isMethod:
id = self.typeinfo.GetFuncDesc(realPos)[0]
names = self.typeinfo.GetNames(id)
for i in range(len(names)):
if i > 0:
self.paramlb.AddString(names[i])
self.SetupAllInfoTypes()
return 1
def ReloadData(self):
service = self.GetSelService()
self.listCtrl.SetRedraw(0)
self.listCtrl.ResetContent()
svcs = win32service.EnumServicesStatus(self.scm)
i = 0
self.data = []
for svc in svcs:
try:
status = ('Unknown', 'Stopped', 'Starting', 'Stopping', 'Running',
'Continuing', 'Pausing', 'Paused')[svc[2][1]]
except:
status = 'Unknown'
s = win32service.OpenService(self.scm, svc[0], win32service.SERVICE_ALL_ACCESS)
cfg = win32service.QueryServiceConfig(s)
try:
startup = ('Boot', 'System', 'Automatic', 'Manual', 'Disabled')[cfg[1]]
except:
startup = 'Unknown'
win32service.CloseServiceHandle(s)
# svc[2][2] control buttons
pos = self.listCtrl.AddString(str(svc[1]) + '\t' + status + '\t' + startup)
self.listCtrl.SetItemData(pos, i)
self.data.append(tuple(svc[2]) + (svc[1], svc[0], ))
i = i + 1
if service and service[1] == svc[0]:
self.listCtrl.SetCurSel(pos)
self.OnListEvent(self.IDC_LIST, win32con.LBN_SELCHANGE)
self.listCtrl.SetRedraw(1)
def OnListEvent(self, id, code):
if code == win32con.LBN_SELCHANGE or code == win32con.LBN_SELCANCEL:
pos = self.listCtrl.GetCurSel()
if pos >= 0:
data = self.data[self.listCtrl.GetItemData(pos)][2]
canstart = (self.data[self.listCtrl.GetItemData(pos)][1] == win32service.SERVICE_STOPPED)
else:
data = 0
canstart = 0
self.GetDlgItem(self.IDC_START).EnableWindow(canstart)
self.GetDlgItem(self.IDC_STOP).EnableWindow(data & win32service.SERVICE_ACCEPT_STOP)
self.GetDlgItem(self.IDC_PAUSE).EnableWindow(data & win32service.SERVICE_ACCEPT_PAUSE_CONTINUE)
self.GetDlgItem(self.IDC_CONTINUE).EnableWindow(data & win32service.SERVICE_ACCEPT_PAUSE_CONTINUE)
def OnListCommand(self, id, code):
if code==win32con.LBN_SELCHANGE:
style = self.GetSelectedStyle()
self.UpdateUIForStyle(style)
return 1
def CmdTypeListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
pos = self.typelb.GetCurSel()
if pos >= 0:
self.memberlb.ResetContent()
self.typeinfo = self.tlb.GetTypeInfo(pos)
self.attr = self.typeinfo.GetTypeAttr()
for i in range(self.attr[7]):
id = self.typeinfo.GetVarDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
for i in range(self.attr[6]):
id = self.typeinfo.GetFuncDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
self.SetupAllInfoTypes()
return 1
def CmdMemberListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
self.paramlb.ResetContent()
pos = self.memberlb.GetCurSel()
realPos, isMethod = self._GetRealMemberPos(pos)
if isMethod:
id = self.typeinfo.GetFuncDesc(realPos)[0]
names = self.typeinfo.GetNames(id)
for i in range(len(names)):
if i > 0:
self.paramlb.AddString(names[i])
self.SetupAllInfoTypes()
return 1
def OnListCommand(self, id, code):
if code==win32con.LBN_SELCHANGE:
style = self.GetSelectedStyle()
self.UpdateUIForStyle(style)
return 1
def ReloadData(self):
service = self.GetSelService()
self.listCtrl.SetRedraw(0)
self.listCtrl.ResetContent()
svcs = win32service.EnumServicesStatus(self.scm)
i = 0
self.data = []
for svc in svcs:
try:
status = ('Unknown', 'Stopped', 'Starting', 'Stopping', 'Running',
'Continuing', 'Pausing', 'Paused')[svc[2][1]]
except:
status = 'Unknown'
s = win32service.OpenService(self.scm, svc[0], win32service.SERVICE_ALL_ACCESS)
cfg = win32service.QueryServiceConfig(s)
try:
startup = ('Boot', 'System', 'Automatic', 'Manual', 'Disabled')[cfg[1]]
except:
startup = 'Unknown'
win32service.CloseServiceHandle(s)
# svc[2][2] control buttons
pos = self.listCtrl.AddString(str(svc[1]) + '\t' + status + '\t' + startup)
self.listCtrl.SetItemData(pos, i)
self.data.append(tuple(svc[2]) + (svc[1], svc[0], ))
i = i + 1
if service and service[1] == svc[0]:
self.listCtrl.SetCurSel(pos)
self.OnListEvent(self.IDC_LIST, win32con.LBN_SELCHANGE)
self.listCtrl.SetRedraw(1)
def OnListEvent(self, id, code):
if code == win32con.LBN_SELCHANGE or code == win32con.LBN_SELCANCEL:
pos = self.listCtrl.GetCurSel()
if pos >= 0:
data = self.data[self.listCtrl.GetItemData(pos)][2]
canstart = (self.data[self.listCtrl.GetItemData(pos)][1] == win32service.SERVICE_STOPPED)
else:
data = 0
canstart = 0
self.GetDlgItem(self.IDC_START).EnableWindow(canstart)
self.GetDlgItem(self.IDC_STOP).EnableWindow(data & win32service.SERVICE_ACCEPT_STOP)
self.GetDlgItem(self.IDC_PAUSE).EnableWindow(data & win32service.SERVICE_ACCEPT_PAUSE_CONTINUE)
self.GetDlgItem(self.IDC_CONTINUE).EnableWindow(data & win32service.SERVICE_ACCEPT_PAUSE_CONTINUE)
def CmdTypeListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
pos = self.typelb.GetCurSel()
if pos >= 0:
self.memberlb.ResetContent()
self.typeinfo = self.tlb.GetTypeInfo(pos)
self.attr = self.typeinfo.GetTypeAttr()
for i in range(self.attr[7]):
id = self.typeinfo.GetVarDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
for i in range(self.attr[6]):
id = self.typeinfo.GetFuncDesc(i)[0]
self.memberlb.AddString(self.typeinfo.GetNames(id)[0])
self.SetupAllInfoTypes()
return 1
def CmdMemberListbox(self, id, code):
if code == win32con.LBN_SELCHANGE:
self.paramlb.ResetContent()
pos = self.memberlb.GetCurSel()
realPos, isMethod = self._GetRealMemberPos(pos)
if isMethod:
id = self.typeinfo.GetFuncDesc(realPos)[0]
names = self.typeinfo.GetNames(id)
for i in range(len(names)):
if i > 0:
self.paramlb.AddString(names[i])
self.SetupAllInfoTypes()
return 1