<commit_before>import string
import sys
import time
import wx
import wx.html

#import resources.python.mainFrame
import resources.graphics.images
import main_frame

class WXInterface(wx.App):
    """WX-based graphical user interface for DeVIDE.

    This contains all functionality that used to be in the main devide WX
    interface.  I'm still working on the division between this class and
    the graph editor.

    For now: we keep this class as small as possible; it only handles WX-app
    central events.  The GraphEditor does everything else.

    An alternative view would be that the GraphEditor is only concerned with
    the actual network editor canvas.  As I said, I'm still working on this.

    NOTE: I'm leaning towards the latter approach.
    
    A third approach would be to factor out a third class responsible for the
    rest of the main UI.  Then we'd have: WXInterface, GraphEditor, 
    MysteryClass.
    """
    
    def __init__(self, devide_app):
        self._devide_app = devide_app
        
        self._main_frame = None

        wx.App.__init__(self, 0)

        self._graph_editor = None
        self._python_shell = None
        self._helpClass = None

    def OnInit(self):
        """Standard WX OnInit() method, called during construction.
        """

        # set the wx.GetApp() application name
        self.SetAppName('DeVIDE')
        
        #self._main_frame = resources.python.mainFrame.mainFrame(
        #    None, -1, "dummy", name="DeVIDE")

        self._main_frame = main_frame.MainWXFrame(None, -1, "DeVIDE", (-1,-1),
                                                  (640,480))
        wx.InitAllImageHandlers()
        self._main_frame.SetIcon(self.getApplicationIcon())

        wx.EVT_MENU(self._main_frame, self._main_frame.fileExitId,
                    self.exitCallback)
        
        #wx.EVT_MENU(self._main_frame, self._main_frame.windowGraphEditorId,
        #           self._handlerMenuGraphEditor)
        wx.EVT_MENU(self._main_frame, self._main_frame.window_python_shell_id,
                    self._handler_menu_python_shell)

        #wx.EVT_MENU(self._main_frame, self._main_frame.windowMinimiseChildrenId,
        #            lambda e: self._windowIconizeAllChildren())
        #wx.EVT_MENU(self._main_frame, self._main_frame.windowRestoreChildrenId,
        #            lambda e: self._windowRestoreAllChildren())
        
        #wx.EVT_MENU(self._main_frame, self._main_frame.testingAllTestsId,
        #            self._handlerTestingAllTests)
        wx.EVT_MENU(self._main_frame, self._main_frame.helpShowHelpId,
                    self._handlerHelpContents)
        wx.EVT_MENU(self._main_frame, self._main_frame.helpAboutId,
                    self.aboutCallback)

        self._main_frame.Show(1)
        # here we also show twice: in wxPython 2.4.2.4 the TextCtrls sometimes
        # have difficulty completely drawing themselves at startup
        self._main_frame.Show(1)

        # with these calls, we force an immediate draw of the full window
        # if we don't do this, some of the controls are only drawn when
        # startup progress is 100% (this is on wxPython 2.6.0.1)
        self._main_frame.Refresh()
        self._main_frame.Update()

        self.SetTopWindow(self._main_frame)

        return True
        
    def OnExit(self):
        pass
    
    def getApplicationIcon(self):
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(
            resources.graphics.images.getdevidelogo32x32Bitmap())
        return icon

    def getMainWindow(self):
        return self._main_frame        

    def get_main_window(self):
        return self.getMainWindow()

    def _handlerHelpContents(self, event):
        self.showHelp()

    def _handler_test_all(self, event):
        import testing
        reload(testing)
        dt = testing.DeVIDETesting(self._devide_app)
        dt.runAllTests()

    def handler_post_app_init(self):
        """AFTER we've started the GUI and performed all pre-imports, this
        method makes sure that all other dependencies are imported into the
        module namespace.  We want these imports here, else the pre-imports
        can't do their thing.
        """
    
        global GraphEditor, PythonShell, helpClass
    
        from graph_editor import GraphEditor
<commit_msg>We have to quit after all tests are done in wx interface mode.<commit_after>import string
import sys
import time
import wx
import wx.html

#import resources.python.mainFrame
import resources.graphics.images
import main_frame

