def OnInit(self):

        # Who am I?
        self.SetVendorName("Red-Bean Software")
        self.SetAppName("ThotKeeper")

        # Get our persisted options into an easily addressable object.
        self.conf = TKOptions()
        self.conf.Read()

        # Get the XML Resource class.
        resource_path = os.path.join(os.path.dirname(sys.argv[0]),
                                     'lib', 'tk_resources.xrc')
        self.resources = wx.xrc.XmlResource(resource_path)

        # Store a bunch of resource IDs for easier access.
        self.calendar_id = self.resources.GetXRCID('TKCalendar')
        self.datetree_id = self.resources.GetXRCID('TKDateTree')
        self.tagtree_id = self.resources.GetXRCID('TKTagTree')
        self.today_id = self.resources.GetXRCID('TKToday')
        self.next_id = self.resources.GetXRCID('TKNext')
        self.prev_id = self.resources.GetXRCID('TKPrev')
        self.date_id = self.resources.GetXRCID('TKEntryDate')
        self.author_id = self.resources.GetXRCID('TKEntryAuthor')
        self.author_label_id = self.resources.GetXRCID('TKEntryAuthorLabel')
        self.subject_id = self.resources.GetXRCID('TKEntrySubject')
        self.tags_id = self.resources.GetXRCID('TKEntryTags')
        self.text_id = self.resources.GetXRCID('TKEntryText')
        self.file_new_id = self.resources.GetXRCID('TKMenuFileNew')
        self.file_open_id = self.resources.GetXRCID('TKMenuFileOpen')
        self.file_save_id = self.resources.GetXRCID('TKMenuFileSave')
        self.file_saveas_id = self.resources.GetXRCID('TKMenuFileSaveAs')
        self.file_archive_id = self.resources.GetXRCID('TKMenuFileArchive')
        self.file_revert_id = self.resources.GetXRCID('TKMenuFileRevert')
        self.file_options_id = self.resources.GetXRCID('TKMenuFileOptions')
        self.file_diary_options_id = self.resources.GetXRCID('TKMenuFileDiaryOptions')
        self.file_quit_id = self.resources.GetXRCID('TKMenuFileQuit')
        self.entry_new_id = self.resources.GetXRCID('TKMenuEntryNew')
        self.entry_new_today_id = self.resources.GetXRCID('TKMenuEntryNewToday')
        self.entry_duplicate_id = self.resources.GetXRCID('TKMenuEntryDuplicate')
        self.entry_redate_id = self.resources.GetXRCID('TKMenuEntryRedate')
        self.entry_delete_id = self.resources.GetXRCID('TKMenuEntryDelete')
        self.entry_preview_id = self.resources.GetXRCID('TKMenuEntryPreview')
        self.entry_print_id = self.resources.GetXRCID('TKMenuEntryPrint')
        self.help_update_id = self.resources.GetXRCID('TKMenuHelpUpdate')
        self.help_about_id = self.resources.GetXRCID('TKMenuHelpAbout')
        self.open_tool_id = self.resources.GetXRCID('TKToolOpen')
        self.choose_font_id = self.resources.GetXRCID('TKChooseFontButton')
        self.font_id = self.resources.GetXRCID('TKFontName')
        self.author_global_id = self.resources.GetXRCID('TKAuthorGlobal')
        self.author_name_id = self.resources.GetXRCID('TKAuthorName')
        self.author_per_entry_id = self.resources.GetXRCID('TKAuthorPerEntry')
        self.tree_edit_id = self.resources.GetXRCID('TKTreeMenuEdit')
        self.tree_redate_id = self.resources.GetXRCID('TKTreeMenuRedate')
        self.tree_dup_id = self.resources.GetXRCID('TKTreeMenuDuplicate')
        self.tree_delete_id = self.resources.GetXRCID('TKTreeMenuDelete')
        self.tree_expand_id = self.resources.GetXRCID('TKTreeMenuExpand')
        self.tree_collapse_id = self.resources.GetXRCID('TKTreeMenuCollapse')
        self.rename_tag_id = self.resources.GetXRCID('TKTagName')

        # Construct our datafile parser and placeholder for data.
        self.entries = None

        # Setup a printer object.
        self.printer = TKEntryPrinter()
        
        # Note that we have no outstanding data modifications.
        self.entry_modified = False
        self.diary_modified = False

        # We are not currently ignoring text events.
        self.ignore_text_event = False

        # Fetch our main frame.
        self.frame = self.resources.LoadFrame(None, 'TKFrame')

        # Fetch our panels.
        self.panel = self.frame.FindWindowById(
            self.resources.GetXRCID('TKPanel'))
        self.date_panel = self.frame.FindWindowById(
            self.resources.GetXRCID('TKDatePanel'))

        # Fetch our options dialog.
        self.options_dialog = self.resources.LoadDialog(self.frame,
                                                        'TKOptions')

        # Fetch the per-diary options dialog
        self.diary_options_dialog = self.resources.LoadDialog(self.frame,
                                                              'TKDiaryOptions')
                                                        
        # Fetch the rename tag dialog
        self.rename_tag_dialog = self.resources.LoadDialog(self.frame,
                                                           'TKTagRename')

        # Fetch (and assign) our menu bar.
        self.menubar = self.resources.LoadMenuBar('TKMenuBar')
        self.frame.SetMenuBar(self.menubar)

        # Create a status bar.import locale
        self.statusbar = self.frame.CreateStatusBar(2)
        self.statusbar.SetStatusWidths([-1, 100])
        
        # Replace "unknown" XRC placeholders with custom widgets.
        self.cal = TKEventCal(parent=self.date_panel,
                              style=wx.calendar.CAL_SEQUENTIAL_MONTH_SELECTION)
        self.resources.AttachUnknownControl('TKCalendar',
                                            self.cal, self.date_panel)
        tree = TKEventTree(parent=self.panel,
                           style=wx.TR_HAS_BUTTONS)
        self.resources.AttachUnknownControl('TKDateTree',
                                            tree, self.panel)
        
        tagtree = TKEventTagTree(parent=self.panel,
                            style = wx.TR_HAS_BUTTONS)
        self.resources.AttachUnknownControl('TKTagTree',
                                            tagtree, self.panel)

        # Populate the tree widget.
        self.tree = self.frame.FindWindowById(self.datetree_id)
        self.tree_root = self.tree.GetRootId()
        self.tag_tree = self.frame.FindWindowById(self.tagtree_id)
        self.tag_tree_root = self.tag_tree.GetRootId()
        
        # Set the default font size for the diary entry text widget.
        self._SetFont(wx.Font(self.conf.font_size, wx.DEFAULT,
                              wx.NORMAL, wx.NORMAL, False,
                              self.conf.font_face))
        
        # Event handlers.  They are the key to the world.
        wx.EVT_CLOSE(self.frame, self._FrameClosure)
        wx.EVT_BUTTON(self, self.today_id, self._TodayButtonActivated)
        wx.EVT_BUTTON(self, self.next_id, self._NextButtonActivated)
        wx.EVT_BUTTON(self, self.prev_id, self._PrevButtonActivated)
        wx.EVT_TEXT(self, self.text_id, self._EntryDataChanged)
        wx.EVT_TEXT(self, self.author_id, self._EntryDataChanged)
        wx.EVT_TEXT(self, self.tags_id, self._EntryDataChanged)
        wx.EVT_TEXT(self, self.subject_id, self._EntryDataChanged)
        wx.calendar.EVT_CALENDAR(self, self.calendar_id, self._CalendarChanged)
        wx.calendar.EVT_CALENDAR_YEAR(self, self.calendar_id, self._CalendarDisplayChanged)
        wx.calendar.EVT_CALENDAR_MONTH(self, self.calendar_id, self._CalendarDisplayChanged)
        wx.EVT_MENU(self, self.file_new_id, self._FileNewMenu)
        wx.EVT_MENU(self, self.file_open_id, self._FileOpenMenu)
        wx.EVT_MENU(self, self.file_save_id, self._FileSaveMenu)
        wx.EVT_MENU(self, self.file_saveas_id, self._FileSaveAsMenu)
        wx.EVT_MENU(self, self.file_archive_id, self._FileArchiveMenu)
        wx.EVT_MENU(self, self.file_revert_id, self._FileRevertMenu)
        wx.EVT_MENU(self, self.file_diary_options_id, self._FileDiaryOptionsMenu)
        wx.EVT_MENU(self, self.file_options_id, self._FileOptionsMenu)
        wx.EVT_MENU(self, self.file_quit_id, self._FileQuitMenu)
        wx.EVT_MENU(self, self.entry_new_id, self._EntryNewMenu)
        wx.EVT_MENU(self, self.entry_new_today_id, self._EntryNewTodayMenu)
        wx.EVT_MENU(self, self.entry_duplicate_id, self._EntryDuplicateMenu)
        wx.EVT_MENU(self, self.entry_redate_id, self._EntryRedateMenu)
        wx.EVT_MENU(self, self.entry_delete_id, self._EntryDeleteMenu)
        wx.EVT_MENU(self, self.entry_preview_id, self._EntryPreviewMenu)
        wx.EVT_MENU(self, self.entry_print_id, self._EntryPrintMenu)
        wx.EVT_MENU(self, self.help_update_id, self._HelpUpdateMenu)
        wx.EVT_MENU(self, self.help_about_id, self._HelpAboutMenu)

        # Event handlers for the Tree widget.
        wx.EVT_TREE_ITEM_ACTIVATED(self, self.datetree_id, self._TreeActivated)
        wx.EVT_RIGHT_DOWN(self.tree, self._TreePopup)
        wx.EVT_MENU(self.tree, self.tree_edit_id, self._TreeEditMenu)
        wx.EVT_MENU(self.tree, self.tree_redate_id, self._TreeChangeDateMenu)
        wx.EVT_MENU(self.tree, self.tree_dup_id, self._TreeDuplicateMenu)
        wx.EVT_MENU(self.tree, self.tree_delete_id, self._TreeDeleteMenu)
        wx.EVT_MENU(self.tree, self.tree_expand_id, self._TreeExpandMenu)
        wx.EVT_MENU(self.tree, self.tree_collapse_id, self._TreeCollapseMenu)
        
        wx.EVT_TREE_ITEM_ACTIVATED(self, self.tagtree_id, self._TreeActivated)
        wx.EVT_RIGHT_DOWN(self.tag_tree, self._TreePopup)
        wx.EVT_MENU(self.tag_tree, self.tree_edit_id, self._TreeEditMenu)
        wx.EVT_MENU(self.tag_tree, self.tree_redate_id, self._TreeChangeDateMenu)
        wx.EVT_MENU(self.tag_tree, self.tree_dup_id, self._TreeDuplicateMenu)
        wx.EVT_MENU(self.tag_tree, self.tree_delete_id, self._TreeDeleteMenu)
        wx.EVT_MENU(self.tag_tree, self.tree_expand_id, self._TreeExpandMenu)
        wx.EVT_MENU(self.tag_tree, self.tree_collapse_id, self._TreeCollapseMenu)

        # Size and position our frame.
        self.frame.SetSize(self.conf.size)
        if self.conf.position is not None:
            self.frame.SetPosition(self.conf.position)
        else:
            self.frame.Center()

        # Init the frame with no datafile.
        old_conf_data_file = self.conf.data_file
        self._SetDataFile(None)

        # Now, show the frame.
        self.frame.Show(True)
        
        # Disable the diary menu until a diary loaded
        self._DiaryMenuEnable(False)

        # If we were not given a datafile, or the one we were given is
        # invalid, ask for a valid one.
        if self.cmd_datafile or old_conf_data_file:
            self._SetDataFile(self.cmd_datafile or old_conf_data_file)

        # Tell wxWidgets that this is our main window
        self.SetTopWindow(self.frame)
        
        # Return a success flag
        return True
wxWidgets calls this method to initialize the application
dataset/ETHPy150Open cmpilato/thotkeeper/lib/tk_main.py/ThotKeeper.OnInit