0
私はSQLサーバーからデータを取得するアプリケーションを持っています。進行状況を示すプログレスバーが表示されます。wxpython:閉じるアプリケーションが進行状況バーを閉じない
ただし、アプリケーションウィンドウの右上にある「x」をクリックしてアプリケーションを終了しようとすると、アプリケーションのメインウィンドウは閉じますが、プログレスバーは実行され続けますSQLサーバーのすべての作業が終了します。
「x」をクリックするとすべてを終了する方法があるのだろうかと思います。サンプルコード(マイナスSQLサーバからのデータの検索を行う部分)以下である:
import wx, pyodbc
class App(wx.Frame):
def __init__(self, parent, title):
super(App, self).__init__(parent, title=title, size=(600, 400))
#-----------------------------------------------------------
self.Bind(wx.EVT_CLOSE, self.OnExit) # ADDED
#-----------------------------------------------------------
p = wx.Panel(self)
nb = wx.Notebook(p)
self.Panel1 = PanelMaker(nb, 'Foo')
nb.AddPage(self.Panel1, "Foo")
sizer = wx.BoxSizer()
sizer.Add(nb, 1, wx.EXPAND)
p.SetSizer(sizer)
self.Centre()
#-----------------------------------------------------------
def OnExit(self, evt): #ADDED
self.Destroy()
#self.Close() #I tried self.Close(), but I could not even
#close the application window when using it.
#-----------------------------------------------------------
class ProgressBar(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="In progress...", size=(300, 90), style = wx.FRAME_FLOAT_ON_PARENT)
GridBagSizer = wx.GridBagSizer()
self.gauge = wx.Gauge(self, range = 100, size = (-1, 30), style = wx.GA_HORIZONTAL, name = 'In Progress')
self.gauge.SetValue(0)
txt = wx.StaticText(self, label = 'Hamsters are working very hard to move data', style = wx.ALIGN_CENTER)
GridBagSizer.Add(self.gauge, pos = (0, 0), span = (1, 1), flag = wx.EXPAND|wx.ALL, border = 15)
GridBagSizer.Add(txt, pos = (1, 0), span = (1, 1), flag = wx.ALL, border = 15)
self.SetSizer(GridBagSizer)
self.Layout()
def Update(self, step):
self.gauge.SetValue(step)
if step == 100:
self.Close()
class PanelMaker(wx.Panel):
def __init__(self, parent, tool):
wx.Panel.__init__(self, parent = parent)
Panel1Sizer = wx.GridBagSizer(0, 10)
ProceedButton = wx.Button(self, label = tool, size = (-1, -1))
ProceedButton.Bind(wx.EVT_BUTTON, self.OnProceedButton)
Panel1Sizer.Add(ProceedButton, pos = (7, 0), span = (1, 1), flag = wx.EXPAND|wx.LEFT, border = 12)
Panel1Sizer.Layout()
self.SetSizer(Panel1Sizer)
def OnProceedButton(self, evt):
Progbar = ProgressBar(self.GetParent())
Progbar.Show()
connection = pyodbc.connect(DRIVER = '{SQL Server}',
SERVER = ServerName,
DATABASE = DatabaseName,
Trusted_Connection = True)
cursor = connection.cursor()
for i in range(100):
#retrieve data from the SQL server.......
wx.Yield()
Progbar.Update(i+1)
#Closing SQL connection
cursor.close()
del cursor
connection.close()
を閉じて表示されていない私はあなたの提案に基づいて変更を加えたが、それでも同じことが起こる:メインアプリケーションウィンドウを閉じることができますが、プログレスバーはSQLプロセスが終了するまで進行します。私のサンプルコードにもっと詳細や詳細を提供できますか?ありがとう! – Alex
私はOnExit関数にも接続コードの終了を追加してから、self.Destroy() –