By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,869 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,869 IT Pros & Developers. It's quick & easy.

Building basic dialog in Windows?

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Fred <no****@nowhere.com> writes:
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/
You've missed venster http://venster.sf.net/

Does someone have a sample on how to display an OK/Cancel dialog with
a label + progress bar? Should I look at other tools?


I think pywin32 has what you need, the makepy utility displays such a
progress dialog when creating python wrappers for large typelibraries.

Thomas
Jul 18 '05 #2

P: n/a
On Tue, 24 Aug 2004 20:24:00 +0200, Thomas Heller <th*****@python.net>
wrote:
You've missed venster http://venster.sf.net/
Oops :-) It's still alpha and documentation barely exists, so I guess
PythonWin/pywin32 looks like a better choice.
I think pywin32 has what you need, the makepy utility displays such a
progress dialog when creating python wrappers for large typelibraries.


OK, I'll check it out. It seems like pywin32 is meant for C++
developers who are already proficient with MFC, and the only
documentation is pretty much the scripts that comes with the software,
but I'll try to figure it out and extract what I need.

Thank you
Fred.
Jul 18 '05 #3

P: n/a
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" <no****@nowhere.com> wrote in message
news:bp********************************@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.

Jul 18 '05 #4

P: n/a
On Tue, 24 Aug 2004 20:49:29 +0200, Fred <no****@nowhere.com> wrote:
OK, I'll check it out. It seems like pywin32 is meant for C++
developers who are already proficient with MFC, and the only
documentation is pretty much the scripts that comes with the software,
but I'll try to figure it out and extract what I need.


After comparing the scripts under \Demo, here's how to display a basic
dialog in Windows with PythonWin/PyWin32, with a label, and two
pushbuttons, OK/Cancel. When you click on OK, the text of the label
changes, and the OK button is disabled:

from pywin.mfc import dialog
import win32con

dlgStatic = 130
dlgButton = 128

class Mydialog(dialog.Dialog):
def OnInitDialog(self):
rc = dialog.Dialog.OnInitDialog(self)
return rc

def OnOK(self):
label=self.GetDlgItem(dlgStatic)
label.SetWindowText("Text changed")
button=self.GetDlgItem(win32con.IDOK)
button.EnableWindow(0)

def OnCancel(self):
self.Cancel = 1
self._obj_.OnCancel()

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
s = win32con.WS_TABSTOP | cs
w = 184
h = 40

dlg = [["PyWin32",(0, 0, w, h), style, None, (8, "MS Sans
Serif")],]

dlg.append([dlgStatic, "Click on OK", dlgStatic, (7, 5, 69, 9), cs |
win32con.SS_LEFT])
dlg.append([dlgButton, "OK", win32con.IDOK, (7, 20, 50, 14), s |
win32con.BS_DEFPUSHBUTTON])
s = win32con.BS_PUSHBUTTON | s
dlg.append([dlgButton, "Cancel", win32con.IDCANCEL, (124, 20, 50, 14),
s])

d = Mydialog(dlg)
d.DoModal()

My .15E/.20$
Fred.
Jul 18 '05 #5

P: n/a
On Tue, 24 Aug 2004 15:04:38 -0500, "Larry Bates"
<lb****@swamisoft.com> wrote:
(snip)

Thx Larry :-)

Fred.
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.