def _UpdateUIForState(self):
"""Change the title to reflect the state of the document -
eg ReadOnly, Dirty, etc
"""
filename = self.GetPathName()
if not filename: return # New file - nothing to do
try:
# This seems necessary so the internal state of the window becomes
# "visible". without it, it is still shown, but certain functions
# (such as updating the title) dont immediately work?
self.GetFirstView().ShowWindow(win32con.SW_SHOW)
title = win32ui.GetFileTitle(filename)
except win32ui.error:
title = filename
if self._IsReadOnly():
title = title + " (read-only)"
self.SetTitle(title)
python类SW_SHOW的实例源码
def GUIAboutToInteract(self):
"Called as the GUI is about to perform any interaction with the user"
frame = win32ui.GetMainFrame()
# Remember the enabled state of our main frame
# may be disabled primarily if a modal dialog is displayed.
# Only get at enabled via GetWindowLong.
self.bFrameEnabled = frame.IsWindowEnabled()
self.oldForeground = None
fw = win32ui.GetForegroundWindow()
if fw is not frame:
self.oldForeground = fw
# fw.EnableWindow(0) Leave enabled for now?
self.oldFrameEnableState = frame.IsWindowEnabled()
frame.EnableWindow(1)
if self.inForcedGUI and not frame.IsWindowVisible():
frame.ShowWindow(win32con.SW_SHOW)
frame.UpdateWindow()
if self.curframe:
SetInteractiveContext(self.curframe.f_globals, self.curframe.f_locals)
else:
SetInteractiveContext(None, None)
self.GUIRespondDebuggerData()
def _UpdateUIForState(self):
"""Change the title to reflect the state of the document -
eg ReadOnly, Dirty, etc
"""
filename = self.GetPathName()
if not filename: return # New file - nothing to do
try:
# This seems necessary so the internal state of the window becomes
# "visible". without it, it is still shown, but certain functions
# (such as updating the title) dont immediately work?
self.GetFirstView().ShowWindow(win32con.SW_SHOW)
title = win32ui.GetFileTitle(filename)
except win32ui.error:
title = filename
if self._IsReadOnly():
title = title + " (read-only)"
self.SetTitle(title)
def GUIAboutToInteract(self):
"Called as the GUI is about to perform any interaction with the user"
frame = win32ui.GetMainFrame()
# Remember the enabled state of our main frame
# may be disabled primarily if a modal dialog is displayed.
# Only get at enabled via GetWindowLong.
self.bFrameEnabled = frame.IsWindowEnabled()
self.oldForeground = None
fw = win32ui.GetForegroundWindow()
if fw is not frame:
self.oldForeground = fw
# fw.EnableWindow(0) Leave enabled for now?
self.oldFrameEnableState = frame.IsWindowEnabled()
frame.EnableWindow(1)
if self.inForcedGUI and not frame.IsWindowVisible():
frame.ShowWindow(win32con.SW_SHOW)
frame.UpdateWindow()
if self.curframe:
SetInteractiveContext(self.curframe.f_globals, self.curframe.f_locals)
else:
SetInteractiveContext(None, None)
self.GUIRespondDebuggerData()
def Show(self):
win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def OpenHelpFile(fileName, helpCmd = None, helpArg = None):
"Open a help file, given a full path"
# default help arg.
win32ui.DoWaitCursor(1)
try:
if helpCmd is None: helpCmd = win32con.HELP_CONTENTS
ext = os.path.splitext(fileName)[1].lower()
if ext == ".hlp":
win32api.WinHelp( win32ui.GetMainFrame().GetSafeHwnd(), fileName, helpCmd, helpArg)
# XXX - using the htmlhelp API wreaks havoc with keyboard shortcuts
# so we disable it, forcing ShellExecute, which works fine (but
# doesn't close the help file when Pythonwin is closed.
# Tom Heller also points out http://www.microsoft.com/mind/0499/faq/faq0499.asp,
# which may or may not be related.
elif 0 and ext == ".chm":
import win32help
global htmlhelp_handle
helpCmd = html_help_command_translators.get(helpCmd, helpCmd)
#frame = win32ui.GetMainFrame().GetSafeHwnd()
frame = 0 # Dont want it overlapping ours!
if htmlhelp_handle is None:
htmlhelp_hwnd, htmlhelp_handle = win32help.HtmlHelp(frame, None, win32help.HH_INITIALIZE)
win32help.HtmlHelp(frame, fileName, helpCmd, helpArg)
else:
# Hope that the extension is registered, and we know what to do!
win32api.ShellExecute(0, "open", fileName, None, "", win32con.SW_SHOW)
return fileName
finally:
win32ui.DoWaitCursor(-1)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def OpenHelpFile(fileName, helpCmd = None, helpArg = None):
"Open a help file, given a full path"
# default help arg.
win32ui.DoWaitCursor(1)
try:
if helpCmd is None: helpCmd = win32con.HELP_CONTENTS
ext = os.path.splitext(fileName)[1].lower()
if ext == ".hlp":
win32api.WinHelp( win32ui.GetMainFrame().GetSafeHwnd(), fileName, helpCmd, helpArg)
# XXX - using the htmlhelp API wreaks havoc with keyboard shortcuts
# so we disable it, forcing ShellExecute, which works fine (but
# doesn't close the help file when Pythonwin is closed.
# Tom Heller also points out http://www.microsoft.com/mind/0499/faq/faq0499.asp,
# which may or may not be related.
elif 0 and ext == ".chm":
import win32help
global htmlhelp_handle
helpCmd = html_help_command_translators.get(helpCmd, helpCmd)
#frame = win32ui.GetMainFrame().GetSafeHwnd()
frame = 0 # Dont want it overlapping ours!
if htmlhelp_handle is None:
htmlhelp_hwnd, htmlhelp_handle = win32help.HtmlHelp(frame, None, win32help.HH_INITIALIZE)
win32help.HtmlHelp(frame, fileName, helpCmd, helpArg)
else:
# Hope that the extension is registered, and we know what to do!
win32api.ShellExecute(0, "open", fileName, None, "", win32con.SW_SHOW)
return fileName
finally:
win32ui.DoWaitCursor(-1)
def ShowDW(self, bShow):
if bShow:
self.toolbar.ShowWindow(win32con.SW_SHOW)
else:
self.toolbar.ShowWindow(win32con.SW_HIDE)
def focus_window(hwnd):
"""
Focuses the given window.
Args:
hwnd (int): The window handler.
"""
wg.ShowWindow(hwnd, wc.SW_SHOW)
wg.ShowWindow(hwnd, wc.SW_SHOWNOACTIVATE)
wg.SetForegroundWindow(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)
def is_win_ok(self,hwnd,starttext,lb_dx='869',lb_dy='38',win_dx='',win_dy=''):
#print "*********is_win_ok function**********"
#print "*********is_win_ok function starttext**********",starttext
if len(win_dx)>0:
self.wdx = string.atoi(win_dx)
if len(win_dy)>0:
self.wdy = string.atoi(win_dy)
s = win32gui.GetWindowText(hwnd)
#print s
if s.startswith(starttext):
#print "*********is_win_ok function s**********",s
#print (s)
dlg=win32gui.FindWindow(None,s)
time.sleep(1)
#win32gui.ShowWindow(dlg,win32con.SW_SHOWMAXIMIZED)
win32gui.ShowWindow(dlg,win32con.SW_SHOW)
time.sleep(1)
#print 'self.wdx,self.wdy:',self.wdx,self.wdy
#win32gui.MoveWindow(dlg,0,0,self.wdx,self.wdy,1)
time.sleep(1)
win32gui.SetForegroundWindow(dlg)
time.sleep(1)
#win32gui.ShowWindow(dlg,win32con.SW_SHOWMAXIMIZED)
win32gui.ShowWindow(dlg,win32con.SW_SHOW)
time.sleep(1)
#self.Mouse_LB(lb_dx,lb_dy)
global MAIN_HWND
MAIN_HWND = hwnd
return None
return 1
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)