RE: jython and toString

2006-10-16 Thread Walter S. Leipold
toString() isn't supposed to be a static method.  When you call
x.toString(), you're accessing x's non-static version of toString(), which
is inherited from Object. 

-- Walt


ivansh ([EMAIL PROTECTED]) wrote:
 For one java class (Hello) i use another (HelloPrinter) to build the
 string representation of the first one. When i've tried to use this
 from within jython,  HelloPrinter.toString(hello) call gives results
 like Object.toString() of hello has being called. The example below
 shows this behaviour.
 Could somebody explain this?
 
 // Hello.java
 package jythontest;
 public class Hello {
   private String name;
   public Hello(String name)
   {
   this.name = name;
   }
   public String sayHello()
   {
   return Hello, +name;
   }
 }
 
 // HelloPrinter.java
 package jythontest;
 public class HelloPrinter {
   public static String toString(Hello h)
   {
   return h.sayHello();
   }
 
   public static String toMyString(Hello h)
   {
   return h.sayHello();
   }
 }
 
 #  calljava.py
 from jythontest import *
 h = Hello(theName)
 print h
 print HelloPrinter.toString(h)
 print HelloPrinter.toMyString(h)
 
 OUTPUT:
 [EMAIL PROTECTED]   // GOOD
 [EMAIL PROTECTED]   // WRONG
 Hello, theName // GOOD
 
 
 Jython 2.1 on java (JIT: null)
 
 java version 1.5.0_03
 Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
 Java HotSpot(TM) Server VM (build 1.5.0_03-b07, mixed mode)
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: (semi-troll): Is Jython development dead?

2006-10-10 Thread Walter S. Leipold
John Roth ([EMAIL PROTECTED]) wrote:
 I've had a couple of inquiries about Jython support 
 in PyFIT, and I've had to say that it simply isn't 
 supported. The latest point release requires Python 
 2.3, and 2.4 will be required in the next year or so.
 
 John Roth
 Python FIT

Just last month, Sun hired Charles Nutter and Thomas Enebo to work on JRuby
full-time.  Can somebody with some street cred (like the PSF) do something
to persuade Sun to support Jython the same way?  

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


RE: Quote ? [was: John Bokma harassment]

2006-05-29 Thread Walter S. Leipold
Chris Uppal ([EMAIL PROTECTED]) wrote:
 Geoffrey Summerhayes wrote:
 
  After you kill Navarth, will it be nothing but gruff and deedle
  with a little wobbly to fill in the chinks?
 
 Where does that come from ?  It sounds like a quote, 
 and Navarth is a Jack Vance name (and /what/ a character),
 but I don't remember the rest of it occurring in Vance.

Trullion: Alastor 2262, a planet with a collectivist, sort-of-communist
government, a huge population, and a crumbling infrastructure -- 'gruff' and
'deedle' are sweet desserts much loved by the population.  

I think all three of the Alastor novels have been collected in a single
volume... [click click click...] Yep, ISBN 0312869525.  Classic Jack Vance,
and well worth reading.  

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


RE: Writing an OPC client with Python ?

2006-03-03 Thread Walter S. Leipold
Larry Bates wrote:
 pierlau wrote:
  I use an OPC server for connection to DC Drive.
  I would like to write a small OPC client.
  I have the dll OPCDAAuto.dll which contains all class
  and method but I wonder if its possible to instance in 
  python the class that are in the dll ?

 You can call methods/functions in a .dll using ctypes.
 
 http://starship.python.net/crew/theller/ctypes/

