Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,116 @@
# The property page to define generic IDE options for Pythonwin
from pywin.mfc import dialog
from pywin.framework import interact
import win32ui
import win32con
buttonControlMap = {
win32ui.IDC_BUTTON1: win32ui.IDC_EDIT1,
win32ui.IDC_BUTTON2: win32ui.IDC_EDIT2,
win32ui.IDC_BUTTON3: win32ui.IDC_EDIT3,
}
class OptionsPropPage(dialog.PropertyPage):
def __init__(self):
dialog.PropertyPage.__init__(self, win32ui.IDD_PP_IDE)
self.AddDDX(win32ui.IDC_CHECK1, "bShowAtStartup")
self.AddDDX(win32ui.IDC_CHECK2, "bDocking")
self.AddDDX(win32ui.IDC_EDIT4, 'MRUSize', "i")
def OnInitDialog(self):
edit = self.GetDlgItem(win32ui.IDC_EDIT1)
format = eval(win32ui.GetProfileVal(interact.sectionProfile, interact.STYLE_INTERACTIVE_PROMPT, str(interact.formatInput)))
edit.SetDefaultCharFormat(format)
edit.SetWindowText("Input Text")
edit = self.GetDlgItem(win32ui.IDC_EDIT2)
format = eval(win32ui.GetProfileVal(interact.sectionProfile, interact.STYLE_INTERACTIVE_OUTPUT, str(interact.formatOutput)))
edit.SetDefaultCharFormat(format)
edit.SetWindowText("Output Text")
edit = self.GetDlgItem(win32ui.IDC_EDIT3)
format = eval(win32ui.GetProfileVal(interact.sectionProfile, interact.STYLE_INTERACTIVE_ERROR, str(interact.formatOutputError)))
edit.SetDefaultCharFormat(format)
edit.SetWindowText("Error Text")
self['bShowAtStartup'] = interact.LoadPreference("Show at startup", 1)
self['bDocking'] = interact.LoadPreference("Docking", 0)
self['MRUSize'] = win32ui.GetProfileVal("Settings","Recent File List Size", 10)
# Hook the button clicks.
self.HookCommand(self.HandleCharFormatChange, win32ui.IDC_BUTTON1)
self.HookCommand(self.HandleCharFormatChange, win32ui.IDC_BUTTON2)
self.HookCommand(self.HandleCharFormatChange, win32ui.IDC_BUTTON3)
# Ensure the spin control remains in range.
spinner = self.GetDlgItem(win32ui.IDC_SPIN1)
spinner.SetRange(1, 16)
return dialog.PropertyPage.OnInitDialog(self)
# Called to save away the new format tuple for the specified item.
def HandleCharFormatChange(self, id, code):
if code == win32con.BN_CLICKED:
editId = buttonControlMap.get(id)
assert editId is not None, "Format button has no associated edit control"
editControl = self.GetDlgItem(editId)
existingFormat = editControl.GetDefaultCharFormat()
flags = win32con.CF_SCREENFONTS
d=win32ui.CreateFontDialog(existingFormat, flags, None, self)
if d.DoModal()==win32con.IDOK:
cf = d.GetCharFormat()
editControl.SetDefaultCharFormat(cf)
self.SetModified(1)
return 0 # We handled this fully!
def OnOK(self):
# Handle the edit controls - get all the fonts, put them back into interact, then
# get interact to save its stuff!
controlAttrs = [
(win32ui.IDC_EDIT1, interact.STYLE_INTERACTIVE_PROMPT),
(win32ui.IDC_EDIT2, interact.STYLE_INTERACTIVE_OUTPUT),
(win32ui.IDC_EDIT3, interact.STYLE_INTERACTIVE_ERROR)]
for id, key in controlAttrs:
control = self.GetDlgItem(id)
fmt = control.GetDefaultCharFormat()
win32ui.WriteProfileVal(interact.sectionProfile, key, str(fmt))
# Save the other interactive window options.
interact.SavePreference("Show at startup", self['bShowAtStartup'])
interact.SavePreference("Docking", self['bDocking'])
# And the other options.
win32ui.WriteProfileVal("Settings","Recent File List Size", self['MRUSize'])
return 1
def ChangeFormat(self, fmtAttribute, fmt):
dlg = win32ui.CreateFontDialog(fmt)
if dlg.DoModal() != win32con.IDOK: return None
return dlg.GetCharFormat()
def OnFormatTitle(self, command, code):
fmt = self.GetFormat(interact.formatTitle)
if fmt:
formatTitle = fmt
SaveFontPreferences()
def OnFormatInput(self, command, code):
global formatInput
fmt = self.GetFormat(formatInput)
if fmt:
formatInput = fmt
SaveFontPreferences()
def OnFormatOutput(self, command, code):
global formatOutput
fmt = self.GetFormat(formatOutput)
if fmt:
formatOutput = fmt
SaveFontPreferences()
def OnFormatError(self, command, code):
global formatOutputError
fmt = self.GetFormat(formatOutputError)
if fmt:
formatOutputError = fmt
SaveFontPreferences()

