wxPythonのは、ウィンドウハンドルである親のフレームを閉じません

StackOverflow https://stackoverflow.com/questions/941470

質問

私は、他のプログラムが最小限に抑えられている場合、私はそのようメインPythonのフレームの親であることを、このウィンドウを設定し、別のプログラム(アドインとしてPythonプログラムを考える)、パイソンからCOM経由でウィンドウハンドルを取得するPythonでプログラムを持っていますフレームは、あまりにもなります。問題は、私は終了し、メインフレームを閉じたり、破壊しようとするために行くとき、frame.closeは(それが消えるんが)、それは実行だ完了しないで、他のプログラムには、タスクマネージャで殺されない限り閉鎖することを拒否します。

ここでは、取る大まかな手順は次のとおりです。

if we are started directly, launch other program
if not, we are called from the other program, do nothing

enter main function:
create new wx.App
set other program as frame parent:
  Get handle via COM
  create a parent using wx.Window_FromHWND
  create new frame with handle as parent
  show frame
enter main loop

App.onexit:
  close frame
  frame = None
  handle as parent = None
  handle = None

誰もがこの種のものでこれや経験上の任意の考えを持っている?

私はこれで任意の助けに感謝!

[編集] 私はちょうどハンドルを取得し、Pythonのプログラムを終了した場合、私は親としてハンドルを使用する場合これが唯一のケースで、他のプログラムが正常に閉じ

役に立ちましたか?

解決 3

これに対する私の解像度は少し私が今までして来た中で最もエレガントな解決策ハッキング、そして確かではない - しかし、それは...かなり効果的に機能します。

基本的に私の手順では、ポーリングは、ウィンドウハンドルが存在しないかどうかを確認するというスレッドを開始します。それはまだ存在しないのですが、何もしません。それはもう存在しない場合は、ハンドル(およびメインアプリケーション)がリリースされることができ、Pythonのアプリケーションを強制終了しない。

class CheckingThread(threading.Thread):
    '''
    This class runs a check on Parent Window to see if it still is running
    If Parent Window closes, this class kills the Python Window application in memory
    '''
    def run(self):
        '''
        Checks Parent Window in 5 seconds intervals to make sure it is still alive.
        If not alive, exit application
        '''
        self.needKill = False

        while not self.needKill:
            if self.handle is not None:
                if not win32gui.IsWindow(self.handle):
                    os._exit(0)
                    break
            time.sleep(5)

    def Kill(self):
        '''
        Call from Python Window main application that causes application to exit
        '''
        self.needKill = True

    def SetHandle(self, handle):
        '''
        Sets Handle so thread can check if handle exists.
        This must be called before thread is started.
        '''
        self.handle = handle

ここでも、それは少しハック感じているが、私は本当にそれの周りに別の方法が表示されません。誰がより良い解決策を持っている場合は、投稿してください。

他のヒント

あなたのCloseコールがクローズハンドラにぶら下がってすることができる場合、私は疑問に思います。あなたの代わりにDestroyを呼び出してみましたか?私はwxでそれを行うための方法が表示されませんが、多分あなたはそのためのWin32 APIにドロップダウンでした - それが解決しない場合は、唯一の解決策は、「親設定」またはあなたのフレームを「切り離す」ように見えるでしょう1つのタスク...?

、親設定が必要なのであれば、あなたがframe.Reparent(None)frame.Close()を試すことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top