473,788 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wx.Dialog subclass instantiates my dbServer class

bartonc
6,596 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. #Boa:Dialog:DBConnectDialog
  2.  
  3. import wx
  4.  
  5. import wxdbtools as db
  6.  
  7. def create(parent):
  8.     return DBConnectDialog(parent)
  9.  
  10. [wxID_DBCONNECTDIALOG, wxID_DBCONNECTDIALOGCANCELBTN,
  11.  wxID_DBCONNECTDIALOGCONNECTBTN, wxID_DBCONNECTDIALOGDATABASETEXTCTRL,
  12.  wxID_DBCONNECTDIALOGPWDTEXTCTRL, wxID_DBCONNECTDIALOGSERVERNAMETEXTCTRL,
  13.  wxID_DBCONNECTDIALOGSTATICTEXT1, wxID_DBCONNECTDIALOGSTATICTEXT2,
  14.  wxID_DBCONNECTDIALOGSTATICTEXT3, wxID_DBCONNECTDIALOGSTATICTEXT4,
  15.  wxID_DBCONNECTDIALOGSTATICTEXT5, wxID_DBCONNECTDIALOGSTATUSTEXTCTRL,
  16.  wxID_DBCONNECTDIALOGUSERNAMETEXTCTRL,
  17. ] = [wx.NewId() for _init_ctrls in range(13)]
  18.  
  19. class DBConnectDialog(wx.Dialog):
  20.     def _init_ctrls(self, prnt):
  21.         # generated method, don't edit
  22.         wx.Dialog.__init__(self, id=wxID_DBCONNECTDIALOG,
  23.               name='DBConnectDialog', parent=prnt, pos=wx.Point(503, 380),
  24.               size=wx.Size(385, 344),
  25.               style=wx.STAY_ON_TOP | wx.DIALOG_MODAL | wx.TAB_TRAVERSAL | wx.SUNKEN_BORDER | wx.DEFAULT_DIALOG_STYLE,
  26.               title='Database Connection Dialog')
  27.         self.SetClientSize(wx.Size(377, 317))
  28.         self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
  29.               'MS Shell Dlg 2'))
  30.         self.SetThemeEnabled(True)
  31.  
  32.         self.staticText1 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT1,
  33.               label='User Name', name='staticText1', parent=self,
  34.               pos=wx.Point(16, 8), size=wx.Size(63, 16), style=0)
  35.         self.staticText1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
  36.               False, 'MS Shell Dlg 2'))
  37.  
  38.         self.staticText2 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT2,
  39.               label='Password', name='staticText2', parent=self,
  40.               pos=wx.Point(200, 8), size=wx.Size(55, 16), style=0)
  41.  
  42.         self.usernameTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGUSERNAMETEXTCTRL,
  43.               name='usernameTextCtrl', parent=self, pos=wx.Point(16, 24),
  44.               size=wx.Size(160, 24), style=0, value='barton')
  45.  
  46.         self.servernameTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGSERVERNAMETEXTCTRL,
  47.               name='servernameTextCtrl', parent=self, pos=wx.Point(16, 80),
  48.               size=wx.Size(160, 24), style=0, value='genesis')
  49.  
  50.         self.staticText3 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT3,
  51.               label='Server Name or IP Address', name='staticText3',
  52.               parent=self, pos=wx.Point(16, 64), size=wx.Size(156, 16),
  53.               style=0)
  54.  
  55.         self.staticText5 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT5,
  56.               label='Default Database', name='staticText5', parent=self,
  57.               pos=wx.Point(200, 64), size=wx.Size(97, 16), style=0)
  58.  
  59.         self.pwdTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGPWDTEXTCTRL,
  60.               name='pwdTextCtrl', parent=self, pos=wx.Point(200, 24),
  61.               size=wx.Size(160, 24), style=wx.TE_PASSWORD, value='1coolSQL')
  62.  
  63.         self.databaseTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGDATABASETEXTCTRL,
  64.               name='databaseTextCtrl', parent=self, pos=wx.Point(200, 80),
  65.               size=wx.Size(160, 24), style=0, value='Trails')
  66.  
  67.         self.staticText4 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT4,
  68.               label='Connection Status Log', name='staticText4', parent=self,
  69.               pos=wx.Point(16, 120), size=wx.Size(127, 16), style=0)
  70.  
  71.         self.ConnectBtn = wx.Button(id=wxID_DBCONNECTDIALOGCONNECTBTN,
  72.               label='Connect', name='ConnectBtn', parent=self, pos=wx.Point(104,
  73.               280), size=wx.Size(75, 26), style=0)
  74.         self.ConnectBtn.Bind(wx.EVT_BUTTON, self.OnConnectButton,
  75.               id=wxID_DBCONNECTDIALOGCONNECTBTN)
  76.  
  77.         self.cancelBtn = wx.Button(id=wxID_DBCONNECTDIALOGCANCELBTN,
  78.               label='Cancel', name='cancelBtn', parent=self, pos=wx.Point(200,
  79.               280), size=wx.Size(75, 26), style=0)
  80.         self.cancelBtn.Bind(wx.EVT_BUTTON, self.OnCancelButton,
  81.               id=wxID_DBCONNECTDIALOGCANCELBTN)
  82.  
  83.         self.statusTextCtrl = wx.TextCtrl(id=wxID_DBCONNECTDIALOGSTATUSTEXTCTRL,
  84.               name='statusTextCtrl', parent=self, pos=wx.Point(16, 136),
  85.               size=wx.Size(344, 136), style=wx.TE_READONLY | wx.TE_MULTILINE,
  86.               value='')
  87.         self.statusTextCtrl.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL,
  88.               False, 'MS Shell Dlg 2'))
  89.  
  90.     def __init__(self, parent):
  91.         self._init_ctrls(parent)
  92.  
  93.         self.dbServer = db.DBServer(self)
  94.         self.dbConnect = self.DBConnect()   # Don't call this guy directly (don't keep?)
  95.         if not self.dbConnect:
  96.             self.Show()
  97.  
  98.     def DBConnect(self):
  99.         user = self.usernameTextCtrl.GetValue()
  100.         password = self.pwdTextCtrl.GetValue()
  101.         host = self.servernameTextCtrl.GetValue()
  102.         dbConnect = self.dbServer.Login(host, user, password)
  103.         database = self.databaseTextCtrl.GetValue()
  104.         if database:
  105.             self.dbServer.Execute("CREATE DATABASE IF NOT EXISTS %s" % database)
  106.         self.dbServer.Execute("USE %s" % database)
  107.         return dbConnect
  108.  
  109.     def GetDBServer(self):
  110.         return self.dbServer
  111.  
  112.     def GetDefaultDatabase(self):
  113.         return self.databaseTextCtrl.GetValue()
  114.  
  115.     def write(self, message):
  116.         self.statusTextCtrl.AppendText("%s\n" %message)
  117.  
  118.     def OnConnectButton(self, event):
  119.         if self.dbConnect:
  120.             self.dbConnect.close()
  121.         self.dbConnect = self.DBConnect()
  122.         if self.dbConnect:
  123.             self.write("Ready")
  124.  
  125.  
  126.     def OnCancelButton(self, event):
  127.         self.Hide()
