def _accessible_object_from_window(self, hwnd):
"""???????AccessibleObject
:type hwnd: int
:param hwnd: ??
:raises: ValueError
:rtype: comtypes.gen.Accessibility.IAccessible
"""
if not win32gui.IsWindow(hwnd):
raise ValueError("window(%s) is not valid!" % hwnd)
OBJID_WINDOW = 0
OBJID_CLIENT = -4
if (win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE) & win32con.WS_CHILDWINDOW) > 0:
objID = OBJID_CLIENT
else:
objID = OBJID_WINDOW
accObj = ctypes.POINTER(IAccessible)()
ctypes.oledll.oleacc.AccessibleObjectFromWindow(hwnd,
objID,
ctypes.byref(IAccessible._iid_),
ctypes.byref(accObj))
return accObj
python类GWL_STYLE的实例源码
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 add_titlebar(hwnd):
"""
Sets the window style to include a titlebar if it doesn't have one.
Args:
hwnd (int): The window handler.
"""
style = wg.GetWindowLong(hwnd, wc.GWL_STYLE)
style |= wc.WS_CAPTION
wg.SetWindowLong(hwnd, wc.GWL_STYLE, style)
maximize(hwnd)
restore(hwnd)
def remove_titlebar(hwnd):
"""
Sets window style to caption (no titlebar).
Args:
hwnd (int): The window handler.
"""
style = wg.GetWindowLong(hwnd, wc.GWL_STYLE)
style &= ~wc.WS_CAPTION
wg.SetWindowLong(hwnd, wc.GWL_STYLE, style)
maximize(hwnd)
restore(hwnd)
def hide_extra_ui(self, hwnd=None, remove=True):
"""
:param hwnd: Hwnd to remove all styling from. If not supplied, then the default hwnd is used
:param remove: If true: Removes all styling. If false: Adds back the removed styles
:return: NoneType
"""
logging.debug('Trying to manipulate UI')
if hwnd is None:
hwnd = self.get_hwnd()
style = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
if remove:
logging.debug('Removing UI')
style = style | win32con.WS_POPUP
style = style & ~win32con.WS_OVERLAPPEDWINDOW
else:
logging.debug('Adding UI')
style = style & ~win32con.WS_POPUP
style = style | win32con.WS_OVERLAPPEDWINDOW
win32gui.ShowWindow(hwnd, win32con.SW_HIDE)
win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, style)
win32gui.ShowWindow(hwnd, win32con.SW_SHOW)
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)