OS : Ubuntu 9.04
Python : 2.6.2
I want to print a "while" loop into a secondary wx.Frame named "Results" here's the code :
#!/usr/bin/env python
# -*- coding: utf8 -*-
import random
import wx
import os # Operating System dependent call
import sys
import cPickle as p
import csv
import thread
# Define dialog component
ID_EXIT = 98
ID_CALCULATE = 99
ID_PLOT = 100
ID_CLOSE = 101
ID_CLEAR_TERM = 102
ID_RESET = 103
ID_CALCULATE_SINGLE = 104
def formatta(valore):
tmp = str("%.1f" % valore)
if tmp == "-0.0":
return tmp.replace("-","")
else:
return tmp
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(600, 600),pos = (200,100))
#Creates a menu
filemenu1=wx.Menu()
filemenu1.AppendSeparator()
filemenu1.Append(ID_EXIT, "&Exit", "Terminate the program")
# Creating the menubar
menuBar=wx.MenuBar()
menuBar.Append(filemenu1, "&File") #Adding the filemenu to the MenuBar
self.SetMenuBar(menuBar) #Adding the MenuBar to the Frame content
#self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A statusbar in the bottom of the window
#mod = ['B-ASK','4-ASK','8-ASK','BPSK','Q-PSK','8-PSK','Sunde FSK','QAM-16','QAM-64','QAM-256']
incr = ['1.0', '0.5', '0.2','0.1']
#wx.StaticText(self, -1, "Scegliere la modulazione :",(50,30))
#self.combo1 = wx.ComboBox(self, -1, pos=(50, 70), size=(150, -1), choices=mod, value='B-ASK',
# style=wx.CB_READONLY)
#wx.StaticText(self, -1, "Scegliere i valori minimo e massimo di Eb/N0 (db):",(50,120))
wx.StaticText(self, -1, "Min :",(50,175))
wx.StaticText(self, -1, "Max :",(210,175))
self.txt1 = wx.TextCtrl(self, -1, '0',(120,170))
self.txt2 = wx.TextCtrl(self, -1, '10',(290,170))
wx.StaticText(self, -1, "Choose increase :",(50,240))
self.combo2 = wx.ComboBox(self, -1, pos=(50, 280), size=(150, -1), choices=incr, value='1.0',
style=wx.CB_READONLY)
#wx.Button(self, ID_CLOSE, 'Close', (500, 540))
self.btn1 = wx.Button(self, ID_CALCULATE, 'Calculate', (50, 340))
self.btn2 = wx.Button(self, ID_PLOT, 'Plot', (150, 340))
self.btn3 = wx.Button(self, ID_RESET, 'Reset', (250, 340))
self.btn4 = wx.Button(self, ID_CLEAR_TERM, 'Clear Terminal', (350, 340))
#wx.StaticText(self, -1, "CALCOLO DI UN SOLO VALORE DEL BER :",(50,400))
#wx.StaticText(self, -1, "Inserire il valore di Eb/N0 (db) :",(50,430))
#wx.StaticText(self, -1, "Eb/N0 (db) :",(50,475))
#self.txt3 = wx.TextCtrl(self, -1, '0',(150,470))
#self.btn5 = wx.Button(self, ID_CALCULATE_SINGLE, 'Calculate single', (250, 465))
#self.rb2 = wx.RadioButton(self, -1, 'Off', (400, 395), style=wx.RB_GROUP)
#self.rb1 = wx.RadioButton(self, -1, 'On', (350, 395),)
#self.Bind(wx.EVT_RADIOBUTTON, self.disable_all, id=self.rb1.GetId())
#self.Bind(wx.EVT_RADIOBUTTON, self.enable_all, id=self.rb2.GetId())
wx.EVT_MENU(self, ID_EXIT, self.OnClose)
wx.EVT_BUTTON(self, ID_CALCULATE, self.miothread1)
#wx.EVT_BUTTON(self, ID_PLOT, self.miothread2)
#wx.EVT_BUTTON(self, ID_RESET, self.reset)
wx.EVT_BUTTON(self, ID_CLEAR_TERM, self.clear_term)
#wx.EVT_BUTTON(self, ID_CALCULATE_SINGLE, self.miothread3)
self.enable_all(True)
self.frame2 = Risultati(None,-1,"Results")
self.frame2.Show(True)
def disable_all(self,e):
self.combo1.Disable()
self.combo2.Enable()
self.txt1.Enable()
self.txt2.Enable()
self.btn1.Disable()
self.btn2.Disable()
#self.btn3.Disable()
#self.btn4.Disable()
self.txt3.Enable()
self.btn5.Enable()
def enable_all(self,e):
#self.combo1.Disable()
self.combo2.Enable()
self.txt1.Enable()
self.txt2.Enable()
self.btn1.Enable()
self.btn2.Disable()
self.btn3.Disable()
#self.btn4.Enable()
#self.txt3.Disable()
#self.btn5.Disable()
def OnClose(self, e):
self.Close(True)
self.frame2.Close(True)
#def calcolo(self,objMod,DeMod,titolo,minimum,maximum,incremento):
def calcolo(self,e):
i = minimum = float(self.txt1.GetValue())
maximum = float(self.txt2.GetValue())
incremento = float(self.combo2.GetValue())
print 'min value = '+str(float(minimum))
print 'max value = '+str(float(maximum))
print 'increase = '+str(incremento)
print '---------------Results---------------'
self.frame2.log.AppendText('min value = '+str(float(minimum))+'\n'+'max value = '+str(float(maximum))+'\n'+'increase = '+str(incremento)+'\n'+'---------------Results---------------\n')
while True:
if i <= maximum:
self.frame2.LogMessage2(formatta(i))
print i
i += incremento
else:
break
#print 'Ber calculation done !'
#self.frame2.LogMessage_single('Ber calculation done !')
#self.frame2.log.AppendText('Ber caculation done !')
def clear_term(self,e):
cmd = 'clear'
os.system(cmd)
self.frame2.log.Clear()
def reset(self,e):
os.system('rm ./sys/incremento.csv')
os.system('rm ./sys/titolo.csv')
os.system('rm ./risultati.csv')
os.system('rm ./db.csv')
#os.system('rm ./risultati.txt')
#os.system('rm ./db.txt')
def miothread1(self,e):
thread.start_new_thread(self.calcolo, (0,))
class Risultati(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
panel = wx.Panel(self)
self.log = wx.TextCtrl(panel, -1, "",style=wx.TE_MULTILINE)
self.log.SetEditable(False)
box = wx.BoxSizer(wx.VERTICAL)
box.Add(self.log, 1, wx.EXPAND|wx.ALL, 5)
#self.SetSizer(box)
panel.SetSizer(box)
def LogMessage(self, msg1, msg2):
self.log.AppendText(msg1+' : '+msg2+'\n')
def LogMessage2(self, msg1):
self.log.AppendText(msg1+'\n')
#class MyApp(wx.App):
#def OnInit(self):
#frame=MainWindow(None, -1, "BER Tool AWGN")
#frame.Show(True)
##frame2 = Risultati(None,-1,"Risultati")
##frame2.Show(True)
#self.SetTopWindow(frame)
#return True
app = wx.App()
frame=MainWindow(None, -1, "Print Data")
frame.Show(True)
app.MainLoop()
By pressing the Calculate button, a while loop is printed in the TextCtrl of the Results frame. The while loop is threaded with the class thread and doing so i get often the following errors in the 50% of cases:
(python:11242): Gtk-CRITICAL **: gtk_text_layout_wrap_loop_start: assertion `layout->one_style_cache == NULL' failed
(python:11242): Gtk-CRITICAL **: gtk_text_layout_wrap_loop_end: assertion `layout->wrap_loop_count > 0' failed
or
Segmentation Fault
i think it's the same problem of this thread
http://www.daniweb.com/forums/thread273160.html
hovewer i can't solve it. could you please help me ?
thx in advance