If all you want to do is *read* data from the OPC server, there's OPC
XML-DA, an XML-based access method for OPC data.  It should be possible to
access OPC data using a SOAP library.  Warning: Some OPC servers don't
support the XML-DA protocol.)  I haven't seen XML-DA done in Python yet
(I've been meaning to write a Python proof-of-concept for a year or more),
but implementations in other languages can be found via Google.

In case anybody's wondering, OPC is OLE for Process Control, the alleged
'open' standard for interfacing instruments and controls to HMI, SCADA, and
MES systems in industrial environments.  Microsoft's sponsorship of the OPC
Foundation was a brilliant piece of anti-competitive marketing; all of the
control system vendors have now standardized on OPC, and it's essentially
impossible to deploy any process monitoring or control computer that doesn't
speak OLE (i.e., that doesn't run Windows).  

(And, yes, I think it's idiotic for companies to build billions of dollars
worth of new manufacturing facilities whose information infrastructures
depend on a deprecated, single-vendor 'standard' like OLE.  And who the heck
wants a 'protocol' that isn't specified at the wire level, anyway?)  

-- Walt
As long as you've lit one candle,
you're allowed to curse the darkness.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: New Python.org website ?

2006-01-18 Thread Walter S. Leipold
Martin Maney writes:
 From a quick look, the beta appears to commit the same error as every
 design (as opposed to usability) driven web site in the 
 world: it makes the running text smaller than the user's default.  
 It's as if they care more about how it looks than whether I can read
 it...

The biggest flaw I've noticed is that the site's stylesheet displays
'visited' links the same color as 'unvisited' links, presumably to make the
page look more professional to the PHBs.  Unfortunately, this makes the site
much less usable; see Jakob Nielsen's column at
http://www.useit.com/alertbox/20040503.html for an explanation.  

-- Walt

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


Re: Spelling mistakes!

2006-01-08 Thread Walter S. Leipold

Terry Hancock ([EMAIL PROTECTED]) writes:
 BTW, one of the most common programming spelling errors is
 deprecate versus depreciate -- I wonder how many people
 actually realize that both words exist, but have entirely
 different meanings?  

That's a common spelling error, yes, but..  The number-one spelling error
among today's semi-literates is writing it's for the third-person neuter
possessive instead of its.  (These folks frequently write her's instead
of hers and who's instead of whose as well, but, strangely, hardly
ever write hi's for the masculine form.)  A native English speaker's
spelling of its is a very accurate measure of his general literacy.  

[Gee, I hope their were no spelling misteaks inn that paragraph...]

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


RE: Problems programming with Tkinter

2005-01-02 Thread Walter S. Leipold
Svenglenn writes:
 But, i want the program to open a new dialogue when i press 
 the button Visa ruta and in that dialogue will be a field 
 where you can enter a value directly in the program, but a 
 can't get it to work because is don't know how i shall do to 
 open a new dialogue window in the program?

For simple data entry (and file choosing, too!), use the built-in Tk
dialogs.  For example:

.import tkSimpleDialog
.
.answer = tkSimpleDialog.askString(
.Dialog title,
.Prompt,
.parent=root,
.initialvalue=Howdy!)
.if answer is not None:
....do something...

-- Walt

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


RE: The Industry choice

2004-12-31 Thread Walter S. Leipold
Paul Rubin writes:
 I don't know that C# is really that much different from Python.  
 I haven't used it but I have the impression that it's sort of similar
 under the skin. 

Nope nope nope.  C# is a statically typed, statically compiled (i.e., no
eval(...) or exec(...)), single-inheritance langauge with a
bondage-and-discipline syntax almost identical to Java's.  It compiles to
run on the Common Language Runtime, which is conceptually similar to the
JVM.  

Other than some syntactic sugar, C#'s primary difference from the latest
Java (v1.5) is that its standard libraries (the .Net stuff) are much poorer
-- this is particularly noticeable in its Collections API.  

-- Walt

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


RE: Is this a good use for lambda

2004-12-19 Thread Walter S. Leipold
Steven Bethard wrote:
 Charlie Taylor wrote:
I have tried using named functions instead of using lambda functions,
however, I always end up with a convoluted, hard to follow mess.
 ...
 Well, I think the jury could still be out on which version is more
 readable, but I don't understand the comment I have tried using 
 named functions instead of using lambda functions, however, I 
 always end up with a convoluted, hard to follow mess.  If you 
 know that:
 
 name = lambda *args, **kwds: expr
 
 is eqivalent to:
 
 def name(*args, **kwds):
  return expr
 
 then it's quite straightforward to translate from one to the other.

I think that Charlie's point is that, when you use def name, you have
name polluting your namespace.  The whole program becomes harder to
understand because you can't ignore name anywhere, even if it was only
ever intended to be used in one place.  It's a good point, and reasonable
people can disagree about whether the namespace pollution or the
unreadability of lambda is a bigger problem.  

I've used lambda from time to time, but only socially, and I can quit any
time I want...

-- Walt

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


RE: example code sought

2004-12-19 Thread Walter S. Leipold
Sean McIlroy wrote:
 What I want to do is simply to move a shape around on 
 the screen using the mouse. I've looked at Tkdnd.py but 
 I can't seem to extract what I need from the more involved 
 stuff in there.

Here's a simple sample that displays random rectangles that can be dragged
around a Canvas:

=-=-=-=-=-=-=-=-=-=

#!/usr/bin/python
# dsimp.py -- test object dragging

import sys
import math
import Tkinter
import random

class DragCanvas(Tkinter.Frame):
A canvas containing 'nrect' random draggable rectangles.
tilecolors = (
cyan, gold, lightgreen, green,
darkgreen, lightblue, blue,
darkblue, pink, red,
)

def __init__(self,master,nrect=1):
Create the Canvas and a bunch of rectangles.
Tkinter.Frame.__init__(self,master)
self.bbox = (0,0,600,400)
self.master = master
self.nrect = nrect
self.rand = random.Random()
self.dragging = 0
self.item = -1
self.xbase = 0
self.ybase = 0

self.xscroll = Tkinter.Scrollbar(self,
orient=Tkinter.HORIZONTAL)
self.yscroll = Tkinter.Scrollbar(self,
orient=Tkinter.VERTICAL)
self.xscroll.pack(side=Tkinter.BOTTOM,fill=Tkinter.X)
self.yscroll.pack(side=Tkinter.RIGHT,fill=Tkinter.Y)

self.world = Tkinter.Canvas(self,
width=self.bbox[2],
height=self.bbox[3],
xscrollcommand=self.xscroll.set,
yscrollcommand=self.yscroll.set,
borderwidth=1,
relief=Tkinter.GROOVE)

self.xscroll.config(command=self.world.xview)
self.yscroll.config(command=self.world.yview)

self.world.pack(fill=Tkinter.BOTH)

# Mouse commands for this view.
self.world.bind(Button-1,self.__doimageClick)
self.world.bind(ButtonRelease-1,self.__doimageUnclick)
self.world.bind(B1-Motion,self.__doimageDrag)

for i in range(0,self.nrect):
# Compute graphics coordinates of tile.
# (Note first row/col offset by 1 pixel from top/left.)
xsize = self.rand.randrange(30,80)
ysize = self.rand.randrange(20,50)
x1 = self.rand.randrange(0,360)
y1 = self.rand.randrange(0,260)
# Create a random rectangle.
rectnum = self.world.create_rectangle(
x1,y1,x1+xsize,y1+ysize,
fill=self.rand.choice(DragCanvas.tilecolors))

# Limit scrolling in the view.
#self.world.config(scrollregion=self.world.bbox(Tkinter.ALL))
self.world.config(scrollregion=self.bbox)

def __doimageClick(self,event):
User clicked mouse; start dragging if item found.
x = self.world.canvasx(event.x)
y = self.world.canvasy(event.y)
items = self.world.find_overlapping(x-2,y-2,x+2,y+2)
if len(items)  0:
self.dragging = 1
self.item = items[-1] # Topmost item is returned last.
self.xbase = x
self.ybase = y

def __doimageUnclick(self,event):
User released mouse; stop dragging.
self.dragging = 0
self.item = -1

def __doimageDrag(self,event):
Drag an item around the map.
if not self.dragging:
return
x = self.world.canvasx(event.x)
y = self.world.canvasy(event.y)
self.world.move(self.item,x-self.xbase,y-self.ybase)
self.xbase = x
self.ybase = y


def doexit():
Exit the program, discarding changes.
sys.exit(0)


root = Tkinter.Tk()
root.geometry(400x300)
root.title(Draggable?)

mbar = Tkinter.Menu(root)
root.config(menu=mbar)
filemenu = Tkinter.Menu(mbar)
mbar.add_cascade(label=File,menu=filemenu)
filemenu.add_separator()
filemenu.add_command(label=Exit,command=doexit)

worldview = DragCanvas(root,12)
worldview.pack()
root.mainloop()

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