0 Replies - 360 Views - Last Post: 18 March 2012 - 03:13 PM Rate Topic: -----

#1 CodyWD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 21-February 10

Doesn't show menubar when run/compiled?

Posted 18 March 2012 - 03:13 PM

I'm making a wxPython program, but there is the weirdest bug...

## Importing Standard Libraries ##
import os
import sys
import webbrowser
import urllib
import tempfile

## Importing Third Party Libraries ##
import wx
from wx.stc import StyledTextCtrl
from wx import Printer as wxPrinter, MessageBox, PrintPreview, PrintDialog

SB_INFO = 0
progVer = 0.51

class prefDialog(wx.Dialog):
    def __init__(self, parent, title):
        super(prefDialog, self).__init__(parent=parent, title=title, size=(300, 700))
        self.InitUI()
    
    def InitUI(self):
        panel = wx.Panel(self)
        
        ## Menu Bar ##
        prefMenuBar = wx.MenuBar()
        prefFileMenu = wx.Menu()
        prefSave = prefFileMenu.Append(wx.ID_SAVE, "Save Preferences...", "Save the current preferences")
        prefFileMenu.AppendSeparator()
        prefExit = prefFileMenu.Append(wx.ID_EXIT, "Exit the Preferences", "Exit out of the Preferences Dialog.")
        prefMenuBar.Append(prefFileMenu, "&File")
        ## End Menu Bar ##
        
        
        
    def OnClose(self, e):
        self.Destroy()
    
    def savePref(self, e):
        pass
    
class reportIssueDialog(wx.Dialog):
    def __init__(self, parent, title):
        super(reportIssueDialog, self).__init__(parent=parent, title=title, size=(300, 270))
        panel = wx.Panel(self)
        posIssues = ["Bug", "Suggestion", "Crash", "Other..."]
        posLevels = ["Application Breaking", "Severe", "Major", "Neutral", "Minor", "Miniscule"]
        #isslbl = wx.StaticText("Issue:")
        conEmailLbl = wx.StaticText(self, label="e-Mail:", pos=(10, 20))
        self.conEmail = wx.TextCtrl(self, size=(190, 25), pos=(100, 20))
        issueLbl = wx.StaticText(self, label="Issue:", pos=(10, 50))
        self.issue = wx.ComboBox(self, value="Suggestion", choices=posIssues, size=(190, 25), style=wx.CB_READONLY, pos=(100, 50))
        descripLbl = wx.StaticText(self, label="Description:", pos=(10, 80))
        self.descrip = wx.TextCtrl(self, size=(190, 90), pos=(100, 80), style=wx.TE_MULTILINE)
        issLvlLbl = wx.StaticText(self, label="Severity:", pos=(10, 178))
        self.issLvl = wx.ComboBox(self, value="Neutral", choices=posLevels, size=(190, 25), pos=(100, 175), style=wx.CB_READONLY)
        sendBtn = wx.Button(self, label="Send Report", pos=(200, 230))
        cancelBtn = wx.Button(self, label="Cancel", pos=(10, 230))
        
        ## Bind Events ##
        self.Bind(wx.EVT_BUTTON, self.OnClose, cancelBtn)
        self.Bind(wx.EVT_BUTTON, self.sendReport, sendBtn)
        
    def OnClose(self, e):
        self.Destroy()
        
    def sendReport(self, e):
        webbrowser.open("http://www.seafiresoftware.org/bugtracker/bug_report_page.php")
        
