6

वर्तमान में मेरे पास एक स्पलैश स्क्रीन है। हालांकि, यह वास्तविक स्प्लैश स्क्रीन के रूप में काम नहीं करता है - क्योंकि यह शेष कोड के निष्पादन को रोकता है (उन्हें पृष्ठभूमि में चलाने की अनुमति देने के बजाय)।पृष्ठभूमि में चलाने के लिए मेरे कोड के अन्य टुकड़ों को अनुमति देने के लिए मेरी वर्तमान स्पलैश स्क्रीन को कैसे अनुकूलित करें?

यह मेरे कार्यक्रम के वर्तमान (कम) आर्किटेक्चर है, जिसमें महत्वपूर्ण बिट्स पूर्ण रूप से प्रदर्शित होते हैं। मैं वास्तव में शेष कार्यक्रम को पृष्ठभूमि में लोड करने की अनुमति देने के लिए वर्तमान में स्प्लैश स्क्रीन को कैसे अनुकूलित कर सकता हूं? क्या यह अजगर में संभव है?

धन्यवाद!

import ... 
(many other imports) 
def ... 
def ... 
(many other definitions) 

class VFrams(wxFrame): 
    wx.Frame.__init__(self, parent, -1, _("Software"), 
         size=(1024, 768), style=wx.DEFAULT_FRAME_STYLE) 
    (a lot of code goes in here) 

class MySplashScreen(wx.SplashScreen): 
    def __init__(self, parent=None): 
     aBitmap = wx.Image(name=VarFiles["img_splash"]).ConvertToBitmap() 
     splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT 
     splashDuration = 5000 # ms 
     wx.SplashScreen.__init__(self, aBitmap, splashStyle, splashDuration, parent) 
     self.Bind(wx.EVT_CLOSE, self.CloseSplash) 
     wx.Yield() 
    def CloseSplash(self, evt): 
     self.Hide() 
     global frame 
     frame = VFrame(parent=None) 
     app.SetTopWindow(frame) 
     frame.Show(True) 
     evt.Skip() 

class MyApp(wx.App): 
    def OnInit(self): 
     MySplash = MySplashScreen() 
     MySplash.Show() 
     return True 

if __name__ == '__main__': 
    DEBUG = viz.addText('DEBUG:', viz.SCREEN) 
    DEBUG.setPosition(0, 0) 
    DEBUG.fontSize(16) 
    DEBUG.color(viz.BLACK) 
    Start_Mainvars()   
    Start_Config() 
    Start_Translation() 
    Start_DB() 
    Start_Themes() 
    Start_Gui() 
    Start_Get_Isos() 
    Start_Bars() 
    Start_Menus() 
    Start_Event_Handlers() 
    app = MyApp() 
    app.MainLoop() 

सभी मदद के लिए धन्यवाद यह कैसे मैं कोड (बशर्ते सलाह के बाद) को बदल दिया है,:, स्प्लैश स्क्रीन के लिए एक:

def show_splash(): 
    # create, show and return the splash screen 
    global splash 
    bitmap = wx.Image(name=VarFiles["img_splash"]).ConvertToBitmap() 
    splash = wx.SplashScreen(bitmap, wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None, -1) 
    splash.Show() 
    return splash 

class MyApp(wx.App): 
    def OnInit(self): 
     global frame, splash 
     splash = show_splash() 
     Start_Config() 
     Start_Translation() 
     Start_DB() 
     Start_Themes() 
     Start_Gui() 
     Start_Get_Isos() 
     Start_Bars("GDP1POP1_20091224_gdp", "1 pork") 
     Start_Menus() 
     Start_Event_Handlers() 
     frame = VFrame(parent=None) 
     frame.Show(True) 
     splash.Destroy() 
     return True 

if __name__ == '__main__': 
    DEBUG = viz.addText('DEBUG:', viz.SCREEN) 
    DEBUG.setPosition(0, 0) 
    DEBUG.fontSize(16) 
    DEBUG.color(viz.BLACK) 
    Start_Mainvars() 
    app = MyApp() 
    app.MainLoop() 

उत्तर

12

आपका कोड बहुत गन्दा/जटिल है। Wx.SplashScreen को ओवरराइड करने की कोई आवश्यकता नहीं है और कोई कारण नहीं है कि आपकी स्प्लैश स्क्रीन बंद घटना मुख्य एप्लिकेशन विंडो बना रही हो। यहां बताया गया है कि मैं स्प्लैश स्क्रीन कैसे करता हूं।

import wx 

def show_splash(): 
    # create, show and return the splash screen 
    bitmap = wx.Bitmap('images/splash.png') 
    splash = wx.SplashScreen(bitmap, wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_NO_TIMEOUT, 0, None, -1) 
    splash.Show() 
    return splash 

def main(): 
    app = wx.PySimpleApp() 
    splash = show_splash() 

    # do processing/initialization here and create main window 
    frame = MyFrame(...) 
    frame.Show() 

    splash.Destroy() 
    app.MainLoop() 

if __name__ == '__main__': 
    main() 

बस बिना किसी टाइमआउट के स्प्लैश स्क्रीन बनाएं। लोड करना जारी रखें और अपने एप्लिकेशन की मुख्य विंडो बनाएं। फिर स्पलैश स्क्रीन को नष्ट करें ताकि यह दूर हो जाए। स्पलैश स्क्रीन दिखाना अन्य प्रसंस्करण होने से नहीं रोकता है।

+0

बहुत बहुत धन्यवाद। मैं यह कोशिश कर रहा हूँ। – relima

0

आप दो धागे का उपयोग करना चाहेंगे आप जो भी अन्य कोड निष्पादित करना चाहते हैं उसके लिए एक। दोनों थ्रेड एक ही समय में चलेंगे, जो परिणाम आप चाहते हैं।

+0

कोई समस्या है: मैंने धागे का कभी भी उपयोग नहीं किया है। मैं इसे काम करने की कोशिश कर रहा हूं, लेकिन मुझे इस बात का कोई संकेत नहीं है कि इसे कैसे प्राप्त किया जाए। मैं इस सवाल के जवाब से सीखने की उम्मीद कर रहा था। – relima

+0

विषय पर ऑनलाइन कुछ लेख देखें। मैंने यह पाया है जो मदद कर सकता है: http://www.devshed.com/c/a/Python/Basic- थ्रेडिंग-in- Python – Bernard

+0

यहां कोई धागे की आवश्यकता नहीं है। यदि सही तरीके से उपयोग किया जाता है तो स्प्लैश स्क्रीन निष्पादन को अवरुद्ध नहीं करती है। – FogleBird