def MakeTransparent(self, amount):
if os.name == 'nt': # could substitute: sys.platform == 'win32'
hwnd = self.GetHandle()
_winlib = win32api.LoadLibrary("user32")
pSetLayeredWindowAttributes = win32api.GetProcAddress(
_winlib, "SetLayeredWindowAttributes")
if pSetLayeredWindowAttributes is None:
return
exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
if 0 == (exstyle & 0x80000):
exstyle |= win32con.WS_EX_LAYERED | win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_TRANSPARENT
win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle)
win32gui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
else:
print('#### OS Platform must be MS Windows')
self.Destroy()
python类GetWindowLong()的实例源码
def OnInitialUpdate(self):
hwnd = self._obj_.GetSafeHwnd()
style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style & ~commctrl.LVS_TYPEMASK) | commctrl.LVS_REPORT);
itemDetails = (commctrl.LVCFMT_LEFT, 100, "Name", 0)
self.InsertColumn(0, itemDetails)
itemDetails = (commctrl.LVCFMT_LEFT, 500, "Data", 0)
self.InsertColumn(1, itemDetails)
def SetStyle(self, newStyle):
hwnd = self.listControl.GetSafeHwnd()
style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style | newStyle) )
def OnInitialUpdate(self):
hwnd = self._obj_.GetSafeHwnd()
style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style & ~commctrl.LVS_TYPEMASK) | commctrl.LVS_REPORT);
itemDetails = (commctrl.LVCFMT_LEFT, 100, "Name", 0)
self.InsertColumn(0, itemDetails)
itemDetails = (commctrl.LVCFMT_LEFT, 500, "Data", 0)
self.InsertColumn(1, itemDetails)
def SetStyle(self, newStyle):
hwnd = self.listControl.GetSafeHwnd()
style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style | newStyle) )
def _sendNotifyMessage(hwnd, nofifyMessage):
"""Send a notify message to a control."""
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def remove_taskbar_button(self):
"""Hide window from taskbar and ALT+TAB dialog."""
win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
win32api.SetWindowLong(
self.hwnd, win32con.GWL_EXSTYLE,
win32api.GetWindowLong(self.hwnd, win32con.GWL_EXSTYLE)
| win32con.WS_EX_NOACTIVATE
| win32con.WS_EX_TOOLWINDOW)
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
winGuiAuto_bak.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def _sendNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
winGuiAuto.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def _sendNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def _sendNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def _postNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.PostMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def EditValue(self, item):
# Edit the current value
class EditDialog(dialog.Dialog):
def __init__(self, item):
self.item = item
dialog.Dialog.__init__(self, win32ui.IDD_LARGE_EDIT)
def OnInitDialog(self):
self.SetWindowText("Enter new value")
self.GetDlgItem(win32con.IDCANCEL).ShowWindow(win32con.SW_SHOW)
self.edit = self.GetDlgItem(win32ui.IDC_EDIT1)
# Modify the edit windows style
style = win32api.GetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE)
style = style & (~win32con.ES_WANTRETURN)
win32api.SetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE, style)
self.edit.SetWindowText(str(self.item))
self.edit.SetSel(-1)
return dialog.Dialog.OnInitDialog(self)
def OnDestroy(self,msg):
self.newvalue = self.edit.GetWindowText()
try:
index = self.GetNextItem(-1, commctrl.LVNI_SELECTED)
except win32ui.error:
return # No item selected.
if index==0:
keyVal = ""
else:
keyVal = self.GetItemText(index,0)
# Query for a new value.
try:
newVal = self.GetItemsCurrentValue(item, keyVal)
except TypeError, details:
win32ui.MessageBox(details)
return
d = EditDialog(newVal)
if d.DoModal()==win32con.IDOK:
try:
self.SetItemsCurrentValue(item, keyVal, d.newvalue)
except win32api.error, exc:
win32ui.MessageBox("Error setting value\r\n\n%s" % exc.strerror)
self.UpdateForRegItem(item)
def EditValue(self, item):
# Edit the current value
class EditDialog(dialog.Dialog):
def __init__(self, item):
self.item = item
dialog.Dialog.__init__(self, win32ui.IDD_LARGE_EDIT)
def OnInitDialog(self):
self.SetWindowText("Enter new value")
self.GetDlgItem(win32con.IDCANCEL).ShowWindow(win32con.SW_SHOW)
self.edit = self.GetDlgItem(win32ui.IDC_EDIT1)
# Modify the edit windows style
style = win32api.GetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE)
style = style & (~win32con.ES_WANTRETURN)
win32api.SetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE, style)
self.edit.SetWindowText(str(self.item))
self.edit.SetSel(-1)
return dialog.Dialog.OnInitDialog(self)
def OnDestroy(self,msg):
self.newvalue = self.edit.GetWindowText()
try:
index = self.GetNextItem(-1, commctrl.LVNI_SELECTED)
except win32ui.error:
return # No item selected.
if index==0:
keyVal = ""
else:
keyVal = self.GetItemText(index,0)
# Query for a new value.
try:
newVal = self.GetItemsCurrentValue(item, keyVal)
except TypeError as details:
win32ui.MessageBox(details)
return
d = EditDialog(newVal)
if d.DoModal()==win32con.IDOK:
try:
self.SetItemsCurrentValue(item, keyVal, d.newvalue)
except win32api.error as exc:
win32ui.MessageBox("Error setting value\r\n\n%s" % exc.strerror)
self.UpdateForRegItem(item)
def run(self, edit):
global websocketHandler
#return
if websocketHandler.ready is False:
sublime.error_message("InstaGoogling: No connection ready! " + DEFAULT_ERROR_ADVICE)
return
selected_text = ""
for region in self.view.sel():
if not region.empty():
# Get the selected text
selected_text = self.view.substr(region)
lang = re.search('(?<=source\.)[^. ]+', self.view.scope_name(region.a))
if lang != None:
selected_text += " " + lang.group(0)
x, y = self.view.text_to_layout(self.view.visible_region().a)
offsetx, offsety = self.view.window_to_layout((0,0))
view_width, view_height = self.view.viewport_extent()
x -= offsetx
y -= offsety
w = int(round(view_width * 0.5))
h = view_height + 10
if w > 540:
w = 540
x += view_width - w
# y += 3
hwnd = self.view.window().hwnd()
style = win32api.GetWindowLong(hwnd , win32con.GWL_STYLE)
if style & win32con.WS_CAPTION != 0:
y += 22
if self.view.window().is_menu_visible():
y += 20
# Lets just offset from the right edge of the screen instead
if isWindows:
from win32api import GetSystemMetrics
screenWidth = GetSystemMetrics(0)
# 20 so scroll bar is still visible
x = screenWidth - w - 15
msg = {
"request": "open",
"position": {"x": x, "y": y},
"size": {"width": w, "height": h},
"search": selected_text
}
jsonmsg = json.dumps(msg)
websocketHandler.sendMessage(jsonmsg)
print("Sending JSON message")
setSettingIsOpen(True)