class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        super(MainWindow, self).__init__(parent, title=title, size=(450, 400))
        self.InitUI()
        
    def InitUI(self):
        ## Menubar ##
        mainMenu = wx.MenuBar()
        
        fileMenu = wx.Menu()
        newWinItem = fileMenu.Append(wx.ID_NEW, "New", "Open a new window.")
        fileMenu.AppendSeparator()
        saveItem = fileMenu.Append(wx.ID_SAVE, "Save", "Save the currently open file.")
        saveAsItem = fileMenu.Append(wx.ID_SAVEAS, "Save As...", "Choose the file name and location, use to not overwrite.")
        openItem = fileMenu.Append(wx.ID_OPEN, "Open File...", "Open a file.")
        fileMenu.AppendSeparator()
        printItem = fileMenu.Append(wx.ID_PRINT, "Print...", "Print the document.")
        printSetItem = fileMenu.Append(wx.ID_PRINT_SETUP, "Print Setup", "Set up the printed page.")
        printSetItem.Enable(False)
        printPrevItem = fileMenu.Append(wx.ID_PREVIEW, "Print Preview", "Preview what the document will look like printed.")
        fileMenu.AppendSeparator()
        printPrevItem.Enable(False)
        exitItem = fileMenu.Append(wx.ID_EXIT, "Exit", "Exit the application.")
        mainMenu.Append(fileMenu, "&File")
        
        editMenu = wx.Menu()
        undoItem = editMenu.Append(wx.ID_UNDO, "Undo", "Undo last action.")
        redoItem = editMenu.Append(wx.ID_REDO, "Redo", "Redo last action.")
        editMenu.AppendSeparator()
        cutItem = editMenu.Append(wx.ID_CUT, "Cut", "Cut from the current document.")
        copyItem = editMenu.Append(wx.ID_COPY, "Copy", "Copy from the current document.")
        pasteItem = editMenu.Append(wx.ID_PASTE, "Paste", "Paste into the current document.")
        selectAllItem = editMenu.Append(wx.ID_SELECTALL, "Select All", "Select everything in the document.")
        clearItem = editMenu.Append(wx.ID_CLEAR, "Clear All", "Clear everything from the document.")
        editMenu.AppendSeparator()
        prefItem = editMenu.Append(wx.ID_PREFERENCES, "Preferences...", "Edit your preferences.")
        mainMenu.Append(editMenu, "&Edit")
        
        viewMenu = wx.Menu()
        self.toggleStatBar = viewMenu.Append(wx.ID_ANY, "Show Statusbar", "Show this statusbar.", kind=wx.ITEM_CHECK)
        viewMenu.Check(self.toggleStatBar.GetId(), True)
        self.wordWrap = viewMenu.Append(wx.ID_ANY, "Word Wrap", "Wrap the text to the size of the text box.", kind=wx.ITEM_CHECK)
        viewMenu.Check(self.wordWrap.GetId(), True)
        mainMenu.Append(viewMenu, "&View")
        
        helpMenu = wx.Menu()
        helpItem = helpMenu.Append(wx.ID_HELP, "Help with SeaPad...", "Get help with Seapad.")
        updateItem = helpMenu.Append(wx.ID_ANY, "Check for Updates...", "Check for Updates to Seapad.")
        reportItem = helpMenu.Append(wx.ID_ANY, "Report an Issue...", "Report an issue.")
        helpMenu.AppendSeparator()
        aboutBox = helpMenu.Append(wx.ID_ABOUT, "About SeaPad", "About SeaPad")
        mainMenu.Append(helpMenu, "&Help")
        
        self.SetMenuBar(mainMenu)
        ## End MenuBar ##
        
        self.richtext = StyledTextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE | wx.TE_RICH2)
        
        self.richtext.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        self.richtext.SetMarginWidth(1, 25)        
        self.dirName = ""
        self.fileName = ""
        
        self.StatusBar = self.CreateStatusBar()
        
        ## Binding Menubar ##
        self.Bind(wx.EVT_MENU, self.OnQuit, exitItem)
        self.Bind(wx.EVT_MENU, self.StatusToggle, self.toggleStatBar)
        self.Bind(wx.EVT_MENU, self.toggleWordWrap, self.wordWrap)
        self.Bind(wx.EVT_MENU, self.AboutReleaseBox, aboutBox)
        self.Bind(wx.EVT_MENU, self.OnNew, newWinItem)
        self.Bind(wx.EVT_MENU, self.OpenFile, openItem)
        self.Bind(wx.EVT_MENU, self.SaveAsFile, saveAsItem)
        self.Bind(wx.EVT_MENU, self.reportIssue, reportItem)
        self.Bind(wx.EVT_MENU, self.printDialog, printItem)
        self.Bind(wx.EVT_MENU, self.updateDialog, updateItem)
        self.Bind(wx.EVT_MENU, self.cutText, cutItem)
        self.Bind(wx.EVT_MENU, self.copyText, copyItem)
        self.Bind(wx.EVT_MENU, self.pasteText, pasteItem)
        self.Bind(wx.EVT_MENU, self.selectAll, selectAllItem)
        self.Bind(wx.EVT_MENU, self.clearAll, clearItem)
        self.Bind(wx.EVT_MENU, self.undoLast, undoItem)
        self.Bind(wx.EVT_MENU, self.redoLast, redoItem)
        self.Bind(wx.EVT_MENU, self.prefeDialog, prefItem)
        self.Bind(wx.EVT_MENU, self.helpPage, helpItem)
        
        self.Center()
        
        try:
            icon = wx.Icon("SeaPad.ico", wx.BITMAP_TYPE_ICO)
            self.SetIcon(icon)
        finally:
            pass
        
        wx.MessageBox("WARNING: This program is in an alpha version currently. Some features may not be fully functional, or not functional at all. This program may also likely be very buggy. Use at your own risk.", "Warning!", wx.ICON_INFORMATION | wx.OK)
        self.Show()
        
    def undoLast(self, e):
        self.richtext.Undo()
        
    def redoLast(self, e):
        self.richtext.Redo()
    
    def cutText(self, e):
        self.richtext.Cut()
        
    def copyText(self, e):
        self.richtext.Copy()
        
    def pasteText(self, e):
        self.richtext.Paste()
        
    def selectAll(self, e):
        self.richtext.SelectAll()
        
    def clearAll(self, e):
        self.richtext.ClearAll()
    
    def OnNew(self, e):
        self.fileName = ""
        self.dirName = ""
        self.richtext.SetValue("")
        self.PushStatusText("Starting new file", SB_INFO)
        self.Show()
    
    def SaveFile(self, e):
        if (self.fileName != "") and (self.dirName !=""):
            try:
                f = file(os.path.join(self.dirName, self.fileName), 'w')
                f.write(self.richtext.GetText())
                self.PushStatusText("Saved file: " + str(self.richtext.GetTextLength()) + " characters as " + self.fileName + ".", SB_INFO)
                f.close()
                return True
            except:
                self.PushStatusText("Error in saving file!", SB_INFO)
                return False
            else:
                return self.SaveAsFile(e)
        
    def SaveAsFile(self, e):
        ret = False
        dlg = wx.FileDialog(self, "Save As", self.dirName, self.fileName, "Rich Text (*.rtf)|*.rtf|Text Files (*.txt)|*.txt|All Files(*.*)|*.*", wx.SAVE)
        if dlg.ShowModal() == wx.ID_OK:
            self.fileName = dlg.GetFilename()
            self.dirName = dlg.GetDirectory()
            if self.SaveFile(e):
                self.SetTitle("SeaPad" + " - [" + self.fileName + "]")
                ret = True
        dlg.Destroy()
        return ret
        
    def OpenFile(self, e):
        dlg = wx.FileDialog(self, "Open", self.dirName, self.fileName, "Text Files(*.txt)|*.txt|Rich Text(*.rtf)|*.rtf|All Files(*.*)|*.*", wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.fileName = dlg.GetFilename()
            self.dirName = dlg.GetDirectory()
            
            if self.richtext.LoadFile(os.path.join(self.dirName, self.fileName)):
                self.SetStatusText("Read " + str(self.richtext.GetTextLength()) + " characters. File named: " + dlg.GetFilename() + ".", SB_INFO)
            else:
                self.SetStatusText("Error in opening file.", SB_INFO)
        
    def AboutReleaseBox(self, e):
        description = """SeaPad is an advanced text editor, utilizing modern day necessities, like toolbars, menus, and statusbars, \nto provide the ability to use advanced markup."""
        
        licensed = """SeaPad is free software; you can redistribute 
it and/or modify it under the terms of the GNU General Public License as 
published by the Free Software Foundation; either version 3 of the License, 
or (at your option) any later version.

SeaPad is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the GNU General Public License for more details. You should have 
received a copy of the GNU General Public License along with SeaPad; 
if not, write to the Free Software Foundation, Inc., 59 Temple Place, 
Suite 330, Boston, MA  02111-1307  USA"""

        info = wx.AboutDialogInfo()
        
        info.SetIcon(wx.Icon("SeaPad.png", wx.BITMAP_TYPE_PNG))
        info.SetName("SeaPad")
        info.SetVersion("0.2")
        info.SetDescription(description)
        info.SetCopyright("(C) 2012 Cody Dostal")
        info.SetWebSite("http://www.seafiresoftware.org")
        info.SetLicense(licensed)
        info.AddDeveloper("Cody Dostal")
        info.AddDocWriter("Cody Dostal")
        info.AddArtist("Sean Poon - Icon (Temporary)")
        info.AddTranslator("Cody Dostal")
        
        wx.AboutBox(info)
        
    def OnQuit(self, e):
        self.Close()
        
    def StatusToggle(self, e):
        if self.toggleStatBar.IsChecked():
            self.StatusBar.Show()
        else:
            self.StatusBar.Hide()
            
    def toggleWordWrap(self, e):
        if self.wordWrap.IsChecked():
            self.richtext.SetWrapMode(1)
        else:
            self.richtext.SetWrapMode(0)
    
    def reportIssue(self, e):
        reportn = reportIssueDialog.reportIssueDialog(self, title="Report Issue Dialog")
        reportn.ShowModal()
        reportn.Destroy()
      
    def prefeDialog(self, e):
        pred = preferences.prefDialog(None, title="Preferences...")
        pred.ShowModal()
        pred.Destroy()         
    
    def printDialog(self, e):
        data = wx.PrintDialogData()
        
        data.EnableSelection(True)
        data.EnablePrintToFile(True)
        data.EnablePageNumbers(True)
        data.SetMinPage(1)
        data.SetAllPages(True)
        
        dlg = wx.PrintDialog(self, data)
        
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetPrintDialogData()
            print ' GetAllPages: %d\n' % data.GetAllPages()
        dlg.Destroy()
        
    def updateDialog(self, e):
        upFile = "https://raw.github.com/Seafire-Software/Seapad/master/curVersion"
        tempDir = tempfile.gettempdir()
        webFile = urllib.urlretrieve(upFile, tempDir + '/' + 'curVersion')
        basVer = open(tempDir + '/' + 'curVersion')
        ver = float(basVer.read())
        
        if progVer < ver:
            dlg = wx.MessageDialog(None, "You must update. Your version is " + str(progVer) + ", and the latest version is " + str(ver) + ", Do you wish to update?", "Update Required.", wx.YES_NO | wx.ICON_INFORMATION)
        
            result = dlg.ShowModal()
            dlg.Destroy()
            if result == wx.ID_YES:
                upgradeFile = "https://raw.github.com/Seafire-Software/Seapad/master/SeaPad.py"
                
                urllib.urlretrieve(upgradeFile, os.path.join(sys.path[0], sys.argv[0]))
                dlg = wx.MessageDialog(None, "Update successful. Please restart the program!", "Restart manually.", wx.YES_NO)
            else:
                wx.MessageBox("You chose not to upgrade. Please upgrade later!", "Upgrade later.", wx.OK)
        elif ver == progVer:
            wx.MessageBox("You do not need to update. Your version is " + str(progVer) + ", which is equal to the latest version of " + str(ver), "No Update Required.", wx.OK | wx.ICON_INFORMATION)
        elif progVer > ver: 
            wx.MessageBox("What happened here? Your version is " + str(progVer) + " which is greater than the latest version of " + str(ver), "Your version is greater than ours?", wx.OK | wx.ICON_QUESTION)
        else:
            wx.MessageBox("Something went wrong with the update. Please try again. If it happens again, file a bug report please.", "Error!", wx.OK | wx.ICON_ERROR)
            
    def helpPage(self, e):
        webbrowser.open("http://seafiresoftware.org/hesk/knowledgebase.php?category=2")
        
def main():
    app = wx.App()
    MainWindow(None, title="SeaPad")
    app.MainLoop()

if __name__ == '__main__':
    main()



What happens is this: I am programming it in the Wing IDE, and when I run it through that, it shows the menu bar, but then when I run it via BASH, or compile it via PyInstaller, it wont show the menu bar :\ I don't understand this at all...

Also, after I close it, this pops up in BASH:

LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent.

LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent.

LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent.

LIBDBUSMENU-GLIB-WARNING **: Trying to remove a child that doesn't believe we're it's parent.


This post has been edited by CodyWD: 18 March 2012 - 03:14 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1