class WXInterface(wx.App):
    """WX-based graphical user interface for DeVIDE.

    This contains all functionality that used to be in the main devide WX
    interface.  I'm still working on the division between this class and
    the graph editor.

    For now: we keep this class as small as possible; it only handles WX-app
    central events.  The GraphEditor does everything else.

    An alternative view would be that the GraphEditor is only concerned with
    the actual network editor canvas.  As I said, I'm still working on this.

    NOTE: I'm leaning towards the latter approach.
    
    A third approach would be to factor out a third class responsible for the
    rest of the main UI.  Then we'd have: WXInterface, GraphEditor, 
    MysteryClass.
    """
    
    def __init__(self, devide_app):
        self._devide_app = devide_app
        
        self._main_frame = None

        wx.App.__init__(self, 0)

        self._graph_editor = None
        self._python_shell = None
        self._helpClass = None

    def OnInit(self):
        """Standard WX OnInit() method, called during construction.
        """

        # set the wx.GetApp() application name
        self.SetAppName('DeVIDE')
        
        #self._main_frame = resources.python.mainFrame.mainFrame(
        #    None, -1, "dummy", name="DeVIDE")

        self._main_frame = main_frame.MainWXFrame(None, -1, "DeVIDE", (-1,-1),
                                                  (640,480))
        wx.InitAllImageHandlers()
        self._main_frame.SetIcon(self.getApplicationIcon())

        wx.EVT_MENU(self._main_frame, self._main_frame.fileExitId,
                    self.exitCallback)
        
        #wx.EVT_MENU(self._main_frame, self._main_frame.windowGraphEditorId,
        #           self._handlerMenuGraphEditor)
        wx.EVT_MENU(self._main_frame, self._main_frame.window_python_shell_id,
                    self._handler_menu_python_shell)

        #wx.EVT_MENU(self._main_frame, self._main_frame.windowMinimiseChildrenId,
        #            lambda e: self._windowIconizeAllChildren())
        #wx.EVT_MENU(self._main_frame, self._main_frame.windowRestoreChildrenId,
        #            lambda e: self._windowRestoreAllChildren())
        
        #wx.EVT_MENU(self._main_frame, self._main_frame.testingAllTestsId,
        #            self._handlerTestingAllTests)
        wx.EVT_MENU(self._main_frame, self._main_frame.helpShowHelpId,
                    self._handlerHelpContents)
        wx.EVT_MENU(self._main_frame, self._main_frame.helpAboutId,
                    self.aboutCallback)

        self._main_frame.Show(1)
        # here we also show twice: in wxPython 2.4.2.4 the TextCtrls sometimes
        # have difficulty completely drawing themselves at startup
        self._main_frame.Show(1)

        # with these calls, we force an immediate draw of the full window
        # if we don't do this, some of the controls are only drawn when
        # startup progress is 100% (this is on wxPython 2.6.0.1)
        self._main_frame.Refresh()
        self._main_frame.Update()

        self.SetTopWindow(self._main_frame)

        return True
        
    def OnExit(self):
        pass
    
    def getApplicationIcon(self):
        icon = wx.EmptyIcon()
        icon.CopyFromBitmap(
            resources.graphics.images.getdevidelogo32x32Bitmap())
        return icon

    def getMainWindow(self):
        return self._main_frame        

    def get_main_window(self):
        return self.getMainWindow()

    def _handlerHelpContents(self, event):
        self.showHelp()

    def _handler_test_all(self, event):
        import testing
        reload(testing)
        dt = testing.DeVIDETesting(self._devide_app)
        dt.runAllTests()

        # after testing, we have to quit...
        self.quit()

    def handler_post_app_init(self):
        """AFTER we've started the GUI and performed all pre-imports, this
        method makes sure that all other dependencies are imported into the
        module namespace.  We want these imports here, else the pre-imports
        can't do their thing.
        """
    
        global GraphEditor, PythonShell, helpClass
    
        from graph_editor import GraphEditor

{'fraction_non_alphanumeric': 0.07434733257661748, 'fraction_numerical': 0.006356413166855846, 'mean_word_length': 2.3261608154020386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5193234', 'n_tokens_mistral': 2558, 'n_tokens_neox': 2443, 'n_words': 693}