Dec 3 '06 #1
0 5663

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2148
by: Frank Millman | last post by:
Hi all I have a question regarding inheritance. I have come up with a solution, but it is not very elegant - I am sure there is a more pythonic approach. Assume the following class definitions. class Table: def __init__(self,table_name,table_type): class Master(Table):
1
3470
by: Sean | last post by:
Hi, I found if a wx.TextCtrl is used in a subclass of wx.Dialog, the event wx.EVT_TEXT_ENTER can not be caught, that is, key code of RETURN can not be indentified. class MyDialog(wx.Dialog): def __init__(self,parent,pos,size,style): ... self.t1 = wx.TextCtrl(self, -1, "", size=(125, -1)) self.t1.Bind(wx.EVT_CHAR, self.OnChar,self.t1)
2
2505
by: William Gill | last post by:
I have created a widget that extends Frame() and contains labels, checkboxes, and entrys. I am trying to use tkSimpleDialog.Dialog to create a modal display of this widget, but am running into some (addressing) problems. My widget displays in the parent widget, not the tkSimpleDialog.Dialog? I hope this snippet is enough to help, as my actual code is really too hard to follow. class showtestWidget(tkSimpleDialog.Dialog): def...
0
1453
by: Ian | last post by:
I have sub-classed the Page class in order to provide some base properties and methods that every page on my site will need access to. I would like to have these things show up in the Simple Binding window of the DataBindings dialog. I then found this site (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxurfDataBindingsDialogBox.asp) which says: The tree view displays these objects: the Page object; any...
0
1608
bartonc
by: bartonc | last post by:
#Boa:Dialog:TiltCalibrate import wx import Multiply from PMD import DefaultMultiplier from time import sleep from string import digits from wxdbtools import MySQLInsert, MySQLUpdate, MySQLSelect
0
7697
bartonc
by: bartonc | last post by:
#Boa:Dialog:DBConnectDialog import wx ##"""Given a set if login specs, create a dbServer instance and ## ensure that there is a valid, open connection to the database. ## If not, set the dbConnect to None. ## spec: dict(UserName=name, Password=pswd, ServerName=host) ## Allow names to be set with Default Holder. Consiter Dictionary ## or even a tuple? (name, pswd, host)"""
0
5240
bartonc
by: bartonc | last post by:
from MySQLdb import * from time import time class DBServer: def __init__(self, master): self.master = master def Login(self, servername, username, password): #, database="" """Attempt to create a database login. If successful, return an open connection. Otherwise, return None."""
11
5297
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok / dangerous? How can I force shutdown code within the dialog's Form.FormClosed event run? Zytan
2
2747
kaushalparik
by: kaushalparik | last post by:
hi all, i am working with Desktop application, and trying to create a setup project. i finalized my application and now creating the setup for that application. what i need to do is, with in setup dialog boxes, i have to add my custom form which will ask for DB Details like DBServer name, User Name, Password, name of Database and SQL Server Selection etc., So, Besides my main application, i also added a Class Library Project with an...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.