Re: Easy-to-use Python GUI

2008-12-24 Thread Raven
On 25 дек, 06:47, "Joel Koltner"  wrote:
> Is there an easy-to-use, "function"-based cross-platform GUI toolkit for
> Python out there that's a little more sophisticated than EasyGui?  EasyGui
> looks good, but it's a little more restrictive than what I'd like to have, yet
> I'm (stubbornly :-) ) resistant to stepping up to a "full service" GUI toolkit
> such as pyGTK or wxPython where it's all about event loops and callbacks and
> you need to start planning how the GUI affects the overall program flow rather
> than just using a "forms" (or "Wizard")-type approach where you put up a few
> dialogs, users fill in some variables, and your program just sits around
> waiting until "OK" or "Cancel" is clicked.
>
> One approach that I like comes from SAX BASIC/WinWrap, which is more or less a
> clone of Microsoft's Visual BASIC for Applications, but they (apparently)
> wanted everything to still be human-readable, so they have a simple GUI
> ("form") builder that generates code that looks like this:
>
> ---
>
>  Begin Dialog UserDialog 850,497,"Export Control" ' %GRID:10,7,1,1
>
>   GroupBox 20,7,360,217,"Drill File Generation",.GroupBox1
>   CheckBox 40,35,130,14,"Output drill file(s)",.genDrill
>   Text 40,63,270,28,"Identify via layers as any that contain this text in
> their names:",.Text
>   TextBox 40,98,220,21,.viaLayerName
>   Text 40,140,100,14,"Output method:",.Text8
>   DropListBox 160,140,180,21,DrillStyle(),.drillStyle
>   Text 40,175,130,28,"Select drill table units:",.Text2
>   ListBox 200,175,120,28,unitNames(),.unitName
>
>   OKButton 310,469,90,21
>   CancelButton 410,469,90,21
>
>  End Dialog
>
> ' GUI builder generates or modifies everything above, but can also be edited
> by hand
> ' You write the following code...
>
>  Dim dlg As UserDialog
>
>  dlg.genDrill = 1
>  ReDim DrillStyle(1)
>  DrillStyle(0) = "All Via Layers In One File"
>  DrillStyle(1) = "One File Per Via Layer"
>  dlg.drillStyle = 1
>
>  func=Dialog(dlg)
>
> ---
>
> This is pretty darned easy for me understand and modify either by hand or with
> the GUI builder.  Still, it's quite powerful, since it supports all the common
> GUI elements (text, group boxes, checkboxes, drop-down lists, text boxes,
> buttons, etc.).  This is about the level of sophistication I'm looking for.
>
> Anything like this for Python?
>
> Thanks,
> ---Joel

Try PyScripter :)
http://mmm-experts.com/Products.aspx?ProductId=4
--
http://mail.python.org/mailman/listinfo/python-list


cxFreeze executable linked to /usr/lib/libpython2.3.so

2006-06-06 Thread Raven
Hi,
I compiled a python script using cxFreeze because I need a standalone
application, while the Windows version runs without any python
installation the linux version of the executable is linked to

libpython2.3.so.1.0 => /usr/lib/libpython2.3.so.1.0


thus the end user have to install python 2.3 in order to run the
binary. I would like to know if it's possible, using cxFreeze to create
a binary that is not linked to any python system library, for example
by putting the library in the directory where the binary file is
located.
Thank

Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxTreeCtrl Q?

2006-02-01 Thread Raven
I hope this can help:

http://wxwidgets.org/manuals/2.6.1/wx_wxtreectrl.html#wxtreectrlsetitemfont
http://wxwidgets.org/manuals/2.6.1/wx_wxtreectrl.html#wxtreectrlsetitembold

This pages are from the wxwidgets api reference but the functions are
the same in wxPython

Bye

Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-04 Thread Raven
Cameron Laird wrote:

> This thread confuses me.
>
> I've lost track of the real goal.  If it's an exact calculation of
> binomial coefficients--or even one of several other potential
> targets mentioned--I echo Steven D'Aprano, and ask, are you *sure*
> the suggestions already offered aren't adequate?

Hi Cameron, my real goal was to calculate the hypergeometric
distribution. The problem was that the  function for hypergeometric
calculation from scipy uses the scipy.comb function which by default
uses floats so for large numbers comb(n,r) returns inf. and hence the
hypergeometric returns nan.
The first suggestion, the one by Robert Kern,  resolved my problem:

Raven wrote:
>Thanks to all of you guys, I could resolve my problem using the
>logarithms as proposed by Robert.

Then the other guys gave alternative solutions so I tried them out. So
form me the suggestions offered are more than adequate :-)

Cameron Laird wrote:
>Also, I think you
> might not realize how accurate Stirling's approximation (perhaps to
> second order) is in the range of interest.

The problem with Stirling's approximation is that I need to calculate
the hypergeometric hence the factorial for numbers within a large range
e.g. choose(14000,170) or choose(5,2)

Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-03 Thread Raven

Travis E. Oliphant wrote:

> Notice the keyword for the comb function (in scipy) lets you use it to
> compute exact values.   SciPy does not just automatically use the long
> integer because this will always slow you down.
>
> comb(N, k, exact=0)
>
> Combinations of N things taken k at a time.
>
> If exact==0, then floating point precision is used, otherwise
> exact long integer is computed.
>
> Notes:
>- Array arguments accepted only for exact=0 case.
>- If k > N, N < 0, or k < 0, then a 0 is returned.
> 
> -Travis Oliphant

Great, thanks Travis.
Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-02 Thread Raven

Bengt Richter wrote:


> ISTM you wouldn't get zero if you scaled by 10**significant_digits (however 
> many
> you require) before dividing. E.g., expected hits per trillion (or septillion 
> or whatever)
> expresses probability too. Perhaps that could work in your calculation?
>
> Regards,
> Bengt Richter

Sorry but I can't figure out how to do it, can you give me an example
please? 
Thnx

Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-02 Thread Raven

Bengt Richter wrote:

> ISTM you wouldn't get zero if you scaled by 10**significant_digits (however 
> many
> you require) before dividing. E.g., expected hits per trillion (or septillion 
> or whatever)
> expresses probability too. Perhaps that could work in your calculation?
>
> Regards,
> Bengt Richter

Sorry Bengt but I can't figure out how to do it, can you give me an
example please? Thanks in advance.
Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-02 Thread Raven
Scott David Daniels ha scritto:

> You should really look into the timeit module -- you'll get nice
> solid timings slightly easier to tweak.

This seems a very interesting module, I will give it a try as soon as
possible. Thanks Scott.
Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-02 Thread Raven
Well, what to say? I am very happy for all the solutions you guys have
posted :-)
For Paul:
I would prefer not to use Stirling's approximation


The problem with long integers is that to calculate the hypergeometric
I need to do float division and multiplication because integer division
returns 0. A solution could be to calculate log(Long_Factorial_Integer)
and finally calculate the hypergeometric with the logarithmic values.
I've done a test: iterated 1000 times two different functions for the
hypergeometric, the first one based on scipy.special.gammaln:

from scipy.special import gammaln

def lnchoose(n, m):
  nf = gammaln(n + 1)
  mf = gammaln(m + 1)
  nmmnf = gammaln(n - m + 1)
  return nf - (mf + nmmnf)

def hypergeometric_gamma(k, n1, n2, t):
  if t > n1 + n2:
t = n1 + n2
  if k > n1 or k > t:
return 0
  elif t > n2 and ((k + n2) < t):
return 0
  else:
c1 = lnchoose(n1,k)
c2 = lnchoose(n2, t - k)
c3 = lnchoose(n1 + n2 ,t)

return exp(c1 + c2 - c3)

and the second one based on the code by Steven and Scott:


import time
from math import log, exp

def bincoeff1(n, r):
  if r < n - r:
r = n - r
  x = 1
  for i in range(n, r, -1):
x *= i
  for i in range(n - r, 1, -1):
x /= i
  return x

def hypergeometric(k, n1, n2, t):
  if t > n1 + n2:
t = n1 + n2
  if k > n1 or k > t:
return 0
  elif t > n2 and ((k + n2) < t):
return 0
  else:
c1 = log(raw_bincoeff1(n1,k))
c2 = log(raw_bincoeff1(n2, t - k))
c3 = log(raw_bincoeff1(n1 + n2 ,t))

return exp(c1 + c2 - c3)

def main():
  t = time.time()
  for i in range(1000):
r = hypergeometric(6,6,30,6)
  print time.time() - t

  t = time.time()
  for i in range(1000):
r = hypergeometric_gamma(6,6,30,6)
  print time.time() - t


if __name__ == "__main__":
  main()


and the result is:

0.0386447906494
0.192448139191

The first approach is faster so I think I will adopt it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2006-01-01 Thread Raven
Thanks Steven for your very interesting post.

This was a critical instance from my problem:

>>>from scipy import comb
>>> comb(14354,174)
inf

The scipy.stats.distributions.hypergeom function uses the scipy.comb
function, so it returned nan since it tries to divide an infinite. I
did not tried to write a self-made function using standard python as I
supposed that the scipy functions reached python's limits but I was
wrong, what a fool :-)

>If you are calculating hundreds of hypergeometric probabilities, 30
>seconds each could be quite painful, but it certainly shows that Python is
>capable of doing it without resorting to logarithms which may lose some
>significant digits. Although, in fairness, the log function doesn't seem
>to lose much accuracy for arguments in the range you are dealing with.

Yes I am calculating hundreds of hypergeometric probabilities so I need
fast calculations

Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Hypergeometric distribution

2005-12-31 Thread Raven
Thanks to all of you guys, I could resolve my problem using the
logarithms as proposed by Robert.  I needed to calculate the factorial
for genomic data, more specifically for the number of genes in the
human genome i.e. about 30.000 and that is a big number :-)
I didn't know gmpy
Thanks a lot, really

Ale

-- 
http://mail.python.org/mailman/listinfo/python-list


Hypergeometric distribution

2005-12-26 Thread Raven
Hi to all, I need to calculate the hpergeometric distribution:


   choose(r, x) * choose(b, n-x)
p(x; r,b,n) =  -
   choose(r+b, n)

choose(r,x) is the binomial coefficient
I use the factorial to calculate the above formula but since I am using
large numbers, the result of choose(a,b) (ie: the binomial coefficient)
is too big even for large int. I've tried the scipy library, but this
library calculates
the hypergeometric using the factorials too, so the problem subsist. Is
there any other libray or an algorithm to calculate
the hypergeometric distribution? The statistical package R can handle
such calculations but I don't want to use python R binding since I want
a standalone app.
Thanks a lot
Ale

-- 
http://mail.python.org/mailman/listinfo/python-list