On 14/06/2010 08:53, Anthony wrote:
Hi Michael
Sorry for the late reply - only got back to my email this morning :-)
I tried to close the form - but when doing that - the whole
application closed - I think this was mainly due to the fact that that
form was seen as the "main form"??
I thought closing the whole application was what you wanted to do? In
your original email you asked:
The program runs fine - except that when I close the MainForm form
- the application is still running. I know it's because a login.py
object is hidden. What I'm asking is how construct the programming in
such a way that this does not happen - that when the second form is
closed - the application closes;
So now the application closing is a problem?
All the best,
Michael
Sorry about this real noob question - but I'm just starting out - and
this is very frustrating for me, I know it's probably something stupid
that I'm doing! Let me post my code here - and see what you can see!
Here is my code
Program.py
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
#clr.AddReference('System.Data.SQLite')
#clr.AddReference('Ironpython')
#clr.AddReference('System.Security.Policy')
from System.Security.Policy import Hash
from System.Data.SQLite import *
import sys
sys.path.append("C:\Python26\Lib")
sys.path.append("C:\Program Files\IronPython 2.6\Lib")
from System.Windows.Forms import Application
import Log_In
import MainForm
import sqlite3
Application.EnableVisualStyles()
#form = MainForm.Log_In()
form = Log_In.Log_In()
Application.Run(form)
**********************************************
Log_In.py
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
import MainForm
#import sqlite3
#import System.Data.SQLite
class Log_In(Form):
def __init__(self):
self.InitializeComponent()
def InitializeComponent(self):
self._label1 = System.Windows.Forms.Label()
self._txt_Login = System.Windows.Forms.TextBox()
self._label2 = System.Windows.Forms.Label()
self._txt_pwd = System.Windows.Forms.MaskedTextBox()
self._bt_login = System.Windows.Forms.Button()
self._bt_cancel = System.Windows.Forms.Button()
self.SuspendLayout()
#
# label1
#
self._label1.Location = System.Drawing.Point(40, 116)
self._label1.Name = "label1"
self._label1.Size = System.Drawing.Size(107, 25)
self._label1.TabIndex = 0
self._label1.Text = "Login Name"
self._label1.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
#
# txt_Login
#
self._txt_Login.Location = System.Drawing.Point(173, 121)
self._txt_Login.Name = "txt_Login"
self._txt_Login.Size = System.Drawing.Size(160, 20)
self._txt_Login.TabIndex = 1
self._txt_Login.Text = "cc"
self._txt_Login.TextChanged += self.Txt_LoginTextChanged
#
# label2
#
self._label2.Location = System.Drawing.Point(40, 174)
self._label2.Name = "label2"
self._label2.Size = System.Drawing.Size(107, 22)
self._label2.TabIndex = 2
self._label2.Text = "Password"
self._label2.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
#
# txt_pwd
#
self._txt_pwd.Location = System.Drawing.Point(173, 174)
self._txt_pwd.Name = "txt_pwd"
self._txt_pwd.PasswordChar = "*"
self._txt_pwd.Size = System.Drawing.Size(160, 20)
self._txt_pwd.TabIndex = 3
#
# bt_login
#
self._bt_login.Location = System.Drawing.Point(85, 252)
self._bt_login.Name = "bt_login"
self._bt_login.Size = System.Drawing.Size(164, 41)
self._bt_login.TabIndex = 4
self._bt_login.Text = "Login"
self._bt_login.UseVisualStyleBackColor = True
self._bt_login.Click += self.Bt_loginClick
#
# bt_cancel
#
self._bt_cancel.Location = System.Drawing.Point(346, 255)
self._bt_cancel.Name = "bt_cancel"
self._bt_cancel.Size = System.Drawing.Size(165, 37)
self._bt_cancel.TabIndex = 5
self._bt_cancel.Text = "Cancel"
self._bt_cancel.UseVisualStyleBackColor = True
self._bt_cancel.Click += self.Bt_cancelClick
#
# Log_In
#
self.AcceptButton = self._bt_login
self.ClientSize = System.Drawing.Size(649, 401)
self.Controls.Add(self._bt_cancel)
self.Controls.Add(self._bt_login)
self.Controls.Add(self._txt_pwd)
self.Controls.Add(self._label2)
self.Controls.Add(self._txt_Login)
self.Controls.Add(self._label1)
self.Name = "Log_In"
self.Text = """ <summary>
Description of Class1.
</summary>
"""
self.ResumeLayout(False)
self.PerformLayout()
def Bt_loginClick(self, sender, e):
MsgBox = System.Windows.Forms.MessageBox
if self._txt_Login.Text == "test" and self._txt_pwd.Text ==
"test":
#MsgBox.Show("Welcome to the Wonderful World of Visual Basic")
MF = mf()
MF.Show()
MF.Activate()
MF.Select()
self.Hide()
#MF.SetTopLevel = "True"
else:
MsgBox.Show("UserName Or Password Incorrect")
#pass
def Txt_LoginTextChanged(self, sender, e):
pass
def Bt_cancelClick(self, sender, e):
self.Close()
class mf(MainForm.MainForm):
pass
#conn = sqlite3.connect(r"c:\tester.sqlite")
#c = conn.cursor()
#c.execute("""insert into test values (Null,'Bozz11','Crazyman11')""")
#conn.commit()
#c.close()
class encrypt_a(object):
def EncryptString(self, strEncrypted):
b = System.Text.ASCIIEncoding.ASCII.GetBytes(strEncrypted)
encryptedConnectionString = System.Convert.ToBase64String(b)
return encryptedConnectionString
def __init__(self):
pass
class decrypt_a(object):
def DecryptString(self, encrString):
b = System.Convert.FromBase64String(encrString)
decryptedConnectionString =
System.Text.ASCIIEncoding.ASCII.GetString(b)
return decryptedConnectionString
#ac = "Anthony"
#cc = encrypt_a().EncryptString(ac)
#cca = Log_In()._txt_Login.Text = "tett
*******************************************************************************
MainForm.py
import System.Drawing
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import *
import Log_In
class MainForm(Form):
def __init__(self):
#pass
self.InitializeComponent()
def InitializeComponent(self):
#xx.Close()
self._textBox1 = System.Windows.Forms.TextBox()
self.SuspendLayout()
#
# textBox1
#
self._textBox1.Location = System.Drawing.Point(129, 101)
self._textBox1.Name = "textBox1"
self._textBox1.Size = System.Drawing.Size(231, 20)
self._textBox1.TabIndex = 0
#
# MainForm
#
self.ClientSize = System.Drawing.Size(503, 356)
self.Controls.Add(self._textBox1)
self.Name = "MainForm"
self.Text = "HS&E"
self.Load += self.MainFormLoad
self.ResumeLayout(False)
#self.PerformLayout()
#self.OnFormClosing(Application.Exit())
def MainFormLoad(self, sender, e):
pass
Hope you can help out with this!
On Sun, Jun 13, 2010 at 1:52 AM, Michael Foord
<fuzzy...@voidspace.org.uk <mailto:fuzzy...@voidspace.org.uk>> wrote:
On 12/06/2010 16:22, Anthony wrote:
Hi All
Just to state - I'm a real newbie to programming & ironpython
I have an application that has 2 forms. The application gets
started in the progam.py module(btw i'm using #develop). This
calls another module - login.py. This is a login form which
validates user names/passwords. Once this is validated I _hide_
the form and call the second module - MainForm.py. The program
runs fine - except that when I close the MainForm form - the
application is still running. I know it's because a login.py
object is hidden. What I'm asking is how construct the
programming in such a way that this does not happen - that when
the second form is closed - the application closes; or is there a
better way to do this?
How about closing the login form instead of hiding it? Another way
is to handle the Closing event on your main form and close the
login form then. You can also call Application.Exit() (I believe
- this is off the top of my head so you should check) to exit the
GUI event loop.
All the best,
Michael
Regards
Anthony
_______________________________________________
Users mailing list
Users@lists.ironpython.com <mailto:Users@lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
READ CAREFULLY. By accepting and reading this email you agree, on behalf of
your employer, to release me from all obligations and waivers arising from any
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap,
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your
employer, its partners, licensors, agents and assigns, in perpetuity, without
prejudice to my ongoing rights and privileges. You further represent that you
have the authority to release me from any BOGUS AGREEMENTS on behalf of your
employer.
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
READ CAREFULLY. By accepting and reading this email you agree, on behalf of
your employer, to release me from all obligations and waivers arising from any
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap,
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your
employer, its partners, licensors, agents and assigns, in perpetuity, without
prejudice to my ongoing rights and privileges. You further represent that you
have the authority to release me from any BOGUS AGREEMENTS on behalf of your
employer.
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com