473,414 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Error Message that I can't explain.

19
This Error message pops up every time I run my program using Python Shell and won't open at all when I don't use Shell.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Traceback (most recent call last):
  3.   File "C:\Documents and Settings\Joshua Leihe\My Documents\My Projects\NewProjects\Joshua\Python projects\French quiz\French Quiz_17.pyw.pyw", line 440, in <module>
  4.     win.start()
  5.   File "C:\Documents and Settings\Joshua Leihe\My Documents\My Projects\NewProjects\Joshua\Python projects\French quiz\French Quiz_17.pyw.pyw", line 179, in start
  6.     self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
  7.   File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14505, in __getattr__
  8.     raise PyDeadObjectError(self.attrStr % self._name)
  9. PyDeadObjectError: The C++ part of the StaticText object has been deleted, attribute access no longer allowed.
  10.  
Any idea what this means and how I can fix it?

Thanks,
Josh
Jan 22 '09 #1
5 1919
Could u post your code so that v can figure out the solution for it.
Jan 23 '09 #2
josh001
19
It's a lot of code and I haven't sorted it for easy reading yet. (until it's finished I don't how I would sort it while still trying to figure out how to make it work)
But here it is.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import wx, shelve, os
  3. from random import randrange as ran
  4. from pprint import pprint 
  5. class FrenchQuiz:
  6.     def start(self):
  7.         self.app = wx.App()
  8.         #Define all windows
  9.         self.win = wx.Frame(None,
  10.                             title='French Quiz',
  11.                             size=(500, 500,),
  12.                             pos=(400, 250),
  13.                             style=wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
  14.         self.win.SetBackgroundColour('Black')
  15.         OpenDLG = wx.FileDialog(
  16.             self.win,
  17.             message='Please choose the quiz or quizes that you wish to use.',
  18.             defaultDir=os.getcwd(),
  19.             defaultFile='',
  20.             wildcard='*.*',
  21.             style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
  22.         self.AllWords = {}
  23.         paths = OpenDLG.GetPaths()
  24.         wordlistnum = -1
  25.         if OpenDLG.ShowModal() == wx.ID_OK:
  26.             for path in paths:
  27.                 try:
  28.                     print path
  29.                 except:
  30.                     KeyError
  31.                 textfile = open(path)
  32.                 words = textfile.readlines()
  33.                 print words#######
  34.                 french = []
  35.                 english = []
  36.                 Pass = 'no'
  37.                 wordlistnum +=1
  38.                 for word in words:
  39.                     if Pass == 'yes':
  40.                         english.append(word[0:-2])
  41.                     if '#english#' in word:
  42.                         Pass = 'yes'
  43.                     if Pass == 'no':
  44.                         if '#english#' not in word:
  45.                             french.append(word[0:-2])
  46.                 #print french##############
  47.                 #print english##############
  48.                 self.AllWords.update(
  49.                     {wordlistnum: {'French': french, 'English': english}})
  50.                 #print 'yes'##############
  51.                 #print self.AllWords##############
  52.  
  53.  
  54.         self.win.Show()
  55. #MainWinStatusBar
  56.         self.win.CreateStatusBar()
  57.         self.win.SetStatusText('Hello')
  58. #MainWinStartUp
  59.         self.Prompt = wx.StaticText(self.win, -1,
  60.                                     'Please choose one of the folowing',
  61.                                     size=(-1, -1), pos=(150, 50),
  62.                                     style=wx.ALIGN_CENTER)
  63.         self.FtoE = wx.Button(self.win, 101, 'French to English', pos=(150, 100),
  64.                               size=wx.DefaultSize, style=wx.NO_BORDER)
  65.         self.FtoE.Bind(wx.EVT_BUTTON, self.French)
  66.         self.EtoF = wx.Button(self.win, 201, 'English to French', pos=(150, 150),
  67.                               size=wx.DefaultSize, style=wx.NO_BORDER)
  68.         self.EtoF.Bind(wx.EVT_BUTTON, self.English)
  69.  
  70. #MainWinCtrls
  71.         self.Words_Left = wx.StaticText(self.win, -1, 'Welcome',
  72.                                     size=(250, 15), pos=(125, 40),
  73.                                     style=wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE)
  74.  
  75.         self.Correct_Incorrect = wx.StaticText(self.win,
  76.                                       -1,
  77.                                       '',
  78.                                       pos=(50, 100),
  79.                                       size=(400, 30),
  80.                                       style=wx.ST_NO_AUTORESIZE |
  81.                                       wx.ALIGN_CENTRE)
  82.  
  83.         self.Word_Correction = wx.StaticText(self.win,
  84.                                       -1,
  85.                                       '',
  86.                                       pos=(50, 150),
  87.                                       size=(400, 80),
  88.                                       style=wx.ST_NO_AUTORESIZE |
  89.                                       wx.ALIGN_CENTRE)
  90.         self.Question = wx.StaticText(self.win,
  91.                                       -1,
  92.                                       '',
  93.                                       pos=(50, 230),
  94.                                       size=(400, 50),
  95.                                       style=wx.ST_NO_AUTORESIZE |
  96.                                       wx.ALIGN_CENTER)
  97.         self.Promt_OnOff = wx.StaticText(self.win,
  98.                                       -1,
  99.                                       'The aswer is?',
  100.                                       pos=(50, 310),
  101.                                       size=(400, 15),
  102.                                       style=wx.ST_NO_AUTORESIZE |
  103.                                       wx.ALIGN_CENTRE)
  104.  
  105.         self.TCinput = wx.TextCtrl(self.win, 1992, '', size=(200, -1),
  106.                                    pos=(150, 350), style=wx.TE_PROCESS_ENTER)
  107.         self.win.Bind(wx.EVT_TEXT_ENTER, self.CheckAnswer, self.TCinput)
  108.     #Custom text buttons
  109.         self.Button_A_Right = wx.Button(self.win, -1, 'À', pos=(10, 10), size=(20, 20))
  110.         self.Button_A_Middle = wx.Button(self.win, -1, 'Â', pos=(30, 10), size=(20, 20))
  111.         self.Button_C_Down = wx.Button(self.win, -1, 'Ç', pos=(50, 10), size=(20, 20))
  112.         self.Button_E_Left = wx.Button(self.win, -1, 'É', pos=(70, 10), size=(20, 20))
  113.         self.Button_E_Right = wx.Button(self.win, -1, 'È', pos=(90, 10), size=(20, 20))
  114.         self.Button_E_Middle = wx.Button(self.win, -1, 'Ê', pos=(110, 10), size=(20, 20))
  115.         self.Button_E_TwoDots = wx.Button(self.win, -1, 'Ë', pos=(130, 10), size=(20, 20))
  116.         self.Button_I_Middle = wx.Button(self.win, -1, 'Î', pos=(150, 10), size=(20, 20))
  117.         self.Button_I_TwoDots = wx.Button(self.win, -1, 'Ï', pos=(170, 10), size=(20, 20))
  118.         self.Button_OE_Combined = wx.Button(self.win, -1, 'Œ', pos=(190, 10), size=(20, 20))
  119.         self.Button_O_Middle = wx.Button(self.win, -1, 'Ô', pos=(210, 10), size=(20, 20))
  120.         self.Button_U_Right = wx.Button(self.win, -1, 'Ù', pos=(230, 10), size=(20, 20))
  121.         self.Button_U_Middle = wx.Button(self.win, -1, 'Û', pos=(250, 10), size=(20, 20))
  122.         Buttons = [[self.Button_A_Right, 'À'], [self.Button_A_Middle, 'Â'],
  123.                    [self.Button_C_Down, 'Ç'], [self.Button_E_Left, 'É'],
  124.                    [self.Button_E_Right, 'È'], [self.Button_E_Middle, 'Ê'],
  125.                    [self.Button_E_TwoDots, 'Ë'], [self.Button_I_Middle, 'Î'],
  126.                    [self.Button_I_TwoDots, 'Ï'], [self.Button_OE_Combined, 'Œ'],
  127.                    [self.Button_O_Middle, 'Ô'], [self.Button_U_Right, 'Ù'],
  128.                    [self.Button_U_Middle, 'Û']]
  129.         for Button in Buttons:
  130.             Button[0].Bind(wx.EVT_BUTTON, self.Button_SpCar)
  131.         self.Button_A_Right.Bind(wx.EVT_BUTTON, self.Button_SpCar)
  132.     #SetColors
  133.         self.Words_Left.SetForegroundColour('Red')
  134.         self.Words_Left.SetBackgroundColour('')
  135.         self.Correct_Incorrect.SetForegroundColour('Red')
  136.         self.Correct_Incorrect.SetBackgroundColour('')
  137.         self.Word_Correction.SetForegroundColour('Red')
  138.         self.Word_Correction.SetBackgroundColour('')
  139.         self.Question.SetForegroundColour('Red')
  140.         self.Question.SetBackgroundColour('')
  141.         self.Promt_OnOff.SetForegroundColour('Red')
  142.         self.Promt_OnOff.SetBackgroundColour('')
  143.         self.TCinput.SetBackgroundColour('Yellow')
  144.         self.TCinput.SetForegroundColour('Red')
  145.         #dissable devices
  146.         self.Words_Left.Show(False)
  147.         self.Correct_Incorrect.Show(False)
  148.         self.Word_Correction.Show(False)
  149.         self.Question.Show(False)
  150.         self.Promt_OnOff.Show(False)
  151.         self.TCinput.Show(False)
  152. #MainWinMenuBar
  153.         MenuBar = wx.MenuBar()
  154.         #Menu1
  155.         Menu1 = wx.Menu()
  156.         Menu1.Append(101, 'Restart\tF1', 'Restarts the program')
  157.         Menu1.Append(102, 'Add\tCtrl+A', 'Open the Add window')
  158.         Menu1.Append(103, 'Close', 'Close French quiz')
  159.         MenuBar.Append(Menu1, '&Game')
  160.         #SetMenuBar
  161.         self.win.SetMenuBar(MenuBar)
  162.         #MenuEvents
  163.         self.win.Bind(wx.EVT_MENU, self.Restart, id=101)
  164.         self.win.Bind(wx.EVT_MENU, self.OpenAddWin, id=102)
  165.         self.win.Bind(wx.EVT_MENU, self.Close, id=103)
  166. #Start main loop
  167.         self.app.MainLoop()
  168.  
  169.     #Asign values...
  170.         self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
  171.                                  ' words left')
  172.         self.Question.SetLabel('The next question is\n\n' + word)
  173.  
  174.     #Methods
  175.     def GameLoop(self, evt):
  176.         self.TCinput.SetFocus()
  177.         try:
  178.             x = self.wordsleft
  179.         except:
  180.             #print self.AllWords##############
  181.             self.French = self.AllWords[0]['French']
  182.             self.English = self.AllWords[0]['English']
  183.             self.wordsleft = 0
  184.             self.correct_incorrect = ''
  185.             self.word_correction = ''
  186.  
  187.         self.wordsleft = len(self.French)
  188.         self.word_number = ran(len(self.French))
  189.         if self.language == 'French':
  190.             word = self.French[self.word_number]
  191.             self.correct_answer = self.English[self.word_number]
  192.         elif self.language == 'English':
  193.             word = self.English[self.word_number]
  194.             self.correct_answer = self.French[self.word_number]
  195.         self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
  196.                                  ' words left')
  197.         self.Question.SetLabel('The next question is\n\n' + word)
  198.  
  199.     def CheckAnswer(self, evt):
  200.         if self.TCinput.GetValue():
  201.             if self.TCinput.GetValue().upper() == self.correct_answer:
  202.                 self.correct_incorrect = 'Correct'
  203.                 del self.French[self.word_number]
  204.                 del self.English[self.word_number]
  205.                 self.Word_Correction.SetLabel('')
  206.             else:
  207.                 self.correct_incorrect = 'Incorrect'
  208.                 self.Word_Correction.SetLabel('The correct answer was:\n' +
  209.                                               self.correct_answer)
  210.         self.Correct_Incorrect.SetLabel(self.correct_incorrect)
  211.         self.TCinput.SetValue('')
  212.         if len(self.French) == 0:
  213.                     self.Score(evt)
  214.         else:
  215.             self.GameLoop(evt)
  216.     def Score(self, evt):
  217.         pass
  218.         #################################################################
  219.         #################################################################
  220.         #################################################################
  221.         #################################################################
  222.         #################################################################
  223.         ###################   Fill in text here   #######################
  224.         #################################################################
  225.         #################################################################
  226.         #################################################################
  227.         #################################################################
  228.         #################################################################
  229.  
  230.     def show(self, mainwin=False, secoundwin=False):
  231.         self.FtoE.Show(mainwin)
  232.         self.EtoF.Show(mainwin)
  233.  
  234.         self.Words_Left.Show(secoundwin)
  235.         self.Correct_Incorrect.Show(secoundwin)
  236.         self.Word_Correction.Show(secoundwin)
  237.         self.Question.Show(secoundwin)
  238.         self.Promt_OnOff.Show(secoundwin)
  239.         self.TCinput.Show(secoundwin)
  240.     def Button_SpCar(self, evt):
  241.         text = self.TCinput.GetValue()
  242.         self.TCinput.SetValue(
  243.             text + evt.GetEventObject().GetLabel())
  244.         self.TCinput.SetFocus()
  245.         self.TCinput.XYToPosition(0, (len(text + 1)))
  246.  
  247.     def French(self, evt):
  248.         self.language = 'French'
  249.         self.show(secoundwin=True)
  250.         self.GameLoop(evt)
  251.  
  252.     def English(self, evt):
  253.         self.language = 'English'
  254.         self.show(secoundwin=True)
  255.         self.GameLoop(evt)
  256.  
  257.     def Close(self, evt):
  258.         self.win.Close()
  259.     def Restart(self, evt):
  260.         self.wordsleft = 0
  261.         self.show(mainwin=True)
  262.     def AddWords(self, evt):
  263.             if self.TC_French:
  264.                 if self.TC_English:
  265.  
  266.                     self.AddWin_WordListFR.append(self.TC_French.GetValue().strip())
  267.                     self.AddWin_WordListEN.append(self.TC_English.GetValue().strip())
  268.                     x_FR = 0
  269.                     for i in range(len(self.AddWin_WordListFR)):
  270.                         y = len(self.AddWin_WordListFR[i])
  271.                         if x_FR > y:
  272.                             x_FR = y
  273.                     List = ''
  274.                     for i in range(len(self.AddWin_WordListFR)):
  275.                         List += self.AddWin_WordListFR[i] + ' '*(0
  276.                             #x_FR - len(self.AddWin_WordListFR[i])
  277.                             + 6) + self.AddWin_WordListEN[i] + '\n  '
  278.                     self.TC_WordList.SetValue(
  279.                         ' '*2 + 'French words:' + ' '*(x_FR - 13) + ' '*6 + 'English words:\n' + ' '*2 + List)
  280.                     self.TC_French.SetValue('')
  281.                     self.TC_English.SetValue('')
  282.                     self.TC_French.SetFocus()
  283.             else:
  284.                 self.dlg.Show()
  285.                 self.TC_French.SetFocus()
  286.     def OpenAddWin(self, evt):
  287.         self.AddWin_WordListFR = []
  288.         self.AddWin_WordListEN = []
  289.         #Functions
  290.         def next(evt):
  291.             self.TC_English.SetFocus()
  292.  
  293.         def AddWin_Button_Cancel(evt):
  294.             self.AddWin.Close()
  295.         def AddWin_Button_Edit(evt):
  296.             #Functions
  297.             def EditWin_Button_Cancel(evt):
  298.                 EditWin.Close()
  299.             def EditWin_Button_Ok(evt):
  300.                 self.AddWin_WordListFR = []
  301.                 for i in range(self.TCEditFR.GetNumberOfLines()):
  302.                     if len(self.TCEditFR.GetValue().strip()) > 0:
  303.                         self.AddWin_WordListFR.append(self.TCEditFR.GetLineText(i).strip())
  304.                 self.AddWin_WordListEN = []
  305.                 for i in range(self.TCEditEN.GetNumberOfLines()):
  306.                     if len(self.TCEditEN.GetValue().strip()) > 0:
  307.                         self.AddWin_WordListEN.append(self.TCEditEN.GetLineText(i).strip())
  308.                 EditWin.Close()
  309.                 self.AddWords(evt)
  310.  
  311.             EditWin = wx.Frame(self.AddWin,
  312.                                title='Edit Window',
  313.                                size=(600, 400),
  314.                                pos=(300, 300),
  315.                                style=wx.CLOSE_BOX |
  316.                                wx.CAPTION |
  317.                                wx.FRAME_NO_TASKBAR |
  318.                                wx.SYSTEM_MENU)
  319.             EditWin.Show()
  320.             self.TCEditFR = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
  321.                                         pos=(10, 20), style=wx.TE_MULTILINE |
  322.                                         wx.TE_DONTWRAP)
  323.             self.TCEditEN = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
  324.                                         pos=(300, 20), style=wx.TE_MULTILINE |
  325.                                         wx.TE_DONTWRAP)
  326.             EditWin_Cancel = wx.Button(EditWin, -1, 'Cancel', size=(100, 20),
  327.                                        pos=(105, 340))
  328.             EditWin_Cancel.Bind(wx.EVT_BUTTON, EditWin_Button_Cancel)
  329.             EditWin_Ok = wx.Button(EditWin, -1, 'Ok', size=(100, 20),
  330.                                    pos=(395, 340))
  331.             EditWin_Ok.Bind(wx.EVT_BUTTON, EditWin_Button_Ok)
  332.             #Append data
  333.             string = ''
  334.             for i in range(len(self.AddWin_WordListFR)):
  335.                 string += self.AddWin_WordListFR[i] + '\n'
  336.             self.TCEditFR.SetValue(string)
  337.             string = ''
  338.             for i in range(len(self.AddWin_WordListEN)):
  339.                 string += self.AddWin_WordListEN[i] + '\n'
  340.             self.TCEditEN.SetValue(string)
  341.         def AddWin_Button_Confirm(evt):
  342.             dlg = wx.FileDialog(self.AddWin, message='Save file as ...',
  343.                                 wildcard='Text Document', style=wx.SAVE)
  344.             if dlg.ShowModal() == wx.ID_OK:
  345.                 path = dlg.GetPath()
  346.                 fp = file(path, 'w')
  347.                 words = []
  348.                 for word in self.AddWin_WordListFR:
  349.                     words += word + '\n'
  350.                 fp.writelines(words)
  351.                 fp.write('#english#\n')
  352.                 words = []
  353.                 for word in self.AddWin_WordListEN:
  354.                     words += word + '\n'
  355.                 fp.writelines(words)
  356.                 fp.close
  357.                 #self.saveinfo['DefaultSavePath'] = path
  358.  
  359.             #when opening txt files use a for loop and get rid of all the \n (newlines) by
  360.             #use:  if str[-2:] == '\n':
  361.             #          str = str[0:-2]
  362.             #and the oposite for when your saving files
  363.             #
  364.             #
  365.             #
  366.             #use filedialow to save and to open
  367.             pass
  368.  
  369.  
  370.  
  371.         self.AddWin = wx.Frame(self.win,
  372.                         title='Add Window',
  373.                         size=(400, 500),
  374.                         pos=(300, 300),
  375.                         style=wx.CLOSE_BOX |
  376.                         wx.CAPTION |
  377.                         wx.FRAME_NO_TASKBAR |
  378.                         wx.SYSTEM_MENU)
  379.         self.AddWin.Show()
  380.         #French
  381.         Static_French = wx.StaticText(self.AddWin, -1,
  382.                                        'French word or phrase:', pos=(7, 10))
  383.         self.TC_French = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
  384.                                       pos=(7, 25))
  385.         self.TC_French.Bind(wx.EVT_TEXT_ENTER
  386. , next)
  387.         self.TC_French.SetFocus()
  388.         #English
  389.         Static_English = wx.StaticText(self.AddWin, -1,
  390.                                        'English word or phrase:', pos=(7, 50))
  391.         self.TC_English = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
  392.                                       pos=(7, 65), style=wx.TE_PROCESS_ENTER)
  393.         self.TC_English.Bind(wx.EVT_TEXT_ENTER, self.AddWords)
  394.         #WordList
  395.         Static_WordList = wx.StaticText(self.AddWin, -1,
  396.                                         'Check list to confirm accuracy:',
  397.                                         pos=(7, 95))
  398.         self.TC_WordList = wx.TextCtrl(self.AddWin, -1, '', size=(380, 310),
  399.                                        pos=(7, 110), style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
  400.         #Cancel
  401.         self.AddWin_Cancel = wx.Button(self.AddWin, -1, 'Cancel', size=(100, 20),
  402.                                         pos=(7, 440))
  403.         self.AddWin_Cancel.Bind(wx.EVT_BUTTON, AddWin_Button_Cancel)
  404.         #Edit
  405.         self.AddWin_Edit = wx.Button(self.AddWin, -1, 'Edit', size=(100, 20),
  406.                                       pos=(135, 440))
  407.         self.AddWin_Edit.Bind(wx.EVT_BUTTON, AddWin_Button_Edit)
  408.         #Confirm
  409.         self.AddWin_Confirm = wx.Button(self.AddWin, -1, 'Confirm', size=(100, 20),
  410.                                          pos=(263, 440))
  411.         self.AddWin_Confirm.Bind(wx.EVT_BUTTON, AddWin_Button_Confirm)
  412.  
  413.  
  414. if __name__ == '__main__':
  415.     win = FrenchQuiz()
  416.     win.start()
  417.  
Jan 23 '09 #3
Expand|Select|Wrap|Line Numbers
  1.         self.app.MainLoop()
  2.  
  3.     #Asign values...
  4.         self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +' words left')
  5.         self.Question.SetLabel('The next question is\n\n' + word)