View file

@ -0,0 +1,122 @@
from pywin.mfc import dialog
import win32ui, win32con, commctrl, win32api
class ListDialog (dialog.Dialog):
def __init__ (self, title, list):
dialog.Dialog.__init__ (self, self._maketemplate(title))
self.HookMessage (self.on_size, win32con.WM_SIZE)
self.HookNotify(self.OnListItemChange, commctrl.LVN_ITEMCHANGED)
self.HookCommand(self.OnListClick, win32ui.IDC_LIST1)
self.items = list
def _maketemplate(self, title):
style = win32con.WS_DLGFRAME | win32con.WS_SYSMENU | win32con.WS_VISIBLE
ls = (
win32con.WS_CHILD |
win32con.WS_VISIBLE |
commctrl.LVS_ALIGNLEFT |
commctrl.LVS_REPORT
)
bs = (
win32con.WS_CHILD |
win32con.WS_VISIBLE
)
return [ [title, (0, 0, 200, 200), style, None, (8, "MS Sans Serif")],
["SysListView32", None, win32ui.IDC_LIST1, (0, 0, 200, 200), ls],
[128, "OK", win32con.IDOK, (10, 0, 50, 14), bs | win32con.BS_DEFPUSHBUTTON],
[128, "Cancel",win32con.IDCANCEL,(0, 0, 50, 14), bs],
]
def FillList(self):
size = self.GetWindowRect()
width = size[2] - size[0] - (10)
itemDetails = (commctrl.LVCFMT_LEFT, width, "Item", 0)
self.itemsControl.InsertColumn(0, itemDetails)
index = 0
for item in self.items:
index = self.itemsControl.InsertItem(index+1, str(item), 0)
def OnListClick(self, id, code):
if code==commctrl.NM_DBLCLK:
self.EndDialog(win32con.IDOK)
return 1
def OnListItemChange(self,std, extra):
(hwndFrom, idFrom, code), (itemNotify, sub, newState, oldState, change, point, lparam) = std, extra
oldSel = (oldState & commctrl.LVIS_SELECTED)!=0
newSel = (newState & commctrl.LVIS_SELECTED)!=0
if oldSel != newSel:
try:
self.selecteditem = itemNotify
self.butOK.EnableWindow(1)
except win32ui.error:
self.selecteditem = None
def OnInitDialog (self):
rc = dialog.Dialog.OnInitDialog (self)
self.itemsControl = self.GetDlgItem(win32ui.IDC_LIST1)
self.butOK = self.GetDlgItem(win32con.IDOK)
self.butCancel = self.GetDlgItem(win32con.IDCANCEL)
self.FillList()
size = self.GetWindowRect()
self.LayoutControls(size[2]-size[0], size[3]-size[1])
self.butOK.EnableWindow(0) # wait for first selection
return rc
def LayoutControls(self, w, h):
self.itemsControl.MoveWindow((0,0,w,h-30))
self.butCancel.MoveWindow((10, h-24, 60, h-4))
self.butOK.MoveWindow((w-60, h-24, w-10, h-4))
def on_size (self, params):
lparam = params[3]
w = win32api.LOWORD(lparam)
h = win32api.HIWORD(lparam)
self.LayoutControls(w, h)
class ListsDialog(ListDialog):
def __init__(self, title, list, colHeadings = ['Item']):
ListDialog.__init__(self, title, list)
self.colHeadings = colHeadings
def FillList(self):
index = 0
size = self.GetWindowRect()
width = size[2] - size[0] - (10) - win32api.GetSystemMetrics(win32con.SM_CXVSCROLL)
numCols = len(self.colHeadings)
for col in self.colHeadings:
itemDetails = (commctrl.LVCFMT_LEFT, width/numCols, col, 0)
self.itemsControl.InsertColumn(index, itemDetails)
index = index + 1
index = 0
for items in self.items:
index = self.itemsControl.InsertItem(index+1, str(items[0]), 0)
for itemno in range(1,numCols):
item = items[itemno]
self.itemsControl.SetItemText(index, itemno, str(item))
def SelectFromList (title, lst):
dlg = ListDialog(title, lst)
if dlg.DoModal()==win32con.IDOK:
return dlg.selecteditem
else:
return None
def SelectFromLists (title, lists, headings):
dlg = ListsDialog(title, lists, headings)
if dlg.DoModal()==win32con.IDOK:
return dlg.selecteditem
else:
return None
def test():
# print SelectFromList('Single list', [1,2,3])
print(SelectFromLists('Multi-List', [ ('1',1, 'a'), ('2',2, 'b'), ('3',3, 'c' )], ['Col 1', 'Col 2']))
if __name__=='__main__':
test()

