473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create 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 5647

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

Similar topics

6
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....
1
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):...
2
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...
0
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...
0
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,...
0
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...
0
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): #,...
11
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 /...
2
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...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.