Try moving the last two lines of the code above the MainLoop
I think the error occurs because when the instance of the main frame is destroyed all the widgets associated are also destroyed but the last two lines perform some activity after the instance of the attribute is destroyed.

I read some where on the net that the objects in the frame are destroyed after being Queued up so i guess all the child widgets fall in place before the mainframe, do not manipulate it after the MainLoop
Jan 28 '09 #4
josh001
19
Solved!
The error message doesn't pop up anymore, Thanks.

The only thing left now is that when I try to open the program without Python Shell (just by clicking on the icon) it doesn't do a thing.
I've saved the file as *.pyw and don't have any idea why it's not opening.

Hear is the slightly edited code.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import wx, shelve, os
  3. from random import randrange as ran
  4. from pprint import pprint 
  5. class FrenchQuiz:
  6.     def start(self):
  7.         self.app = wx.App()
  8.         #Define all windows
  9.         self.win = wx.Frame(None,
  10.                             title='French Quiz',
  11.                             size=(500, 500,),
  12.                             pos=(400, 250),
  13.                             style=wx.CLOSE_BOX | wx.CAPTION | wx.SYSTEM_MENU)
  14.         self.win.SetBackgroundColour('Black')
  15.         self.win.Show()
  16.  
  17.         OpenDLG = wx.FileDialog(
  18.             self.win,
  19.             message='Please choose the quiz or quizes that you wish to use.',
  20.             defaultDir=os.getcwd(),
  21.             defaultFile='',
  22.             wildcard='*.*',
  23.             style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
  24.         self.AllWords = {}
  25.         wordlistnum = -1
  26.         if OpenDLG.ShowModal() == wx.ID_OK:
  27.             paths = OpenDLG.GetPaths()
  28.             for path in paths:
  29.                 textfile = open(path)
  30.                 words = textfile.readlines()
  31.                 french = []
  32.                 english = []
  33.                 Pass = 'no'
  34.                 wordlistnum +=1
  35.                 for word in words:
  36.                     if Pass == 'yes':
  37.                         english.append(word[0:-2])
  38.                     if '#english#' in word:
  39.                         Pass = 'yes'
  40.                     if Pass == 'no':
  41.                         if '#english#' not in word:
  42.                             french.append(word[0:-2])
  43.                 self.AllWords.update(
  44.                     {wordlistnum: {'French': french, 'English': english}})
  45.  
  46.         self.win.Show()
  47. #MainWinStatusBar
  48.         self.win.CreateStatusBar()
  49.         self.win.SetStatusText('Hello')
  50. #MainWinStartUp
  51.         self.Prompt = wx.StaticText(self.win, -1,
  52.                                     'Please choose one of the folowing',
  53.                                     size=(-1, -1), pos=(150, 50),
  54.                                     style=wx.ALIGN_CENTER)
  55.         self.FtoE = wx.Button(self.win, 101, 'French to English', pos=(150, 100),
  56.                               size=wx.DefaultSize, style=wx.NO_BORDER)
  57.         self.FtoE.Bind(wx.EVT_BUTTON, self.French)
  58.         self.EtoF = wx.Button(self.win, 201, 'English to French', pos=(150, 150),
  59.                               size=wx.DefaultSize, style=wx.NO_BORDER)
  60.         self.EtoF.Bind(wx.EVT_BUTTON, self.English)
  61.  
  62. #MainWinCtrls
  63.         self.Words_Left = wx.StaticText(self.win, -1, 'Welcome',
  64.                                     size=(250, 15), pos=(125, 40),
  65.                                     style=wx.ALIGN_CENTER | wx.ST_NO_AUTORESIZE)
  66.  
  67.         self.Correct_Incorrect = wx.StaticText(self.win,
  68.                                       -1,
  69.                                       '',
  70.                                       pos=(50, 100),
  71.                                       size=(400, 30),
  72.                                       style=wx.ST_NO_AUTORESIZE |
  73.                                       wx.ALIGN_CENTRE)
  74.  
  75.         self.Word_Correction = wx.StaticText(self.win,
  76.                                       -1,
  77.                                       '',
  78.                                       pos=(50, 150),
  79.                                       size=(400, 80),
  80.                                       style=wx.ST_NO_AUTORESIZE |
  81.                                       wx.ALIGN_CENTRE)
  82.         self.Question = wx.StaticText(self.win,
  83.                                       -1,
  84.                                       '',
  85.                                       pos=(50, 230),
  86.                                       size=(400, 50),
  87.                                       style=wx.ST_NO_AUTORESIZE |
  88.                                       wx.ALIGN_CENTER)
  89.         self.Promt_OnOff = wx.StaticText(self.win,
  90.                                       -1,
  91.                                       'The aswer is?',
  92.                                       pos=(50, 310),
  93.                                       size=(400, 15),
  94.                                       style=wx.ST_NO_AUTORESIZE |
  95.                                       wx.ALIGN_CENTRE)
  96.  
  97.         self.TCinput = wx.TextCtrl(self.win, 1992, '', size=(200, -1),
  98.                                    pos=(150, 350), style=wx.TE_PROCESS_ENTER)
  99.         self.win.Bind(wx.EVT_TEXT_ENTER, self.CheckAnswer, self.TCinput)
  100.     #Custom text buttons
  101.         self.Button_A_Right = wx.Button(self.win, -1, 'À', pos=(10, 10), size=(20, 20))
  102.         self.Button_A_Middle = wx.Button(self.win, -1, 'Â', pos=(30, 10), size=(20, 20))
  103.         self.Button_C_Down = wx.Button(self.win, -1, 'Ç', pos=(50, 10), size=(20, 20))
  104.         self.Button_E_Left = wx.Button(self.win, -1, 'É', pos=(70, 10), size=(20, 20))
  105.         self.Button_E_Right = wx.Button(self.win, -1, 'È', pos=(90, 10), size=(20, 20))
  106.         self.Button_E_Middle = wx.Button(self.win, -1, 'Ê', pos=(110, 10), size=(20, 20))
  107.         self.Button_E_TwoDots = wx.Button(self.win, -1, 'Ë', pos=(130, 10), size=(20, 20))
  108.         self.Button_I_Middle = wx.Button(self.win, -1, 'Î', pos=(150, 10), size=(20, 20))
  109.         self.Button_I_TwoDots = wx.Button(self.win, -1, 'Ï', pos=(170, 10), size=(20, 20))
  110.         self.Button_OE_Combined = wx.Button(self.win, -1, 'Œ', pos=(190, 10), size=(20, 20))
  111.         self.Button_O_Middle = wx.Button(self.win, -1, 'Ô', pos=(210, 10), size=(20, 20))
  112.         self.Button_U_Right = wx.Button(self.win, -1, 'Ù', pos=(230, 10), size=(20, 20))
  113.         self.Button_U_Middle = wx.Button(self.win, -1, 'Û', pos=(250, 10), size=(20, 20))
  114.         Buttons = [[self.Button_A_Right, 'À'], [self.Button_A_Middle, 'Â'],
  115.                    [self.Button_C_Down, 'Ç'], [self.Button_E_Left, 'É'],
  116.                    [self.Button_E_Right, 'È'], [self.Button_E_Middle, 'Ê'],
  117.                    [self.Button_E_TwoDots, 'Ë'], [self.Button_I_Middle, 'Î'],
  118.                    [self.Button_I_TwoDots, 'Ï'], [self.Button_OE_Combined, 'Œ'],
  119.                    [self.Button_O_Middle, 'Ô'], [self.Button_U_Right, 'Ù'],
  120.                    [self.Button_U_Middle, 'Û']]
  121.         for Button in Buttons:
  122.             Button[0].Bind(wx.EVT_BUTTON, self.Button_SpCar)
  123.         self.Button_A_Right.Bind(wx.EVT_BUTTON, self.Button_SpCar)
  124.     #SetColors
  125.         self.Words_Left.SetForegroundColour('Red')
  126.         self.Words_Left.SetBackgroundColour('')
  127.         self.Correct_Incorrect.SetForegroundColour('Red')
  128.         self.Correct_Incorrect.SetBackgroundColour('')
  129.         self.Word_Correction.SetForegroundColour('Red')
  130.         self.Word_Correction.SetBackgroundColour('')
  131.         self.Question.SetForegroundColour('Red')
  132.         self.Question.SetBackgroundColour('')
  133.         self.Promt_OnOff.SetForegroundColour('Red')
  134.         self.Promt_OnOff.SetBackgroundColour('')
  135.         self.TCinput.SetBackgroundColour('Yellow')
  136.         self.TCinput.SetForegroundColour('Red')
  137.         #dissable devices
  138.         self.Words_Left.Show(False)
  139.         self.Correct_Incorrect.Show(False)
  140.         self.Word_Correction.Show(False)
  141.         self.Question.Show(False)
  142.         self.Promt_OnOff.Show(False)
  143.         self.TCinput.Show(False)
  144. #MainWinMenuBar
  145.         MenuBar = wx.MenuBar()
  146.         #Menu1
  147.         Menu1 = wx.Menu()
  148.         Menu1.Append(101, 'Restart\tF1', 'Restarts the program')
  149.         Menu1.Append(102, 'Add\tCtrl+A', 'Open the Add window')
  150.         Menu1.Append(103, 'Close', 'Close French quiz')
  151.         MenuBar.Append(Menu1, '&Game')
  152.         #SetMenuBar
  153.         self.win.SetMenuBar(MenuBar)
  154.         #MenuEvents
  155.         self.win.Bind(wx.EVT_MENU, self.Restart, id=101)
  156.         self.win.Bind(wx.EVT_MENU, self.OpenAddWin, id=102)
  157.         self.win.Bind(wx.EVT_MENU, self.Close, id=103)
  158.  
  159. #Start main loop
  160.         self.app.MainLoop()
  161.  
  162.     #Methods
  163.     def GameLoop(self, evt):
  164.         self.TCinput.SetFocus()
  165.         try:
  166.             x = self.wordsleft
  167.         except:
  168.             self.French = self.AllWords[0]['French']
  169.             self.English = self.AllWords[0]['English']
  170.             self.wordsleft = 0
  171.             self.correct_incorrect = ''
  172.             self.word_correction = ''
  173.  
  174.         self.wordsleft = len(self.French)
  175.         self.word_number = ran(len(self.French))
  176.         if self.language == 'French':
  177.             word = self.French[self.word_number]
  178.             self.correct_answer = self.English[self.word_number]
  179.         elif self.language == 'English':
  180.             word = self.English[self.word_number]
  181.             self.correct_answer = self.French[self.word_number]
  182.         self.Words_Left.SetLabel('You have ' + str(self.wordsleft) +
  183.                                  ' words left')
  184.         self.Question.SetLabel('The next question is\n\n' + word)
  185.  
  186.     def CheckAnswer(self, evt):
  187.         if self.TCinput.GetValue():
  188.             if self.TCinput.GetValue().upper() == self.correct_answer:
  189.                 self.correct_incorrect = 'Correct'
  190.                 del self.French[self.word_number]
  191.                 del self.English[self.word_number]
  192.                 self.Word_Correction.SetLabel('')
  193.             else:
  194.                 self.correct_incorrect = 'Incorrect'
  195.                 self.Word_Correction.SetLabel('The correct answer was:\n' +
  196.                                               self.correct_answer)
  197.         self.Correct_Incorrect.SetLabel(self.correct_incorrect)
  198.         self.TCinput.SetValue('')
  199.         if len(self.French) == 0:
  200.                     self.Score(evt)
  201.         else:
  202.             self.GameLoop(evt)
  203.     def Score(self, evt):
  204.         pass
  205.         #################################################################
  206.         #################################################################
  207.         #################################################################
  208.         #################################################################
  209.         #################################################################
  210.         ###################   Fill in text here   #######################
  211.         #################################################################
  212.         #################################################################
  213.         #################################################################
  214.         #################################################################
  215.         #################################################################
  216.  
  217.     def show(self, mainwin=False, secoundwin=False):
  218.         self.FtoE.Show(mainwin)
  219.         self.EtoF.Show(mainwin)
  220.  
  221.         self.Words_Left.Show(secoundwin)
  222.         self.Correct_Incorrect.Show(secoundwin)
  223.         self.Word_Correction.Show(secoundwin)
  224.         self.Question.Show(secoundwin)
  225.         self.Promt_OnOff.Show(secoundwin)
  226.         self.TCinput.Show(secoundwin)
  227.     def Button_SpCar(self, evt):
  228.         text = self.TCinput.GetValue()
  229.         self.TCinput.SetValue(
  230.             text + evt.GetEventObject().GetLabel())
  231.         self.TCinput.SetFocus()
  232.         self.TCinput.XYToPosition(0, (len(text + 1)))
  233.  
  234.     def French(self, evt):
  235.         self.language = 'French'
  236.         self.show(secoundwin=True)
  237.         self.GameLoop(evt)
  238.  
  239.     def English(self, evt):
  240.         self.language = 'English'
  241.         self.show(secoundwin=True)
  242.         self.GameLoop(evt)
  243.  
  244.     def Close(self, evt):
  245.         self.win.Close()
  246.     def Restart(self, evt):
  247.         self.wordsleft = 0
  248.         self.show(mainwin=True)
  249.     def AddWords(self, evt):
  250.             if self.TC_French:
  251.                 if self.TC_English:
  252.  
  253.                     self.AddWin_WordListFR.append(self.TC_French.GetValue().strip())
  254.                     self.AddWin_WordListEN.append(self.TC_English.GetValue().strip())
  255.                     x_FR = 0
  256.                     for i in range(len(self.AddWin_WordListFR)):
  257.                         y = len(self.AddWin_WordListFR[i])
  258.                         if x_FR > y:
  259.                             x_FR = y
  260.                     List = ''
  261.                     for i in range(len(self.AddWin_WordListFR)):
  262.                         List += self.AddWin_WordListFR[i] + ' '*(0
  263.                             #x_FR - len(self.AddWin_WordListFR[i])
  264.                             + 6) + self.AddWin_WordListEN[i] + '\n  '
  265.                     self.TC_WordList.SetValue(
  266.                         ' '*2 + 'French words:' + ' '*(x_FR - 13) + ' '*6 + 'English words:\n' + ' '*2 + List)
  267.                     self.TC_French.SetValue('')
  268.                     self.TC_English.SetValue('')
  269.                     self.TC_French.SetFocus()
  270.             else:
  271.                 self.dlg.Show()
  272.                 self.TC_French.SetFocus()
  273.     def OpenAddWin(self, evt):
  274.         self.AddWin_WordListFR = []
  275.         self.AddWin_WordListEN = []
  276.         #Functions
  277.         def next(evt):
  278.             self.TC_English.SetFocus()
  279.  
  280.         def AddWin_Button_Cancel(evt):
  281.             self.AddWin.Close()
  282.         def AddWin_Button_Edit(evt):
  283.             #Functions
  284.             def EditWin_Button_Cancel(evt):
  285.                 EditWin.Close()
  286.             def EditWin_Button_Ok(evt):
  287.                 self.AddWin_WordListFR = []
  288.                 for i in range(self.TCEditFR.GetNumberOfLines()):
  289.                     if len(self.TCEditFR.GetValue().strip()) > 0:
  290.                         self.AddWin_WordListFR.append(self.TCEditFR.GetLineText(i).strip())
  291.                 self.AddWin_WordListEN = []
  292.                 for i in range(self.TCEditEN.GetNumberOfLines()):
  293.                     if len(self.TCEditEN.GetValue().strip()) > 0:
  294.                         self.AddWin_WordListEN.append(self.TCEditEN.GetLineText(i).strip())
  295.                 EditWin.Close()
  296.                 self.AddWords(evt)
  297.  
  298.             EditWin = wx.Frame(self.AddWin,
  299.                                title='Edit Window',
  300.                                size=(600, 400),
  301.                                pos=(300, 300),
  302.                                style=wx.CLOSE_BOX |
  303.                                wx.CAPTION |
  304.                                wx.FRAME_NO_TASKBAR |
  305.                                wx.SYSTEM_MENU)
  306.             EditWin.Show()
  307.             self.TCEditFR = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
  308.                                         pos=(10, 20), style=wx.TE_MULTILINE |
  309.                                         wx.TE_DONTWRAP)
  310.             self.TCEditEN = wx.TextCtrl(EditWin, -1, '', size=(280, 310),
  311.                                         pos=(300, 20), style=wx.TE_MULTILINE |
  312.                                         wx.TE_DONTWRAP)
  313.             EditWin_Cancel = wx.Button(EditWin, -1, 'Cancel', size=(100, 20),
  314.                                        pos=(105, 340))
  315.             EditWin_Cancel.Bind(wx.EVT_BUTTON, EditWin_Button_Cancel)
  316.             EditWin_Ok = wx.Button(EditWin, -1, 'Ok', size=(100, 20),
  317.                                    pos=(395, 340))
  318.             EditWin_Ok.Bind(wx.EVT_BUTTON, EditWin_Button_Ok)
  319.             #Append data
  320.             string = ''
  321.             for i in range(len(self.AddWin_WordListFR)):
  322.                 string += self.AddWin_WordListFR[i] + '\n'
  323.             self.TCEditFR.SetValue(string)
  324.             string = ''
  325.             for i in range(len(self.AddWin_WordListEN)):
  326.                 string += self.AddWin_WordListEN[i] + '\n'
  327.             self.TCEditEN.SetValue(string)
  328.         def AddWin_Button_Confirm(evt):
  329.             dlg = wx.FileDialog(self.AddWin, message='Save file as ...',
  330.                                 wildcard='Text Document', style=wx.SAVE)
  331.             if dlg.ShowModal() == wx.ID_OK:
  332.                 path = dlg.GetPath()
  333.                 fp = file(path, 'w')
  334.                 words = []
  335.                 for word in self.AddWin_WordListFR:
  336.                     words += word + '\n'
  337.                 fp.writelines(words)
  338.                 fp.write('#english#\n')
  339.                 words = []
  340.                 for word in self.AddWin_WordListEN:
  341.                     words += word + '\n'
  342.                 fp.writelines(words)
  343.                 fp.close
  344.                 #self.saveinfo['DefaultSavePath'] = path
  345.  
  346.             #when opening txt files use a for loop and get rid of all the \n (newlines) by
  347.             #use:  if str[-2:] == '\n':
  348.             #          str = str[0:-2]
  349.             #and the oposite for when your saving files
  350.             #
  351.             #
  352.             #
  353.             #use filedialow to save and to open
  354.             pass
  355.  
  356.  
  357.  
  358.         self.AddWin = wx.Frame(self.win,
  359.                         title='Add Window',
  360.                         size=(400, 500),
  361.                         pos=(300, 300),
  362.                         style=wx.CLOSE_BOX |
  363.                         wx.CAPTION |
  364.                         wx.FRAME_NO_TASKBAR |
  365.                         wx.SYSTEM_MENU)
  366.         self.AddWin.Show()
  367.         #French
  368.         Static_French = wx.StaticText(self.AddWin, -1,
  369.                                        'French word or phrase:', pos=(7, 10))
  370.         self.TC_French = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
  371.                                       pos=(7, 25))
  372.         self.TC_French.Bind(wx.EVT_TEXT_ENTER
  373. , next)
  374.         self.TC_French.SetFocus()
  375.         #English
  376.         Static_English = wx.StaticText(self.AddWin, -1,
  377.                                        'English word or phrase:', pos=(7, 50))
  378.         self.TC_English = wx.TextCtrl(self.AddWin, -1, '', size=(380, 20),
  379.                                       pos=(7, 65), style=wx.TE_PROCESS_ENTER)
  380.         self.TC_English.Bind(wx.EVT_TEXT_ENTER, self.AddWords)
  381.         #WordList
  382.         Static_WordList = wx.StaticText(self.AddWin, -1,
  383.                                         'Check list to confirm accuracy:',
  384.                                         pos=(7, 95))
  385.         self.TC_WordList = wx.TextCtrl(self.AddWin, -1, '', size=(380, 310),
  386.                                        pos=(7, 110), style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
  387.         #Cancel
  388.         self.AddWin_Cancel = wx.Button(self.AddWin, -1, 'Cancel', size=(100, 20),
  389.                                         pos=(7, 440))
  390.         self.AddWin_Cancel.Bind(wx.EVT_BUTTON, AddWin_Button_Cancel)
  391.         #Edit
  392.         self.AddWin_Edit = wx.Button(self.AddWin, -1, 'Edit', size=(100, 20),
  393.                                       pos=(135, 440))
  394.         self.AddWin_Edit.Bind(wx.EVT_BUTTON, AddWin_Button_Edit)
  395.         #Confirm
  396.         self.AddWin_Confirm = wx.Button(self.AddWin, -1, 'Confirm', size=(100, 20),
  397.                                          pos=(263, 440))
  398.         self.AddWin_Confirm.Bind(wx.EVT_BUTTON, AddWin_Button_Confirm)
  399.  
  400.  
  401. if __name__ == '__main__':
  402.     win = FrenchQuiz()
  403.     win.start()
  404.  
Jan 28 '09 #5
boxfish
469 Expert 256MB
Unfortunately, I can't test your program because I don't have wx. Does it work as a .py file? Is the .pyw file being opened with pythonw.exe?
Jan 28 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
2
by: brazilnut | last post by:
Hi. Let me explain the setup. I am using Visual Studio .NET to develop a sort of add-in (COM class) for Excel called SQLAddin. It basically queries a SQL server and pulls in data. Now within my...
2
by: Zenobia | last post by:
Hi, Below is a bit of code from ASP.NET Unleashed which gives an error and I can't figure out why. It uses the Authors table from the standard Pubs database. The error message is...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
2
by: dee | last post by:
Hi In web.config I have to the following: <configuration> <system.web> <customErrors defaultRedirect="error.htm" mode="On" /> </system.web> </configuration>
2
by: Rabbit | last post by:
Dear All, I've been tried various configuration and did install SP1 on Windows 2003 Server. The problem now that I have is an aspx page located on the web site for taking the file post by...
4
by: marklawford | last post by:
Not having earned my DBA badge from the scouts just yet I'm a little lost with an error I'm getting. We've just upgraded our development database from 7.2 to 8.2 as the first step in upgrading...
10
by: robert d via AccessMonster.com | last post by:
I have a global error handler that up until today has been working flawlessly. Let me first provide the relevant code **************************************************************** On Error...
1
by: kommaraju | last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2 using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a error message of HTTP STATUS 500 my jdbc...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.