Building basic dialog in Windows?
Larry Bates
lbates at swamisoft.com
Tue Aug 24 16:04:38 EDT 2004
Here's a class for Windows progress bar:
#
# Progress bar control example
#
# PyCProgressCtrl encapsulates the MFC CProgressCtrl class. To use it,
# you:
#
# - Create the control with win32ui.CreateProgressCtrl()
# - Create the control window with PyCProgressCtrl.CreateWindow()
# - Initialize the range if you want it to be other than (0, 100) using
# PyCProgressCtrl.SetRange()
# - Either:
# - Set the step size with PyCProgressCtrl.SetStep(), and
# - Increment using PyCProgressCtrl.StepIt()
# or:
# - Set the amount completed using PyCProgressCtrl.SetPos()
#
# Example and progress bar code courtesy of KDL Technologies, Ltd., Hong
Kong SAR, China.
#
from pywin.mfc import dialog
import win32ui
import win32con
import time
def MakeDlgTemplate():
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
dlg = [["Progress bar",
(0, 0, w, h),
style,
None,
(8, "MS Sans Serif")],
]
return dlg
class TestDialog(dialog.Dialog):
def OnInitDialog(self):
rc = dialog.Dialog.OnInitDialog(self)
self.pbar = win32ui.CreateProgressCtrl()
self.pbar.CreateWindow (win32con.WS_CHILD |
win32con.WS_VISIBLE,
(10, 10, 310, 24),
self, 1001)
return rc
def demo():
d = TestDialog (MakeDlgTemplate())
d.CreateWindow ()
for i in xrange(100):
d.pbar.SetPos(i)
time.sleep(0.1)
d.OnCancel()
if __name__=='__main__':
demo()
Here's some code for a file dialog box that I stripped from
an application that asks user to select an export file
from TimePilot payroll application (the files are always
called TimePilot.mdb):
import win32ui
import win32con
#---------------------------------------------------------------------------
----
# Display a file dialog box that allows the user to browse to the
TimePilot.mdb
# file that they wish to export.
#---------------------------------------------------------------------------
----
timepilotdatapath="C:\TimePilot"
f=win32ui.CreateFileDialog(1, None, "TimePilot.mdb", 0,
'TimePilot databases|TimePilot.mdb||')
f.SetOFNInitialDir(timepilotdatapath)
f.SetOFNTitle("Timepilot Extracted Data")
result=f.DoModal()
if result == win32con.IDCANCEL:
emsg="Cancel button pressed during TimePilot.mdb file selection,
aborting"
sys.exit(emsg)
mdb_path=f.GetPathName()
HTH,
Larry Bates
Syscon, Inc.
"Fred" <nobody at nowhere.com> wrote in message
news:bp0ni09fofpahse8uoa4l3hdmq5lmi61rr at 4ax.com...
> Hi,
>
> I'd like to turn a command-line script into a Windows GUI app
> using the native widgets so as to reduce the size of the binary (ie.
> no QT, wxWidgets, et al.)
>
> I came up with the following list of tools to access the Win32 API:
>
> - PythonWin (MFC) http://www.python.org/windows/pythonwin/
> - ctypes http://starship.python.net/crew/theller/ctypes/
> - EasyDialogs for Windows
> http://www.averdevelopment.com/python/EasyDialogs.html
> - DynWin http://www.nightmare.com/~rushing/dynwin/
> - sdk32 - Partial Python wrap of the Win32 Platform SDK
> http://www.object-craft.com.au/projects/sdk32/
>
> Does someone have a sample on how to display an OK/Cancel dialog with
> a label + progress bar? Should I look at other tools?
>
> Thank you
> Fred.
More information about the Python-list
mailing list