View file

@ -0,0 +1,121 @@
'''login -- PythonWin user ID and password dialog box
(Adapted from originally distributed with Mark Hammond's PythonWin -
this now replaces it!)
login.GetLogin() displays a modal "OK/Cancel" dialog box with input
fields for a user ID and password. The password field input is masked
with *'s. GetLogin takes two optional parameters, a window title, and a
default user ID. If these parameters are omitted, the title defaults to
"Login", and the user ID is left blank. GetLogin returns a (userid, password)
tuple. GetLogin can be called from scripts running on the console - i.e. you
don't need to write a full-blown GUI app to use it.
login.GetPassword() is similar, except there is no username field.
Example:
import pywin.dialogs.login
title = "FTP Login"
def_user = "fred"
userid, password = pywin.dialogs.login.GetLogin(title, def_user)
Jim Eggleston, 28 August 1996
Merged with dlgpass and moved to pywin.dialogs by Mark Hammond Jan 1998.
'''
import win32ui
import win32api
import win32con
from pywin.mfc import dialog
def MakeLoginDlgTemplate(title):
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
# Window frame and title
dlg = [ [title, (0, 0, 184, 40), style, None, (8, "MS Sans Serif")], ]
# ID label and text box
dlg.append([130, "User ID:", -1, (7, 9, 69, 9), cs | win32con.SS_LEFT])
s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
dlg.append(['EDIT', None, win32ui.IDC_EDIT1, (50, 7, 60, 12), s])
# Password label and text box
dlg.append([130, "Password:", -1, (7, 22, 69, 9), cs | win32con.SS_LEFT])
s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
dlg.append(['EDIT', None, win32ui.IDC_EDIT2, (50, 20, 60, 12), s | win32con.ES_PASSWORD])
# OK/Cancel Buttons
s = cs | win32con.WS_TABSTOP
dlg.append([128, "OK", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON])
s = win32con.BS_PUSHBUTTON | s
dlg.append([128, "Cancel", win32con.IDCANCEL, (124, 20, 50, 14), s])
return dlg
def MakePasswordDlgTemplate(title):
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
# Window frame and title
dlg = [ [title, (0, 0, 177, 45), style, None, (8, "MS Sans Serif")], ]
# Password label and text box
dlg.append([130, "Password:", -1, (7, 7, 69, 9), cs | win32con.SS_LEFT])
s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER
dlg.append(['EDIT', None, win32ui.IDC_EDIT1, (50, 7, 60, 12), s | win32con.ES_PASSWORD])
# OK/Cancel Buttons
s = cs | win32con.WS_TABSTOP | win32con.BS_PUSHBUTTON
dlg.append([128, "OK", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON])
dlg.append([128, "Cancel", win32con.IDCANCEL, (124, 22, 50, 14), s])
return dlg
class LoginDlg(dialog.Dialog):
Cancel = 0
def __init__(self, title):
dialog.Dialog.__init__(self, MakeLoginDlgTemplate(title) )
self.AddDDX(win32ui.IDC_EDIT1,'userid')
self.AddDDX(win32ui.IDC_EDIT2,'password')
def GetLogin(title='Login', userid='', password=''):
d = LoginDlg(title)
d['userid'] = userid
d['password'] = password
if d.DoModal() != win32con.IDOK:
return (None, None)
else:
return (d['userid'], d['password'])
class PasswordDlg(dialog.Dialog):
def __init__(self, title):
dialog.Dialog.__init__(self, MakePasswordDlgTemplate(title) )
self.AddDDX(win32ui.IDC_EDIT1,'password')
def GetPassword(title='Password', password=''):
d = PasswordDlg(title)
d['password'] = password
if d.DoModal()!=win32con.IDOK:
return None
return d['password']
if __name__ == "__main__":
import sys
title = 'Login'
def_user = ''
if len(sys.argv) > 1:
title = sys.argv[1]
if len(sys.argv) > 2:
def_userid = sys.argv[2]
userid, password = GetLogin(title, def_user)
if userid == password == None:
print("User pressed Cancel")
else:
print("User ID: ", userid)
print("Password:", password)
newpassword = GetPassword("Reenter just for fun", password)
if newpassword is None:
print("User cancelled")
else:
what = ""
if newpassword != password:
what = "not "
print("The passwords did %smatch" % (what))

