Search code examples
pythonuser-interfacewxpython

wxPython frame don't show


I have the following Python code that would make a GUI for the command line process of turning a video into frames that is native to VLC Media Player.

# -*- coding: utf-8 -*-
from subprocess import call
import wx
import wx.xrc

vidpath = ''
framedir = ''

def VideoToFrame(videopath, targetdirpath):
    "Converts a video into frames. Make sure you have VLC Media Player installed!"
    call('vlc.exe "' + videopath + '" --video-filter=scene --vout=dummy --start-time=300 --stop-time=600 --scene-ratio=250 --scene-path=”' + targetdirpath + '” vlc://quit')


if __name__ == "__main__":

    class MyFrame1 ( wx.Frame ):

        def __init__( self, parent ):
                wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 436,159 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

                self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

                gbSizer1 = wx.GridBagSizer( 0, 0 )
                gbSizer1.SetFlexibleDirection( wx.BOTH )
                gbSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

                gbSizer2 = wx.GridBagSizer( 0, 0 )
                gbSizer2.SetFlexibleDirection( wx.BOTH )
                gbSizer2.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

                self.VidLabel = wx.StaticText( self, wx.ID_ANY, u"Video path", wx.DefaultPosition, wx.DefaultSize, 0 )
                self.VidLabel.Wrap( -1 )
                gbSizer2.Add( self.VidLabel, wx.GBPosition( 0, 0 ), wx.GBSpan( 1, 1 ), wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )

                self.m_filePicker1 = wx.FilePickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a file", u"*.*", wx.DefaultPosition, wx.DefaultSize, wx.FLP_DEFAULT_STYLE )
                gbSizer2.Add( self.m_filePicker1, wx.GBPosition( 1, 0 ), wx.GBSpan( 1, 1 ), wx.ALL, 5 )


                gbSizer1.Add( gbSizer2, wx.GBPosition( 0, 0 ), wx.GBSpan( 1, 1 ), wx.EXPAND, 5 )

                gbSizer3 = wx.GridBagSizer( 0, 0 )
                gbSizer3.SetFlexibleDirection( wx.BOTH )
                gbSizer3.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )

                self.FrameLabel = wx.StaticText( self, wx.ID_ANY, u"Frame extraction path", wx.DefaultPosition, wx.DefaultSize, 0 )
                self.FrameLabel.Wrap( -1 )
                gbSizer3.Add( self.FrameLabel, wx.GBPosition( 0, 0 ), wx.GBSpan( 1, 1 ), wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )

                self.m_dirPicker1 = wx.DirPickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"Select a folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
                gbSizer3.Add( self.m_dirPicker1, wx.GBPosition( 1, 0 ), wx.GBSpan( 1, 1 ), wx.ALL, 5 )


                gbSizer1.Add( gbSizer3, wx.GBPosition( 0, 1 ), wx.GBSpan( 1, 1 ), wx.EXPAND, 5 )

                bSizer1 = wx.BoxSizer( wx.VERTICAL )

                self.framebutton = wx.Button( self, wx.ID_ANY, u"Extract frames!", wx.DefaultPosition, wx.DefaultSize, 0 )
                bSizer1.Add( self.framebutton, 0, wx.ALL, 5 )


                gbSizer1.Add( bSizer1, wx.GBPosition( 2, 0 ), wx.GBSpan( 1, 1 ), wx.EXPAND, 5 )


                self.SetSizer( gbSizer1 )
                self.Layout()

                self.Centre( wx.BOTH )

                # Connect Events
                self.m_filePicker1.Bind( wx.EVT_FILEPICKER_CHANGED, self.chvidpath )
                self.m_dirPicker1.Bind( wx.EVT_DIRPICKER_CHANGED, self.chframedir )
                self.framebutton.Bind( wx.EVT_BUTTON, self.extractframes )

        def __del__( self ):
                pass


            # Virtual event handlers, overide them in your derived class
        def chvidpath( self, event ):
                vidpath = event.path
                event.Skip()

        def chframedir( self, event ):
                framedir = event.path
                event.Skip()

        def extractframes( self, event ):
                VideoToFrame(vidpath, framedir)
                event.Skip()

Unfortunately I couldn't manage the frame to show when I ran the script. The result was... nothing! Please help! I have no idea of what I am doing, and no other idea of how to make a GUI of a command line process. I am a good Python player though.


Solution

  • I don't see where you created an instance of your MyFrame1

    add:

    app = wx.App()
    frame = MyFrame1(None)
    frame.Show()
    app.MainLoop()