473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,399 developers and data experts.

wx.Dialog subclass instantiates my dbServer class

bartonc
6,596 Expert 4TB
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 5642

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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...

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.