[Tutor] Fwd: RE: Thread output to GUI Text Field

2016-01-12 Thread Alan Gauld

Forwarding to list.
Please use Reply-All or Rely to List when responding to tutor messages.

You didn't mention earlier that you were using threads!
That significantly complicates matters.


 Forwarded Message 
Subject:RE: [Tutor] Thread output to GUI Text Field
Date:   Tue, 12 Jan 2016 08:52:42 +
From:   Patrycja Niewosz 
To: Alan Gauld 



Hi Alan,

Thanks for a reply.
I have found that I need to use slots and signal to pass data between Threads 
and hence 


class Panel(QtGui.QWidget):
def __init__(self,master,parent=None):
.
.
self.initUI()


def initUI(self):
#Build layout
self.tcpControlMessages = QtGui.QPlainTextEdit()

def startThreadedProcess(self):
self. tcpControlMessage.clear()
self.thread.start()

@QtCore.Slot()
 def updateMessages(self, message):
print message
self. tcpControlMessages.appendPlainText(message)


Patrycja


-Original Message-
From: Tutor [mailto:tutor-bounces+pniewosz=slb@python.org] On Behalf Of 
Alan Gauld
Sent: Monday, January 11, 2016 6:37 PM
To: tutor@python.org
Subject: Re: [Tutor] Thread output to GUI Text Field

On 11/01/16 16:12, Patrycja Niewosz wrote:
> Hi All,
> 
> I use commands,
> 
> server_address = ('134.32.45.9', 1)
> print ('starting up on port '% server_address)
> sock.bind(server_address)
> 
> the message pop ups in the window command when I run full code, 
> however I would like to print this message in the main GUI, where I 
> have defined
> 
> tcpControlGrid.addWidget(QtGui.QLabel('TCP Server Messages'),3,0)
> tcpControlGrid.addWidget(self.tcpControlMessages,4,0)
> 
> self.tcpControlMessages = QtGui.QPlainTextEdit()
> 
> How can I transfer messages from above code directly to the GUI interface, so 
> that I can see on main window.

Since this is obviously a PyQt issue you would be best asking on a Qt or SIDE 
forum. However most UIs have a Text control(*) that you can insert text into. 
So look for a method of your control called something like insert() or put() or 
maybe even write().

(*)I'm assuming your QtGui.QPlainTextEdit() is the Qt version.
What methods does it have?

--
Alan G
Author of the Learn to Program web site
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.alan-2Dg.me.uk_=CwICAg=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw=VlCD52JbZNT0daOyAL7vAA=lMWz8Zwkrgc7CBzDOXEXkb8oTuIeuRsGgutRf32psIc=utKS1TTBmN6wmUJ4SnWJcRbNjIddYO09HyTV2cQUwj8=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.amazon.com_author_alan-5Fgauld=CwICAg=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw=VlCD52JbZNT0daOyAL7vAA=lMWz8Zwkrgc7CBzDOXEXkb8oTuIeuRsGgutRf32psIc=jXyzhQxcanJnO9e1u-yPXFqlRSgVfDu-CVVnYHsPrOM=
Follow my photo-blog on Flickr at:
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.flickr.com_photos_alangauldphotos=CwICAg=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw=VlCD52JbZNT0daOyAL7vAA=lMWz8Zwkrgc7CBzDOXEXkb8oTuIeuRsGgutRf32psIc=zDdjUw8RFbWAtyLe1ywjgC40UayySD5H6fzQAlZN5N8=
 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_tutor=CwICAg=uGuXJ43KPkPWEl2imVFDmZQlhQUET7pVRA2PDIOxgqw=VlCD52JbZNT0daOyAL7vAA=lMWz8Zwkrgc7CBzDOXEXkb8oTuIeuRsGgutRf32psIc=afbUD2-GlmdFUE2rIbOMtKiOxKEZSqDi0Z85FSoldpM=
 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: RE: Thread output to GUI Text Field

2016-01-12 Thread Alan Gauld
On 12/01/16 09:44, Alan Gauld wrote:

> You didn't mention earlier that you were using threads!
> That significantly complicates matters.

Apologies, I just noticed that the subject line does,
although it wasn't clear that you were trying to output
between threads.

> I have found that I need to use slots and signal to pass data between Threads 
> and hence 

Does that mean you have solved the problem?
Or are you still looking for help?
If so what exactly do you want to know?
Do you have some code that doesn't work for example?

> class Panel(QtGui.QWidget):
> def __init__(self,master,parent=None):
> .
> .
> self.initUI()
> 
> 
> def initUI(self):
> #Build layout
> self.tcpControlMessages = QtGui.QPlainTextEdit()
> 
> def startThreadedProcess(self):
> self. tcpControlMessage.clear()
> self.thread.start()
> 
> @QtCore.Slot()
>  def updateMessages(self, message):
> print message
> self. tcpControlMessages.appendPlainText(message)

We can help with the threading aspects but for Qt specifics
you will probably do better on a PyQt forum.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!

2016-01-12 Thread Joel Goldstick
On Tue, Jan 12, 2016 at 3:36 PM, Chelsea G  wrote:

> So I am importing a csv file to textfile and the first column is product
> names and the second is a description of each. I am trying to find the sum
> of all descriptions using sum(c.values)). Here is my code so far:
>
> import csv
> import json
> import sys
> #from sys import argv
> from collections import defaultdict
> from collections import Counter
> #script, filename = argv
> data = defaultdict(list)
> counted_data = defaultdict(list)
> grouped_data = defaultdict(list)
>
> class dictionary:
> with open ('weekly_20160102.csv', 'rb') as f:
> reader = csv.reader(f)
> next(reader, None)
> for row in reader:
> data[row[2]].append(row[3]) #this appends the description(value) to the
> product name(key)
> #new_item = {}
> for key in data.keys():
> #print key
> c = Counter(data[key])
> for value in c:
> #print c[value]
> if c[value] >= 5:
> print key, ':', value, ':', c[value]
> elif c[value] <= 1:
> print 'other', ':', sum(c.values())
>
>
> Please help!!
>

First of all, turn off your rich text mail editor -- we can only help if we
see the indentation.  Send Text only to this list.
You define a class, but never instantiate it.  what is Counter()?  Where is
it defined?

This is awfully complicated.  If your csv file looks like this:

name1, 5
name3, 54
name2, 3
name1, 4

you can read the file line by line, split on , and add the second value to
a dict with the first value as a key.  You will need to check for the
exception of their being no key with that value (the first time it appears).

But first, resend in plain text

> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] HELP!!

2016-01-12 Thread Chelsea G
So I am importing a csv file to textfile and the first column is product
names and the second is a description of each. I am trying to find the sum
of all descriptions using sum(c.values)). Here is my code so far:

import csv
import json
import sys
#from sys import argv
from collections import defaultdict
from collections import Counter
#script, filename = argv
data = defaultdict(list)
counted_data = defaultdict(list)
grouped_data = defaultdict(list)

class dictionary:
with open ('weekly_20160102.csv', 'rb') as f:
reader = csv.reader(f)
next(reader, None)
for row in reader:
data[row[2]].append(row[3]) #this appends the description(value) to the
product name(key)
#new_item = {}
for key in data.keys():
#print key
c = Counter(data[key])
for value in c:
#print c[value]
if c[value] >= 5:
print key, ':', value, ':', c[value]
elif c[value] <= 1:
print 'other', ':', sum(c.values())


Please help!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!

2016-01-12 Thread Alan Gauld
On 12/01/16 20:36, Chelsea G wrote:

> data = defaultdict(list)
> 
> class dictionary:
>with open ('weekly_20160102.csv', 'rb') as f:
>   reader = csv.reader(f)
>   next(reader, None)
>   for row in reader:
>   data[row[2]].append(row[3]) 
>   for key in data.keys():
>   c = Counter(data[key])
>   for value in c:
>  if c[value] >= 5:
> print key, ':', value, ':', c[value]
>  elif c[value] <= 1:
> print 'other', ':', sum(c.values())

I think that's what your code was supposed to look like.
Am I right?

If so you have all the code inside a class definition.
But you do nothing with the class and it certainly doesn't
define a dictionary. Its not clear what the class line is for.

That aside, This implies the data format has 4 columns
and you are throwing away the first two and using
the third as a key to find the fourth.
Is that correct? It's certainly not what your introductory
paragraph said.

But I don't understand what you think the Counter is doing?
You are counting how many there are of each key, but a dict
can only have unique keys so it must always be 1.

Then you iterate over the Counter and none of that makes
any sense. I can't even think what you are trying to do.

Can you confirm the code layout - ideally by posting a plain
text version. And explain how you think it is supposed to
work.

Also please show us a sample (3-10 lines) of input data
and what exactly you expect the output to be.

Thanks,

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] HELP!!

2016-01-12 Thread Danny Yoo
On Tue, Jan 12, 2016 at 12:36 PM, Chelsea G  wrote:
> So I am importing a csv file to textfile and the first column is product
> names and the second is a description of each. I am trying to find the sum
> of all descriptions using sum(c.values)). Here is my code so far:

[code cut]

Code is sometimes useful, but it's also very important to express what
you see is going wrong.  Or, at the very least, try to explain the
problem as best as possible.

At the moment, all you've said is, effectively:

1.  I have this program.
2.  I need help!!!

Here's why these two pieces are often not enough.

1.  If your program can be executed by us, it may not be obvious or
clear that there's anything wrong with the program.  If your program
doesn't run, that's also no guarantee that we can do anything
effective.

For example, if we don't have your input file 'weekly_20160102.csv',
we can't determine whether your input is well-formed or not: perhaps
the input itself is wrong, and your program might be perfectly ok?

Or maybe it runs, but returns the wrong output.  How could we tell,
though?  What it means to have "wrong" output is something that's in
your head, and because we are not mind readers, we may not know what
"right" output looks like.

Or maybe it doesn't run.  In that case, if you show us the error, we
have an opportunity to explain what the error is trying to say, so
that you can understand what it means.  If you show us the error, then
we're more assured that we both are looking at the same thing.


The key thing here is: when you're asking for help on a program, try
to state up front what correct output looks like.  If the input is
big, then take a subset of the input, simplify it if necessary, and
present that to us.  Finally, present what you want the expected
result to look like.  Concrete is best.  When you say: " I am trying
to find the sum of all descriptions", I have to truthfully say that I
have no idea what this means.  Try expressing the idea concretely in
terms of what the input looks like, and what the output looks like.


2.  I know this will sound funny, but desperation doesn't work very
well as a strategy to get complicated things done.  Try to calm down.

If one is in "panic mode", then that person's brain is in a
flight-or-flight reactive state.  That would be productive if one
could run physically fast enough to get a program fixed.  But
programming is just not athletic.  Programming, and learning in
general, is something that's easier to do when you're not struggling
with immediate survival.

I'm not joking: I'm being very serious.  Please try to de-escalate the
stakes: don't make this a life-or-death situation.


Good luck!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor