Need to modify a Python Gui
Hi everybody, I have a Python GUI that displays some data in labeled fields. As new data comes in the fields clear and the old data is lost. I need to make a text box in the GUI that will display the cleared data in a scrolling list. I also need this scrolling list to be logged to a file in comma-seperated values for analysis at a later time. The fields I need to scroll and log are labeled in the “class TrafficPane(wx.Panel):” starting at line 64. Thanks #!/usr/bin/env python # -*- coding: utf-8 -*- # # op25_traffic_panel.py # # Copyright 2013 Balint Seeber # # This program 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 2 of the License, or # (at your option) any later version. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # import wx import cPickle as pickle import gnuradio.gr.gr_threading as _threading wxDATA_EVENT = wx.NewEventType() def EVT_DATA_EVENT(win, func): win.Connect(-1, -1, wxDATA_EVENT, func) class DataEvent(wx.PyEvent): def __init__(self, data): wx.PyEvent.__init__(self) self.SetEventType (wxDATA_EVENT) self.data = data def Clone (self): self.__class__ (self.GetId()) class traffic_watcher_thread(_threading.Thread): def __init__(self, rcvd_pktq, event_receiver): _threading.Thread.__init__(self) self.setDaemon(1) self.rcvd_pktq = rcvd_pktq self.event_receiver = event_receiver self.keep_running = True self.start() def stop(self): self.keep_running = False def run(self): while self.keep_running: msg = self.rcvd_pktq.delete_head() de = DataEvent (msg) wx.PostEvent (self.event_receiver, de) del de # A snapshot of important fields in current traffic # class TrafficPane(wx.Panel): # Initializer # def __init__(self, parent, msgq): wx.Panel.__init__(self, parent) self.msgq = msgq sizer = wx.GridBagSizer(hgap=10, vgap=10) self.fields = {} label = wx.StaticText(self, -1, "DUID:") sizer.Add(label, pos=(1,1)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(1,2)) self.fields["duid"] = field; label = wx.StaticText(self, -1, "NAC:") sizer.Add(label, pos=(2,1)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(2,2)) self.fields["nac"] = field; label = wx.StaticText(self, -1, "Source:") sizer.Add(label, pos=(3,1)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(3,2)) self.fields["source"] = field; label = wx.StaticText(self, -1, "Destination:") sizer.Add(label, pos=(4,1)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(4,2)) self.fields["dest"] = field; label = wx.StaticText(self, -1, "MFID:") sizer.Add(label, pos=(1,4)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(1,5)) self.fields["mfid"] = field; label = wx.StaticText(self, -1, "ALGID:") sizer.Add(label, pos=(2,4)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(2,5)) self.fields["algid"] = field; label = wx.StaticText(self, -1, "KID:") sizer.Add(label, pos=(3,4)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(3,5)) self.fields["kid"] = field; label = wx.StaticText(self, -1, "MI:") sizer.Add(label, pos=(4,4)) field = wx.TextCtrl(self, -1, "", size=(216, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(4,5)) self.fields["mi"] = field; label = wx.StaticText(self, -1, "TGID:") sizer.Add(label, pos=(5,4)) field = wx.TextCtrl(self, -1, "", size=(144, -1), style=wx.TE_READONLY) sizer.Add(field, pos=(5,5)) self.fields["tgid"] = field; self.SetSizer(sizer) self.Fit() EVT_DATA_EVENT(
need to print seconds from the epoch including the millisecond
i am using 2.7. I need to print the time in seconds from the epoch with millisecond precision. i have tried many things but have failed. heres my latest: from time import time, strftime from datetime import datetime, time # write date, time, then seconds from epoch self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",))) self.logfile.write('%s\t'%(now.time())) what am i doing wrong? what should i be doing here? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote: > On Thu, Dec 26, 2013 at 10:32 AM, wrote: > > > i am using 2.7. I need to print the time in seconds from the epoch with > > millisecond precision. i have tried many things but have failed. heres my > > latest: > > > > > > from time import time, strftime > > > from datetime import datetime, time > > > > > > # write date, time, then seconds from epoch > > > self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) > > > self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",))) > > > self.logfile.write('%s\t'%(now.time())) > > > > In [1]: import time > > > > In [2]: time.time() > > Out[2]: 1388085670.1567955 > > > > HTH OK i did what you said but I am only getting 2 decimal places. Why is this and what can I do to get the millisecond? -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Thursday, December 26, 2013 8:29:15 PM UTC-5, Roy Smith wrote: > In article <59aa73ac-e06e-4c0e-83a4-147ac42ca...@googlegroups.com>, > > matt.doolittl...@gmail.com wrote: > > > > > > In [1]: import time > > > > In [2]: time.time() > > > > Out[2]: 1388085670.1567955 > > > > > > OK i did what you said but I am only getting 2 decimal places. > > > Why is this and what can I do to get the millisecond? > > > > What operating system are you on? The Python time routines can only > > return as much precision as the operating system makes available. I use Ubuntu 12.10. Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
I pretty much stopped using Windows 4 > > years ago. > I got off the plantation over a year ago and have not looked back. -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Thursday, December 26, 2013 11:54:41 PM UTC-5, Dave Angel wrote: > On Thu, 26 Dec 2013 20:03:34 -0500, Terry Reedy > > wrote: > > > On 12/26/2013 5:48 PM, Dave Angel wrote: > > > > You're probably on Windows, which does time differently. > > > > > With 3.3 and 3.4 on Windows 7, time.time() gives 6 fractional > > digits. > > > >>> import time; time.time() > > > 1388105935.971099 > > > > > With 2.7, same machine, I only get 3. > > > > The way I recall it, Windows time is a mess. To get better than 10 > > ms resolution you needed to use time.clock, but that isn't epoch > > time. Trickier solutions existed, depending on exactly what the > > problem was. But judging from your test, 3.3 built those gyrations > > into the stdlib. I dunno, I pretty much stopped using Windows 4 > > years ago. > > > > -- > > DaveA I am on Ubuntu 12.10. I am still working with the 2 decimal places. Sometime ago i had this issue and I forget how i solved it. maybe i used datetime? thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote: > In article <0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com>, > > matt.doolittl...@gmail.com wrote: > > > > > I am on Ubuntu 12.10. I am still working with the 2 decimal places. > > > Sometime ago i had this issue and I forget how i solved it. maybe i used > > > datetime? thanks! > > > > That's strange. Linux should give you time to the microsecond, or > > something in that range. > > > > Please post the *exact* code you're running. The code you posted > > earlier is obviously only a fragment of some larger program, so we can > > only guess what's happening. Assuming your program is in a file called > > "prog.py", run the following commands and copy-paste the output: > > i cant run it that way. i tried using the python prompt in terminal but got nothing. but here is all the code relevant to this issue: #all the imports import sys import posixpath import time from time import strftime from datetime import datetime import os import wx import cPickle as pickle import gnuradio.gr.gr_threading as _threading #the function that writes the time values def update(self, field_values): now = datetime.now() #logger --- # new line to write on self.logfile.write('\n') # write date, time, and seconds from the epoch self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",))) self.logfile.write('%s\t'%(time.time())) # list to store dictionary keys in tis order keys = ["duid", "nac", "tgid", "source", "algid", "kid"] # loop through the keys in the right order for k in keys: # get the value of the current key f = field_values.get(k, None) # if data unit has value... if f: # output the value with trailing tab self.logfile.write('%s\t'%(str(f))) # if data unit doesnt have this value print a tab else: self.logfile.write('\t') #end logger #if the field 'duid' == 'hdu', then clear fields if field_values['duid'] == 'hdu': self.clear() elif field_values['duid'] == 'ldu1': self.clear() elif field_values['duid'] == 'ldu2': self.clear() #elif field_values['duid'] == 'tdu': # self.clear() #loop through all TextCtrl fields storing the key/value pairs in k, v for k,v in self.fields.items(): # get the dict value for this TextCtrl f = field_values.get(k, None) # if the value is empty then set the new value if f: v.SetValue(f) #sample output in a .txt file: 2013-12-27 12:07:331388164053.18 2013-12-27 12:07:331388164053.36 2013-12-27 12:07:331388164053.54 2013-12-27 12:07:331388164053.73 2013-12-27 12:07:331388164053.91 2013-12-27 12:07:341388164054.11 2013-12-27 12:07:341388164054.28 2013-12-27 12:07:341388164054.48 2013-12-27 12:07:341388164054.66 2013-12-27 12:07:341388164054.84 2013-12-27 12:07:371388164057.62 2013-12-27 12:07:371388164057.81 2013-12-27 12:07:371388164057.99 2013-12-27 12:07:381388164058.18 2013-12-27 12:07:381388164058.37 2013-12-27 12:07:381388164058.54 2013-12-27 12:07:381388164058.73 2013-12-27 12:07:381388164058.92 Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Friday, December 27, 2013 7:25:42 PM UTC-5, Cameron Simpson wrote: > On 27Dec2013 07:40, matt.doolittl...@gmail.com > wrote: > > > I am on Ubuntu 12.10. I am still working with the 2 decimal > > > places. Sometime ago i had this issue and I forget how i solved it. > > > maybe i used datetime? thanks! > > > > Repeatedly people have asked you to show your exact code. Still nothing. > > > > Here's a clue, from a Gentoo box running kernel 3.2.1-gentoo-r2: > > > > $ python > > Python 2.7.2 (default, Feb 9 2012, 18:40:46) > > [GCC 4.5.3] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import time; print time.time() > > 1388190100.44 > > >>> import time; time.time() > > 1388190102.795531 > > >>> > > > > Please show us _exactly_ what you're doing. I'm guessing that print > > is confusing you. > > > matt@matt-Inspiron-1525:~$ python Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time; print time.time() 1388371148.39 >>> import time; time.time() 1388371173.556624 >>> i get the same result as you expect. so its got to be the write statement that is truncated the decimal places right? -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Friday, December 27, 2013 1:49:54 PM UTC-5, Ned Batchelder wrote: > On 12/27/13 1:09 PM, matt.doolittl...@gmail.com wrote: > > > On Friday, December 27, 2013 11:27:58 AM UTC-5, Roy Smith wrote: > > >> In article <0c33b7e4-edc9-4e1e-b919-fec210c92...@googlegroups.com>, > > >> > > >> matt.doolittl...@gmail.com wrote: > > >> > > >> > > >> > > >>> I am on Ubuntu 12.10. I am still working with the 2 decimal places. > > >> > > >>> Sometime ago i had this issue and I forget how i solved it. maybe i used > > >> > > >>> datetime? thanks! > > >> > > >> > > >> > > >> That's strange. Linux should give you time to the microsecond, or > > >> > > >> something in that range. > > >> > > >> > > >> > > >> Please post the *exact* code you're running. The code you posted > > >> > > >> earlier is obviously only a fragment of some larger program, so we can > > >> > > >> only guess what's happening. Assuming your program is in a file called > > >> > > >> "prog.py", run the following commands and copy-paste the output: > > >> > > >> > > > i cant run it that way. i tried using the python prompt in terminal but > > got nothing. but here is all the code relevant to this issue: > > > #all the imports > > > import sys > > > import posixpath > > > import time > > > from time import strftime > > > from datetime import datetime > > > import os > > > import wx > > > import cPickle as pickle > > > import gnuradio.gr.gr_threading as _threading > > > > > > > > > #the function that writes the time values > > > def update(self, field_values): > > > > > > now = datetime.now() > > > > > > #logger --- > > > # new line to write on > > > self.logfile.write('\n') > > > # write date, time, and seconds from the epoch > > > self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) > > > self.logfile.write('%s\t'%(now.strftime("%H:%M:%S",))) > > > self.logfile.write('%s\t'%(time.time())) > > > # list to store dictionary keys in tis order > > > keys = ["duid", "nac", "tgid", "source", "algid", "kid"] > > > # loop through the keys in the right order > > > for k in keys: > > > # get the value of the current key > > > f = field_values.get(k, None) > > > # if data unit has value... > > > if f: > > > # output the value with trailing tab > > > self.logfile.write('%s\t'%(str(f))) > > > # if data unit doesnt have this value print a tab > > > else: > > > self.logfile.write('\t') > > > #end logger > > > > > > #if the field 'duid' == 'hdu', then clear fields > > > if field_values['duid'] == 'hdu': > > > self.clear() > > > elif field_values['duid'] == 'ldu1': > > > self.clear() > > > elif field_values['duid'] == 'ldu2': > > > self.clear() > > > #elif field_values['duid'] == 'tdu': > > > # self.clear() > > > #loop through all TextCtrl fields storing the key/value pairs in > > k, v > > > for k,v in self.fields.items(): > > > # get the dict value for this TextCtrl > > > f = field_values.get(k, None) > > > # if the value is empty then set the new value > > > if f: > > > v.SetValue(f) > > > > > > #sample output in a .txt file: > > > > > > 2013-12-27 12:07:331388164053.18 > > > 2013-12-27 12:07:331388164053.36 > > > 2013-12-27 12:07:331388164053.54 > > > 2013-12-27 12:07:331388164053.73 > > > 2013-12-27 12:07:331388164053.91 > > > 2013-12-27 12:07:341388164054.11 > > > 2013-12-27 12:07:341388164054.28 > > > 2013-12-27 12:07:341388164054.48 > > > 2013-12-27 12:07:341388164054.66 > > > 2013-12-27 12:07:341388164054.84 > > > 2013-12-27 12:07:371388164057.62 > > > 2013-12-27 12:07:371388164057.81 > > > 2013-12-27 12:07:371388164057.99 > > > 2013-12-27 12:07:381388164058.18 > > > 2013-12-27 12:07:381388164058.37 > > > 2013-12-27 12:07:381388164058.54 > > > 2013-12-27 12:07:381388164058.73 > > > 2013-12-27 12:07:381388164058.92 > > > > > > Thanks! > > > > > > > Instead of: > > > > "%s" % time.time() > > > > try: > > > > "%.6f" % time.time() > > > > %.6f is a formatting code meaning, floating-point number, 6 decimal places. > > > > -- > > Ned Batchelder, http://nedbatchelder.com thanks a bunch. the "%.6f" was the cure. can you please point me to the doc for formatting time? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: need to print seconds from the epoch including the millisecond
On Monday, December 30, 2013 8:01:21 AM UTC-5, Ned Batchelder wrote: > On 12/30/13 7:50 AM, Ned Batchelder wrote: > > > BTW, I said something very similar in this thread 2.5 days ago: > > > https://mail.python.org/pipermail/python-list/2013-December/663454.html > > > I get the feeling not all messages are flowing to all places. > > > > Oops, and now Matt's reply to that message has just arrived! Sorry for > > the noise. > > > > -- > > Ned Batchelder, http://nedbatchelder.com the formatting: self.logfile.write('%.6f\t'%(time.time())) fixed it. thank you very much. -- https://mail.python.org/mailman/listinfo/python-list
outputting time in microseconds or milliseconds
Hey everybody, I am using 2.7 on Ubuntu 12.10. All I need to do is to print time with the microseconds. I have been looking at the docs and trying things for about half a day now with no success. Currently my code looks like this: # write date and time and microseocnds self.logfile.write('%s\t'%(str(strftime("%Y-%m-%d", self.logfile.write('%s\t'%(str(strftime("%H:%M:%S", self.logfile.write('%s\t'%(str(time( the output looks like this: 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:43 00:00:00 2013-08-02 06:01:44 00:00:00 2013-08-02 06:01:44 00:00:00 as you can see in the 2nd column the observations occur with 'fractional second' frequency, up to 8 or 9 per second. You can also see my latest attempt to get the microseconds in the third column is not working. It would really be great if python had a way to just tack the microseconds (actually i think milliseconds would be better) on to the second (in the 2nd column) as a fraction. If this is not possible I need the extra write statement for just the microseconds (millisecond if possible). Any help will be much appreciated. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting time in microseconds or milliseconds
so you are saying that self.logfile.write('%s\t'%(str(time( should be: self.logfile.write('%s\t'%(str(time.time( ??? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting time in microseconds or milliseconds
On Friday, August 2, 2013 8:37:45 AM UTC-4, Skip Montanaro wrote: > Perhaps use datetime? > > > > >>> now = datetime.datetime.now() > > >>> now.isoformat() > > '2013-08-02T07:37:08.430131' > > >>> now.strftime("%f") > > '430131' > > > > Skip Thanks Skip, what i currently i have is: dt = datetime.now() and self.logfile.write('%s\t'%(str(strftime("%Y-%m-%d", self.logfile.write('%s\t'%(str(strftime("%H:%M:%S", self.logfile.write('%s\t'%(str(dt.microsecond))) what i get is this: 2013-08-02 09:52:20312961 2013-08-02 09:52:20313274 2013-08-02 09:52:20313461 2013-08-02 09:52:20313580 2013-08-02 09:52:20498705 2013-08-02 09:52:20508610 2013-08-02 09:52:20508963 2013-08-02 09:52:20509191 2013-08-02 09:52:20509477 2013-08-02 09:52:20509703 2013-08-02 09:52:20509798 2013-08-02 09:52:20509887 2013-08-02 09:52:20509975 2013-08-02 09:52:20511013 2013-08-02 09:52:2052 2013-08-02 09:52:20678554 2013-08-02 09:52:20687994 2013-08-02 09:52:20688291 2013-08-02 09:52:20688519 2013-08-02 09:52:20688740 2013-08-02 09:52:20688963 is the third column is only the microsecond? how could i get this to write with the rest of the time (the hh:mm:ss) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting time in microseconds or milliseconds
On Friday, August 2, 2013 8:35:13 AM UTC-4, Steven D'Aprano wrote: > On Fri, 02 Aug 2013 03:54:32 -0700, matt.doolittle33 wrote: > > > > > Hey everybody, > > > > > > I am using 2.7 on Ubuntu 12.10. All I need to do is to print time with > > > the microseconds. I have been looking at the docs and trying things for > > > about half a day now with no success. Currently my code looks like > > > this: > > > > > > # write date and time and microseocnds > > > self.logfile.write('%s\t'%(str(strftime("%Y-%m-%d", > > > self.logfile.write('%s\t'%(str(strftime("%H:%M:%S", > > > self.logfile.write('%s\t'%(str(time( > > What's this time() function? Where does it come from, and what does it > > do? By the look of it, it merely returns the string "00:00:00". The > > time.time() function returns a number of seconds: > > py> "%s" % time.time() > > '1375445812.873546' > > right this is the number that i need in the third column. so should i try?: > > self.logfile.write('%s\t'%(str(time.time( -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting time in microseconds or milliseconds
ok so now i import the module like this: from time import strftime, time i made the write statement like this: self.logfile.write('%s\t'%(str(strftime("%Y-%m-%d", self.logfile.write('%s\t'%(str(strftime("%H:%M:%S", self.logfile.write('%s\t'%(str(time( (oh and btw,i know the code is hacker ugly). and the output is this: 2013-08-03 23:59:341375588774.89 2013-08-03 23:59:351375588775.06 2013-08-03 23:59:351375588775.25 2013-08-03 23:59:351375588775.43 2013-08-03 23:59:351375588775.80 2013-08-03 23:59:351375588775.99 2013-08-03 23:59:351375588775.99 2013-08-03 23:59:351375588775.99 2013-08-03 23:59:351375588776.00 2013-08-03 23:59:361375588776.15 2013-08-03 23:59:361375588776.15 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.16 2013-08-03 23:59:361375588776.34 2013-08-03 23:59:361375588776.35 2013-08-03 23:59:361375588776.35 2013-08-03 23:59:361375588776.35 the first two columns are for eyes so if they are a microsecond apart it doesn't matter. the numbers in the third column are for calculating duration which is where i need the precision. Why is it only giving me the centisecond precision? the docs say i should get microsecond precision with the code i put together. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: outputting time in microseconds or milliseconds
> > Taking a step back, you're probably better off using datetimes. You'll > > get all this conversion nonsense for free: > i did: from time import strftime, time from datetime import datetime now = datetime.now() self.logfile.write('%s\t'%(strftime("%Y-%m-%d",))) self.logfile.write('%s\t'%(now.strftime("%H:%M:%S.%f",))) this gives me: 2013-08-04 14:01:27.906126 2013-08-04 14:01:28.052273 2013-08-04 14:01:28.058967 2013-08-04 14:01:28.243959 2013-08-04 14:01:28.251107 2013-08-04 14:01:28.251268 2013-08-04 14:01:28.251373 2013-08-04 14:01:28.251475 2013-08-04 14:01:28.424568 2013-08-04 14:01:28.612548 2013-08-04 14:01:28.616569 2013-08-04 14:01:28.616727 2013-08-04 14:01:28.792487 2013-08-04 14:01:28.796226 thats what i need. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re:
here is the code in "hier_block2.py": # # Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # # GNU Radio 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, or (at your option) # any later version. # # GNU Radio 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 GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # from gnuradio_core import hier_block2_swig try: import pmt except ImportError: from gruel import pmt # # This hack forces a 'has-a' relationship to look like an 'is-a' one. # # It allows Python classes to subclass this one, while passing through # method calls to the C++ class shared pointer from SWIG. # # It also allows us to intercept method calls if needed # class hier_block2(object): """ Python wrapper around the C++ hierarchical block implementation. Provides convenience functions and allows proper Python subclassing. """ def __init__(self, name, input_signature, output_signature): """ Create a hierarchical block with a given name and I/O signatures. """ self._hb = hier_block2_swig(name, input_signature, output_signature) def __getattr__(self, name): """ Pass-through member requests to the C++ object. """ if not hasattr(self, "_hb"): raise RuntimeError("hier_block2: invalid state--did you forget to call gr.hier_block2.__init__ in a derived class?") return getattr(self._hb, name) def connect(self, *points): """ Connect two or more block endpoints. An endpoint is either a (block, port) tuple or a block instance. In the latter case, the port number is assumed to be zero. To connect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If multiple arguments are provided, connect will attempt to wire them in series, interpreting the endpoints as inputs or outputs as appropriate. """ if len (points) < 1: raise ValueError, ("connect requires at least one endpoint; %d provided." % (len (points),)) else: if len(points) == 1: self._hb.primitive_connect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._connect(points[i-1], points[i]) def _connect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_connect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) def _coerce_endpoint(self, endp): if hasattr(endp, 'to_basic_block'): return (endp, 0) else: if hasattr(endp, "__getitem__") and len(endp) == 2: return endp # Assume user put (block, port) else: raise ValueError("unable to coerce endpoint") def disconnect(self, *points): """ Disconnect two endpoints in the flowgraph. To disconnect the hierarchical block external inputs or outputs to internal block inputs or outputs, use 'self' in the connect call. If more than two arguments are provided, they are disconnected successively. """ if len (points) < 1: raise ValueError, ("disconnect requires at least one endpoint; %d provided." % (len (points),)) else: if len (points) == 1: self._hb.primitive_disconnect(points[0].to_basic_block()) else: for i in range (1, len (points)): self._disconnect(points[i-1], points[i]) def _disconnect(self, src, dst): (src_block, src_port) = self._coerce_endpoint(src) (dst_block, dst_port) = self._coerce_endpoint(dst) self._hb.primitive_disconnect(src_block.to_basic_block(), src_port, dst_block.to_basic_block(), dst_port) def msg_connect(self, src, srcport, dst, dstport): self.primitive_msg_connect(src.to_basic_block(), srcport, dst.to_basic_block(), dstport); def msg_disconnect(self, src, srcport, dst, dstport): self.primitive_msg_disconnect(src.to_basic_block(), srcport, dst.to_basic_block(), dstport); def message_port_register_hier_in(self, portname): self.primitive_message_port_register_hier_in(pmt.pmt_intern(
Re:
oh and the version of python is 2.7.3 THanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Exception running GNU module "op25_grc.py" : AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
I am using using ubuntu 12.10 i am trying to run a python block, namely OP25, in GNU Radio Companion v3.6.3-35-g4435082f, which uses python version 2.7.3 for some reason although python3.2 is in the lib folder. I run the following trace command in terminal: ~$ python -m trace --count -C . op25_grc.py Here is the output with an error: Imported legacy fsk4 Using Volk machine: ssse3_32 Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in run_module_as_main "_main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in run_code exec code in run_globals File "/usr/lib/python2.7/trace.py", line 819, in main() File "/usr/lib/python2.7/trace.py", line 807, in main t.runctx(code, globs, globs) File "/usr/lib/python2.7/trace.py", line 513, in runctx exec cmd in globals, locals File "op25_grc.py", line 493, in tb = op25_grc() File "op25_grc.py", line 231, in __init_ self.wxgui_fftsink2_0_0.set_callback(wxgui_fftsink2_0_0_callback) File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 54, in getattr return getattr(self._hb, name) AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback' The code for "op25_grc.py": #!/usr/bin/env python ## # Gnuradio Python Flow Graph # Title: Op25 Grc # Generated: Wed Feb 13 19:37:41 2013 ## from baz import message_callback from baz import op25 from gnuradio import audio from gnuradio import blks2 from gnuradio import eng_notation from gnuradio import gr from gnuradio import window from gnuradio.eng_option import eng_option from gnuradio.gr import firdes from gnuradio.wxgui import fftsink2 from gnuradio.wxgui import forms from gnuradio.wxgui import scopesink2 from gnuradio.wxgui import waterfallsink2 from grc_gnuradio import wxgui as grc_wxgui from optparse import OptionParser import ConfigParser import math import wx class op25_grc(grc_wxgui.top_block_gui): def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Op25 Grc") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ## # Variables ## self._config_freq_config = ConfigParser.ConfigParser() self._config_freq_config.read(".grc_op25") try: config_freq = self._config_freq_config.getfloat("main", "freq") except: config_freq = 434075000 self.config_freq = config_freq self.freq = freq = config_freq self._config_xlate_offset_config = ConfigParser.ConfigParser() self._config_xlate_offset_config.read(".grc_op25") try: config_xlate_offset = self._config_xlate_offset_config.getfloat("main", "xlate_offset") except: config_xlate_offset = 0 self.config_xlate_offset = config_xlate_offset self.click_freq = click_freq = freq-config_xlate_offset self.xlate_offset_fine = xlate_offset_fine = 0 self.xlate_offset = xlate_offset = freq-click_freq self.samp_rate = samp_rate = 48000 self.samp_per_sym = samp_per_sym = 5+1 self.decim = decim = 20 self._config_xlate_bandwidth_config = ConfigParser.ConfigParser() self._config_xlate_bandwidth_config.read(".grc_rtl") try: config_xlate_bandwidth = self._config_xlate_bandwidth_config.getfloat("main", "xlate_bandwidth") except: config_xlate_bandwidth = 24000 self.config_xlate_bandwidth = config_xlate_bandwidth self.auto_tune_offset = auto_tune_offset = 0 self.xlate_bandwidth = xlate_bandwidth = config_xlate_bandwidth self.variable_static_text_0 = variable_static_text_0 = freq+xlate_offset+xlate_offset_fine+auto_tune_offset self.pre_channel_rate = pre_channel_rate = samp_rate/decim self.gain = gain = 20 self.fine_click_freq = fine_click_freq = 0 self.channel_rate = channel_rate = op25.SYMBOL_RATE*samp_per_sym self.auto_tune_offset_freq = auto_tune_offset_freq = auto_tune_offset*op25.SYMBOL_DEVIATION self.audio_mul = audio_mul = 2 ## # Message Queues ## op25_decoder_0_msgq_out = baz_message_callback_0_msgq_in = gr.msg_queue(2) ## # Blocks ##
Re: Exception running GNU module "op25_grc.py" : AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
> > I know nothing about this gnuradio thingie, and you didn't supply a > > website url. I was wondering if the module is even intended to be run > > standalone, but I suppose the if __name__ == "__main__" thing is a clue > > that it's supposed to. > > > > I found the mixture of trace lines to confuse the stack trace immensely, > > since the exception doesn't occur in the last source line quoted. > > Somebody better than I had best jump in and help. > > > > > If nobody else jumps in, I'd suggest finding a forum that supports > > gnuradio, and ask there. > > > > > > -- > > DaveA Thanks Dave, yes, I too am a little surprised as to why nobody cares to supply a fix, a workaround, or even a hint as why this is going on. I put the exact same post in the gnu-radio homebrew forum and the moderated closed the thread; I am not sure why because he wouldn't answer me but he closed it. Ive posted this question in so many places with but no luck so far. As a workaround I removed the block "wxgui_fftsink2", as that block is not integral to the signal processing. And that is the goal of "op25_grc.py", to decode digital radio signals. This code block is run in GNU radio companion (GRC) along with many others in the signal processing path . GRC is a GUI where one can manage the code (ie. use a flow graph instead of coding) needed to process radio signals with a personal computer; sort of like the IDEs people use to create executables. One can create there own processing blocks or use blocks that others have created. Thanks for your cooperation and patience! I am going to keep working on this as time allows. -- http://mail.python.org/mailman/listinfo/python-list
Python module import failed error
Hello all; I am using Ubuntu 12.10 and Python v2.7.3. I am trying to add a directory to the PYTHONPATH. All of the commands I have found on the web have failed. Please help me to add a directory to the PYHONPATH. The file path is Home/home/bin. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
> > What do you mean by that path? That doesn't look like an Ubuntu/Linux > > path name. Pull up a terminal (Ctrl-Alt-T should do that for you, > > though I haven't used an Ubuntu since 10.10) and see if you can 'ls' > > the path - once you have the real path name (it might start with > > /home/your_user_name/ for instance), go back to the commands you found > > on the web and try them - they'll probably work, then. > thats the file path. the directory "bin" in my home directory. in bash it obviously looks like this "~/bin" using the file system folder the path is home/Home/bin. i have tried commands like, export PYTHONPATH=${PYTHONPATH}:/users/matt/bin or home/matt/bin or Home/home/bin and nothing has worked. from what ive found on the web the Python import process is notoriously underspecified, notwithstanding i was under the impression that PYTHONPATH is a global variable that i can add directories to at anytime to tell Python where to look, without having to add some sort of code to every program. is this impression incorrect? is there some code i need to add to the Python program call the modules in the "bin" dir? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
My guess would be /home/matt/bin - note the leading slash. > > > > ChrisA correct. and in the home directory i run export PYTHONPATH=${PYTHONPATH}:/home/matt/bin and have had no luck? am i using the wrong command? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
On Tuesday, February 19, 2013 11:39:14 AM UTC-5, Chris Angelico wrote:> > > What exactly do you mean by "no luck"? More details would be good. > The program i am using (GNU radio companion) that wants to import the modules from the ~/bin folder shows this error: Block - import_0_0_0 - Import(import): Param - Import(import): Import "import multimode_helper as mh" failed. . -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
On Tuesday, February 19, 2013 11:44:32 AM UTC-5, Thomas Calmant wrote: > Hi, > > Do you run Python in the same terminal than where you run the export command ? > no i dont. the python program looking for the modules in the ~/bin directory is called GNU radio companion. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
> What is PYTHONPATH actually set to? You can find out by running python > > interactively, then i dont know. how do i run pythoin interactively? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
Does anyone know why i keep having these double posts? please excuse them; i am a super newbie to this forum (and python obviously). Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
> > What is PYTHONPATH actually set to? OK so i ran python and then : import sys sys.path bash returned: ['', '/home/matt', '/users/matt/bin', '/home/matt/bin', '/Home/bin', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] so the paths i have been adding are there. should i be adding the python file names in the "bin" directory as well? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
> > gnuradiocompanion.py ? And does the error message/stacktrace appear in > > the same terminal window? > hi. ok so i am trying to run the python module (multimode_helper.py) in the GNU radio companion (GRC) which is sort of like an IDE which lets you organize code blocks by arranging them in a flow graph instead of having to write the code that would call the blocks in some particular order. GRC shows the import error in its flow graph error viewer: Error 0: Block - import_0_0_0 - Import(import): Param - Import(import): Import "import multimode_helper as mh" failed. The directory /home/matt/bin contains "multimode_helper.py" and this file path is in the PYTHONPATH. I still get the import error however. so now that i know the file path is in PYTHONPATH but i am still getting the import error i am really confused here. Thanks for your attention. -- http://mail.python.org/mailman/listinfo/python-list
Re: Double posts (was Re: Python module import failed error)
Thanks Lele. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python module import failed error
Here is the PYTHONPATH >>> import sys >>> sys.path ['', '/home/matt', '/users/matt/bin', '/home/matt/bin', '/Home/bin', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] -- http://mail.python.org/mailman/listinfo/python-list
AttributeError: ' ' object has no attribute ' '
I am using Ubuntu 12.10, and Python 2.7.3, GNU Radio Companion v3.6.3. I get the this error in terminal: in __init__ self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 54, in __getattr__ return getattr(self._hb, name) AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback' I have been getting this error in multiple programs. So what is stopping the program here? There is no Attribute .set_callback obviously. But where is this attribute missing from exactly and how do i put it where it should be? -- http://mail.python.org/mailman/listinfo/python-list
Re: AttributeError: ' ' object has no attribute ' '
yeah im not a programmer, i have not wrote anything here that i am trying to use; i am an end user. my only interest in this code is to get the program working. so i have to do what i have to do try to get it working. im just hoping that what im going through here, this error thats coming up here, has been encountered by someone else that has solved it and that someone will see this and care to tell me how fix it. -- http://mail.python.org/mailman/listinfo/python-list