S
Stevie_mac
OK, 1st off, I'm brand new to python so all help is appreciated. Right...
Lets say I want a class called Window. It will have some functions namely DoModal()
Now this class is inherited in MyClass
What is wrong with this?...
import win32con, win32ui
from pywin.mfc import dialog #, window
class Window:
def MakeDlgTemplate(self):
style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION |
win32con.WS_SYSMENU | win32con.DS_SETFONT
dlg = [ ["My Dialog", (0, 0, 100, 100), style, None, (8, "MS Sans Serif")], ]
s = win32con.BS_PUSHBUTTON | win32con.WS_CHILD | win32con.WS_VISIBLE
dlg.append([128, "Cancel", win32con.IDCANCEL, (55, 80, 40, 16), s])
return dlg
def DoModal(self):
mw = win32ui.CreateDialogIndirect( self.MakeDlgTemplate() )
mw.DoModal()
w = Window()
w.DoModal()
^ ^ ^ This Works ^ ^ ^
but if I disable w = Window() & w.DoModal() and derive from this class . . .
# file test.py #
import mywindow
class MyClass(mywindow.Window):
def Show(self):
self.DoModal()
t = MyClass()
t.Show()
.. . . I get
NameError: global name 'MakeDlgTemplate' is not defined ???
another 1 I managed to clear up was . . .
TypeError: Show() takes no arguments (1 given)
.. . . until I added 'self' to the Show function ???
I really am struggling with this - some real clarity is needed - can anyone explain the rules (I've read stuff &
dissected samples, but I still struggle when it comes to this. If someone can clear this up for me, I should be flying
as I am familiar with the concepts of OOP)
I'm also struggling with other things like...
Where do I save .py files?
Will 'import' find my files where ever they are? (obviously not but...)
What basic should be considerations when deriving classes?
any help will be greatly appreciated - Ta Stevie_Mac
Lets say I want a class called Window. It will have some functions namely DoModal()
Now this class is inherited in MyClass
What is wrong with this?...
import win32con, win32ui
from pywin.mfc import dialog #, window
class Window:
def MakeDlgTemplate(self):
style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION |
win32con.WS_SYSMENU | win32con.DS_SETFONT
dlg = [ ["My Dialog", (0, 0, 100, 100), style, None, (8, "MS Sans Serif")], ]
s = win32con.BS_PUSHBUTTON | win32con.WS_CHILD | win32con.WS_VISIBLE
dlg.append([128, "Cancel", win32con.IDCANCEL, (55, 80, 40, 16), s])
return dlg
def DoModal(self):
mw = win32ui.CreateDialogIndirect( self.MakeDlgTemplate() )
mw.DoModal()
w = Window()
w.DoModal()
^ ^ ^ This Works ^ ^ ^
but if I disable w = Window() & w.DoModal() and derive from this class . . .
# file test.py #
import mywindow
class MyClass(mywindow.Window):
def Show(self):
self.DoModal()
t = MyClass()
t.Show()
.. . . I get
NameError: global name 'MakeDlgTemplate' is not defined ???
another 1 I managed to clear up was . . .
TypeError: Show() takes no arguments (1 given)
.. . . until I added 'self' to the Show function ???
I really am struggling with this - some real clarity is needed - can anyone explain the rules (I've read stuff &
dissected samples, but I still struggle when it comes to this. If someone can clear this up for me, I should be flying
as I am familiar with the concepts of OOP)
I'm also struggling with other things like...
Where do I save .py files?
Will 'import' find my files where ever they are? (obviously not but...)
What basic should be considerations when deriving classes?
any help will be greatly appreciated - Ta Stevie_Mac