一个很简单的python+wx的小程序
# --*-- encoding: UTF-8 --*--
import wx
import os
import wx.lib.dialogs
cmd_dbsvc = "C:\\win32\\dbsvc.exe"
cmd_dbsrv = "c:\win32\\dbsrv9.exe"
db_file = "C:\\Program Files\\Sybase\\SQL Anywhere 9\\asademo.db"
class InsertFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, u"Bceng 服务管理器",
size=(380, 100),style=wx.SYSTEM_MENU |wx.CAPTION |wx.MINIMIZE_BOX |wx.CLOSE_BOX )
panel = wx.Panel(self)
bsvcReg = wx.Button(panel, label=u"注册服务", pos=(10, 10),
size=(70, 50))
bsvcStart= wx.Button(panel, label = u"启动服务", pos=(80,10),
size=(70,50) )
bsvcDel = wx.Button(panel, label = u"删除服务", pos=(150,10),
size=(70,50))
bsvcStop= wx.Button(panel, label=u"停止服务", pos=(220,10),
size =(70,50))
bexit = wx.Button(panel, label = u"退出", pos =(290,10),
size=(70,50))
if os.path.exists(cmd_dbsvc) == False or os.path.exists(cmd_dbsrv) == False or os.path.exists(db_file) == False:
bsvcReg.Enable(False)
bsvcStart.Enable(False)
bsvcDel.Enable(False)
bsvcStop.Enable(False)
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, bexit)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Bind(wx.EVT_BUTTON, self.OnSvcReg, bsvcReg)
self.Bind(wx.EVT_BUTTON, self.OnSvcStop, bsvcStop)
self.Bind(wx.EVT_BUTTON, self.OnSvcDel, bsvcDel)
self.Bind(wx.EVT_BUTTON, self.OnSvcStart, bsvcStart)
def OnCloseMe(self, event):
self.Close(True)
def OnSvcReg(self, event):
# dbsvc -as -s auto -t network -w mynetworkserv "C:\Program Files\Sybase\SQL Anywhere 9\win32\dbsrv9.exe" -x tcpip -c 8m "C:\Program Files\Sybase\SQL Anywhere 9\sample.db"
rtn = os.popen( cmd_dbsvc + " -as -s auto -t network -w BCENGSVC " + cmd_dbsrv + " -x tcpip -c 8m " + '"'+db_file+ '"')
dlg = wx.lib.dialogs.scrolledMessageDialog(self, rtn.read(), u"提示")
dlg.ShowModal()
wx.MessageDialog(None,u"数据库服务器注册成功,请重新启动系统",u"提示")
pass
def OnSvcStop(self, event):
dlg = wx.MessageDialog(None, u"确定要停止数据库服务器吗?",u"询问", wx.OK|wx.CANCEL|wx.ICON_WARNING)
retCode = dlg.ShowModal()
if retCode == wx.ID_CANCEL:return
rtn = os.popen(cmd_dbsvc + " -x BCENGSVC" )
dlg = wx.lib.dialogs.scrolledMessageDialog(self, rtn.read(), u"提示")
dlg.ShowModal()
def OnSvcDel(self, event):
dlg = wx.MessageDialog(None,u"确定要删除服务吗?",u"警告",
wx.OK|wx.CANCEL|wx.ICON_WARNING )
retCode = dlg.ShowModal()
if retCode == wx.ID_OK:
rtn = os.popen(cmd_dbsvc +" -y -d BCENGSVC")
dlg = wx.lib.dialogs.scrolledMessageDialog(self, rtn.read(), u"提示")
dlg.ShowModal()
if retCode == wx.ID_CANCEL:
print 'Cancel'
def OnSvcStart(self, event):
rtn = os.popen(cmd_dbsvc + " -u BCENGSVC")
dlg = wx.lib.dialogs.scrolledMessageDialog(self, rtn.read(), u"提示")
dlg.ShowModal()
def OnCloseWindow(self, event):
self.Destroy()
if __name__ == '__main__':
# cmd_dbsvc = os.path.dirname(__file__)+os.sep + "dbsvc.exe"
# tmp = os.popen(dbsvc)
cmd_dbsvc = os.getcwd() + os.sep + "DB" + os.sep + "dbsvc.exe"
cmd_dbsrv = os.getcwd() + os.sep + "DB" + os.sep + "dbsrv9.exe"
db_file = os.getcwd() + os.sep + "DB" + os.sep + "BCENG.db"
app = wx.PySimpleApp()
frame = InsertFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()