View file

@ -0,0 +1,227 @@
# No cancel button.
from pywin.mfc import dialog
from pywin.mfc.thread import WinThread
import threading
import win32ui
import win32con
import win32api
import time
def MakeProgressDlgTemplate(caption, staticText = ""):
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)
w = 215
h = 36 # With button
h = 40
dlg = [[caption,
(0, 0, w, h),
style,
None,
(8, "MS Sans Serif")],
]
s = win32con.WS_TABSTOP | cs
dlg.append([130, staticText, 1000, (7, 7, w-7, h-32), cs | win32con.SS_LEFT])
# dlg.append([128,
# "Cancel",
# win32con.IDCANCEL,
# (w - 60, h - 18, 50, 14), s | win32con.BS_PUSHBUTTON])
return dlg
class CStatusProgressDialog(dialog.Dialog):
def __init__(self, title, msg = "", maxticks = 100, tickincr = 1):
self.initMsg = msg
templ = MakeProgressDlgTemplate(title, msg)
dialog.Dialog.__init__(self, templ)
self.maxticks = maxticks
self.tickincr = tickincr
self.pbar = None
def OnInitDialog(self):
rc = dialog.Dialog.OnInitDialog(self)
self.static = self.GetDlgItem(1000)
self.pbar = win32ui.CreateProgressCtrl()
self.pbar.CreateWindow (win32con.WS_CHILD |
win32con.WS_VISIBLE,
(10, 30, 310, 44),
self, 1001)
self.pbar.SetRange(0, self.maxticks)
self.pbar.SetStep(self.tickincr)
self.progress = 0
self.pincr = 5
return rc
def Close(self):
self.EndDialog(0)
def SetMaxTicks(self, maxticks):
if self.pbar is not None:
self.pbar.SetRange(0, maxticks)
def Tick(self):
if self.pbar is not None:
self.pbar.StepIt()
def SetTitle(self, text):
self.SetWindowText(text)
def SetText(self, text):
self.SetDlgItemText(1000, text)
def Set(self, pos, max = None):
if self.pbar is not None:
self.pbar.SetPos(pos)
if max is not None:
self.pbar.SetRange(0, max)
# a progress dialog created in a new thread - especially suitable for
# console apps with no message loop.
MYWM_SETTITLE = win32con.WM_USER+10
MYWM_SETMSG = win32con.WM_USER+11
MYWM_TICK = win32con.WM_USER+12
MYWM_SETMAXTICKS = win32con.WM_USER+13
MYWM_SET = win32con.WM_USER+14
class CThreadedStatusProcessDialog(CStatusProgressDialog):
def __init__(self, title, msg = "", maxticks = 100, tickincr = 1):
self.title = title
self.msg = msg
self.threadid = win32api.GetCurrentThreadId()
CStatusProgressDialog.__init__(self, title, msg, maxticks, tickincr)
def OnInitDialog(self):
rc = CStatusProgressDialog.OnInitDialog(self)
self.HookMessage(self.OnTitle, MYWM_SETTITLE)
self.HookMessage(self.OnMsg, MYWM_SETMSG)
self.HookMessage(self.OnTick, MYWM_TICK)
self.HookMessage(self.OnMaxTicks, MYWM_SETMAXTICKS)
self.HookMessage(self.OnSet, MYWM_SET)
return rc
def _Send(self, msg):
try:
self.PostMessage(msg)
except win32ui.error:
# the user closed the window - but this does not cancel the
# process - so just ignore it.
pass
def OnTitle(self, msg):
CStatusProgressDialog.SetTitle(self, self.title)
def OnMsg(self, msg):
CStatusProgressDialog.SetText(self, self.msg)
def OnTick(self, msg):
CStatusProgressDialog.Tick(self)
def OnMaxTicks(self, msg):
CStatusProgressDialog.SetMaxTicks(self, self.maxticks)
def OnSet(self, msg):
CStatusProgressDialog.Set(self, self.pos, self.max)
def Close(self):
assert self.threadid, "No thread!"
win32api.PostThreadMessage(self.threadid, win32con.WM_QUIT, 0, 0)
def SetMaxTicks(self, maxticks):
self.maxticks = maxticks
self._Send(MYWM_SETMAXTICKS)
def SetTitle(self, title):
self.title = title
self._Send(MYWM_SETTITLE)
def SetText(self, text):
self.msg = text
self._Send(MYWM_SETMSG)
def Tick(self):
self._Send(MYWM_TICK)
def Set(self, pos, max = None):
self.pos = pos
self.max = max
self._Send(MYWM_SET)
class ProgressThread(WinThread):
def __init__(self, title, msg = "", maxticks = 100, tickincr = 1):
self.title = title
self.msg = msg
self.maxticks = maxticks
self.tickincr = tickincr
self.dialog = None
WinThread.__init__(self)
self.createdEvent = threading.Event()
def InitInstance(self):
self.dialog = CThreadedStatusProcessDialog( self.title, self.msg, self.maxticks, self.tickincr)
self.dialog.CreateWindow()
try:
self.dialog.SetForegroundWindow()
except win32ui.error:
pass
self.createdEvent.set()
return WinThread.InitInstance(self)
def ExitInstance(self):
return 0
def StatusProgressDialog(title, msg = "", maxticks = 100, parent = None):
d = CStatusProgressDialog (title, msg, maxticks)
d.CreateWindow (parent)
return d
def ThreadedStatusProgressDialog(title, msg = "", maxticks = 100):
t = ProgressThread(title, msg, maxticks)
t.CreateThread()
# Need to run a basic "PumpWaitingMessages" loop just incase we are
# running inside Pythonwin.
# Basic timeout incase things go terribly wrong. Ideally we should use
# win32event.MsgWaitForMultipleObjects(), but we use a threading module
# event - so use a dumb strategy
end_time = time.time() + 10
while time.time() < end_time:
if t.createdEvent.isSet():
break
win32ui.PumpWaitingMessages()
time.sleep(0.1)
return t.dialog
def demo():
d = StatusProgressDialog("A Demo", "Doing something...")
import win32api
for i in range(100):
if i == 50:
d.SetText("Getting there...")
if i==90:
d.SetText("Nearly done...")
win32api.Sleep(20)
d.Tick()
d.Close()
def thread_demo():
d = ThreadedStatusProgressDialog("A threaded demo", "Doing something")
import win32api
for i in range(100):
if i == 50:
d.SetText("Getting there...")
if i==90:
d.SetText("Nearly done...")
win32api.Sleep(20)
d.Tick()
d.Close()
if __name__=='__main__':
thread_demo()
#demo()