A Fixed Tk Text widget

2008-04-13 Thread Ron Provost
I have just completed and uploaded to the Tkinter wiki a Fixed version of the 
Tk Text widget called EnhancedText.  This new widget (subclassed from Text) is 
intended to fix some of the quirks of the Text widget involving cursor 
movement.  Namely, in Text, the cursor moves by paragraph rather than 
display-line when using the Up and Down arrow keys and it jumps to the 
beginning and end of a paragraph when using the 'Home' and 'End' keys.

EnhancedText rewrites all the event handling of the Text widget.  With 
EnhancedText, Up, Down, Home and End now move according to display lines rather 
than Paragraphs.

This widget can be found here http://tkinter.unpythonic.net/wiki/EnhancedText.

Thanks for any comments, bug reports, etc.

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

tkinter coordinates, conversion

2008-03-29 Thread Ron Provost
Is there any way in tkinter to convert between coordinate systems?  
Specifically, I'm refering to the canvas.  I'm getting x and y's back in mouse 
events and I would like to convert them back to inches 'i', centemeters 'c', 
millimeters 'm' or points 'p'.  Which I wish to use to provided information 
back to the user.

Thanks,
Ron-- 
http://mail.python.org/mailman/listinfo/python-list

New Full Tkinter document editor widget -- suggestions, comments, etc.

2008-03-24 Thread Ron Provost
I've posted a demo (http://tkinter.unpy.net/wiki/StyledEditor).  This demo 
creates a widget with full styled editing capabilities; sort of a 
mini-word processor.  It runs as is on my WinXP machine with Python 2.5. 
The demo allows styling of any selected text via toolbars; just select the 
text, then select the styling.  Also included are buttons to save and 
retrieve all content and styling information (works for the small tests I've 
tried myself, not guaranteed bug-free).

The actual widget wraps the Text widget to give greater freedom in the 
assignment of any single styling attribute to any region.  This differs from 
the Text widget itself in that the Text widget does not allow you to 
individually assign a family, size, weight or slant with tag_config().  That 
is, for example, you can't simply apply 'bold' to some region of text.

This demo was written quite quickly (I pounded it out over the weekend) so 
I'm sure it's full of bugs.  Also in my desire to get something working 
quickly its API doesn't really work like a normal widget, so I guess this 
serves as more of a proof of concept than full-blown widget but the basic 
functionality is there.  I'm presenting it here because I thought maybe 
others might have thoughts on how to improve it.

API Notes:

applyStyleAttribute( index1, index2, attributeName, attributeValue )

This method is is frontend to the business.  attributeName and 
attributeValue may be any option accpeted by tag_config() of the Text widget 
along with appropriate value.  There are also some ''new'' options:

- 'family', attributeValue is a font family name
- 'size', attributeValue is a font point size
- 'weight', attributeValue is one of: 'normal', 'bold'
- 'bold', attributeValue is a boolean (alternative to using 'weight')
- 'slant', attributeValue is one of: 'roman', 'italic'
- 'italic', attributeValue is boolean (alternative to using 'slant')

Several previously existing options have some new values:

'spacing1', 'spacing2' and 'spacing3' may take 'None', 'Half Line', 'One 
Line' or 'Two Lines' in addition to any of the values acceptable by 
tag_config().

'offset' may take 'normal', 'superscript' or 'subscript' in addition to any 
value acceptable by tag_config.

Please download and try-out my demo 
(http://tkinter.unpy.net/wiki/StyledEditor).  I'm anxious for suggestions 
and comments.

Ron Longo 

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


Re: Removal of tkinter from python 3.0? [was: Fate of the repr module inPy3.0]

2008-03-20 Thread Ron Provost
I would really hate to see Tkinter removed from 3.0.  Because it's part of 
the distribution and extremely easy to create simple GUIs I use it all the 
time.  Isn't Python supposed to be a Batteries Included language?  Can 
that be said anymore without a GUI library?  And do we want to drop Tkinter 
only now, when tk seems to finally be getting renewed attention after years 
of neglect?

- Original Message - 
From: Daniel Fetchinson [EMAIL PROTECTED]
To: python-list@python.org
Sent: Thursday, March 20, 2008 3:39 AM
Subject: Removal of tkinter from python 3.0? [was: Fate of the repr module 
inPy3.0]


 Was looking at PEP 3108, http://www.python.org/dev/peps/pep-3108/ ,
 and saw that the repr module was slated for vaporization. I've only
 used the module a few times ever. I'm curious if the community wants
 it kept around or whether it is considered clutter.

 The PEP is going to be finalized soon, so if you have issues with it,
 they should be sent to the PEP author or brought up on the list,
 http://mail.python.org/mailman/listinfo/stdlib-sig .

 Is it just me or others also think that it would be a major loss to
 remove tkinter from the python core? PEP 3108 starts off with:

 Each module to be removed needs to have a justification as to why it
 should no longer be distributed with Python.

 then goes on with,

 With so many other GUI options out there that are considered better
 than Tkinter, it might be best to remove Tkinter from the stdlib and
 make it an externally maintained package.

 I don't get it. There are many [insert your favorite software
 component] options outside of the python core that are considered
 better than the one coming with python, yet they don't get removed.
 All network servers for example could be thrown out because twisted is
 considered better. This just doesn't make sense to me. Tkinter is
 great for its purpose, typical use cases are creating a simple GUI
 composed of a couple of components only. You can nicely do this with
 tkinter and the large user base shows that it's a real need real
 people have. Sure, for fancy GUI stuff there are better options but
 for quick and simple things tkinter is just great. And last time I
 checked python comes with batteries included so why sould I need to
 search and download a third party package for such a common use case?

 Thoughts anyone?

 Cheers,
 Daniel
 -- 
 http://mail.python.org/mailman/listinfo/python-list 

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


RE: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread Ron Provost
The division between philosophy and science can be fine indeed.  Philosophy and 
science are the two rigorous methods of inquiry into the fundamental nature of 
things (other methods include religion and superstition).  Because of it's 
process, science limits itself to those questions which can be tested 
expermientally.  Philosophy is left to address the remaining questions which 
can be examined through reason (mostly deduction).  Of many of the questions 
which were thought to be only answerably via philosophy, often someone finds a 
way to test some of them.  This is very often the case in areas of philosophy 
studying the fields involving the mind and nature.  Thus whold chunks of 
philosophy slowly become the realms of psychology, lingustics, logic (Which as 
a whole became the realm of the theoretical science of math around), and many 
of the questions about the nature of the universe, existance and time have 
become the realm of physics.  In this way philosophy may be thought of as the 
cutting edge of science.

Similarly science itself has uncovered new questions which currently can only 
be addressed through the methods of philosophy.  One of the most interested and 
recently practical have been investigations into the foundations of science.  
For example, Karl Popper was interested in the process of science and what 
constitutes a scientific theory vs. non-scientific theory.  His answer:  A 
scientific theory is falsifyable via the techniques of science (that is 
experimentation).  This is practical today, because it excludes the whole 
intelligent design theory from science, little if any of which is falsifyable.

Thus the line that divides philosophy and science is fine.  The two disciplies 
in fact need oneanother.  Science uncovers new information used by philosophy 
to build new philosophical theories while philosophy spends a huge amount of 
time questioning or judging the practices of other fields such as science in 
much the same way as the US supreme court is supposed to work to check on the 
other branches of the government.-- 
http://mail.python.org/mailman/listinfo/python-list

CoCoPy Release Candidate

2007-12-19 Thread Ron Provost
I'm happy to announce the CoCo/r for Python release candidate.  CoCo/r is an 
scanner generator and LL(k) parser generator which has already been ported to 
many languages.  CocoPy 1.1.0rc can be found in the Python Package Index.

CoCo/r for Python now passes all tests in the official COCO test suite 
(http://www.ssw.uni-linz.ac.at/coco/).

Features:
- The generated scanner and parser are completely independant.  Either is 
easily replaced by handwritten equivalents.

- The syntax for the target language specification is reminicent of the Pascal 
family of languages.

- The production syntax is not the usual UNIX regular expression syntax.  
Instead, CoCo uses the much more readable EBNF syntax introduced by Nicholas 
Wirth.  This same syntax is used for writing productions for both the regular 
(token syntax) and context free (phrase or statement syntax) grammars.

- The specification language supports botn inherited and synthetic attributes; 
as well as embedding semantic actions throughout a production.

- The generated scanners are DFAs.

- The generated parsers are recursive descent (hence the /r in CoCo/r)

- Features like comments and case (in)sensativity are handled automatically.

- Lexemes may be context dependant.

- CoCo provides a unique and easy to use error recovery system; a difficult 
problem in recursive descent parsers.

- The developer can customize error messages and event include his own.

What follows is a very simplistic example compiler included in the distribution.

# === Calc.atg

COMPILER Calc

   # ---
   # Everything here goes into the parser class

   VARS = [ 0 ] * 1000   # Create an array to hold the variables

   def getSpix( self ):
  varName = self.token.val.upper()   # Grab the most recently parsed lexeme

  if len(varName) = 2:
 return 26*(ord(varName[1])-ord('A'))+(ord(varName[0])-ord('A'))
  else:
 return ord(varName[0])-ord('A')

   def getNumber( self ):
  return int(self.token.val)

   def newVar( self, spix ):
  self.VARS[ spix ] = 0

   def getVar( self, spix ):
  return self.VARS[ spix ]

   def writeVal( self, val ):
  print val

   def readVal( self, spix ):
  self.VARS[ spix ] = int(raw_input( 'Read ' ))

   def setVar( self, spix, val ):
  self.VARS[ spix ] = val

   # End of definitions for parser class
   # -

IGNORECASE

CHARACTERS
  letter = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.
  digit  = 0123456789.
  eol= CHR(13) .
  lf = CHR(10) .

TOKENS
  ident  = letter {letter | digit} .
  number = digit {digit} .

COMMENTS
  FROM '--' TO eol

IGNORE eol + lf

PRODUCTIONS
  Calc =
[Declarations] StatSeq .

  Declarations
=
   'VAR'
   Identout spix(. self.newVar(spix)   .)
   { ',' Identout spix  (. self.newVar(spix)   .)
   } ';'
.

  StatSeq =
Stat {';' Stat}.

  Stat
=
READ  Identout spix   (. self.readVal(spix)  .)
  | WRITE Exprout val (. self.writeVal(val)  .)
  | Identout spix := Exprout val(. self.setVar(spix, val)  .)
.

  Exprout exprVal
=
  Termout exprVal
  {  '+' Termout termVal(. exprVal += termVal .)
  |  '-' Termout termVal(. exprVal -= termVal .)
  }
.

  Termout termVal
=
  Factout termVal
  {  '*' Factout factVal(. termVal *= factVal .)
  |  '/' Factout factVal(. termVal /= factVal .)
  }
.

  Factout factVal
=
 Identout spix  (. factVal = self.getVar(spix) .)
  |  number   (. factVal = self.getNumber()  .)
  | '(' Exprout factVal ')'
.

  Identout spix
= ident   (. spix = self.getSpix()   .)
.

END Calc.


# ---Sample input 
calc.inp

VAR
  A,B,C,D;
  WRITE 1+(2*3)+4;
  WRITE 100/10;
  READ  A;
  WRITE A;
  B := A*16;
  WRITE B*2

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

Re: Rounding

2007-12-18 Thread Ron Provost
Adding 0.5, then converting to an int always works for me.

 x = 6.345
 int( x + 0.5 )
 6

Ron


- Original Message - 
From: katie smith [EMAIL PROTECTED]
To: python-list@python.org
Sent: Saturday, December 15, 2007 9:09 AM
Subject: Rounding


 if i have a number 6.345 and i wanted it to be 6 without subtracting .345 
 because it won't always be .345 what do i do?

 how do i round to the nearest whole number. Or in this case round down. Is 
 there an easy way to round down to the nearest whole number?


 
 
 Never miss a thing.  Make Yahoo your home page.
 http://www.yahoo.com/r/hs

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

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


Re: finding dir of main .py file

2007-12-11 Thread Ron Provost
Thanks, didn't realize it would be quite so easy.


- Original Message - 
From: Matt Nordhoff [EMAIL PROTECTED]
To: ron.longo [EMAIL PROTECTED]
Cc: python-list@python.org
Sent: Tuesday, December 11, 2007 2:50 PM
Subject: Re: finding dir of main .py file


 ron.longo wrote:
 Nope, maybe I'm not explaining myself well.
 
 When I do os.getenv('HOME') I get back None.
 
 According to the docs, 'HOME' is the user's home directory on some
 platforms.  Which is not what I want.
 
 What I want is the directory in which an application's main .py file
 resides.  That is, when I type: python MyApp.py, I want to know in which
 directory does MyApp.py reside?
 
 Shane is right.
 
 print __file__
 
 print modulename.__file__
 
 Just call os.path.dirname() on __file__ to get the directory.
 -- 
 -- 
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Is Python really a scripting language?

2007-12-11 Thread Ron Provost
OK, I don't mean to start any sort of war or flaming or anything here but I 
really need to discuss this with other afficionados of Python - I know none 
other than myself.

I'm a software developer.  Where I work, the dominant development language is 
Java with some mostly-legacy C/C++ software.  In places where I don't need to 
directly integrate with our Java suite of apps, the first thing I ask is, do 
you mind if I do that in Python?  in several cases I was given approval after 
demonstrating stuff I've already done (These people giving approval are 
generally not very technical).

Now, I've also shown my applications (both work related and my own projects) to 
other developers at work.
Some of the applications I've written are quite sophisticated.  I have software 
which uses pymedia to playback media files and Tkinter/Tix apps with quite-good 
(infact called very professional looking by a few coworkers) GUIs.  Apps that 
process thousands of records of data in less than a second, and an application 
I developed which launches our suite of Java applications (previously 
everything needed to be launched by hand with lots of command-line parameters). 
 Configurations (that specify which apps and which command line parameters) can 
be created, edited, deleted, saved and loaded.  In addition, once the suite of 
applications is running, my application continues to monitor all the processes 
(many of which don't have GUIs).  The application alerts the user if an app 
appears to start taking over memory or %CPU (Our app suite is extremely large 
and complex) and allows a user to selectively terminate apps.  It's incredibly 
useful and I've gotten nothing but complements on the app.

But here's my problem, most of my coworkers, when they see my apps and learn 
that they are written in Python ask questions like, Why would you write that 
in a scripting language?  Whenever I hear a comment like that I can feel 
myself boiling inside.  While many call Python a scripting language, I acutally 
use it as a full-fledged programming language.  To me a scripting language is 
sort of like a shell language where I may process output of one app, feed it 
into another, etc.  That is, a scripting language (by my definition) pulls apps 
together.  I don't use python like that (in fact, after my suite launching app 
I feel subprocess is very immature).  What's so different from python 
generating .pyc files and executing them from javac producing .class files 
which you then run on java?

I've been in the Python world since version 2.3 final was released, so I don't 
know a lot about the history of Python.  Was Python originally more like a 
scripting language and the culture of refering to it as scripting has just 
stuck?  I would like to see the Python world get away from the script term, 
perhaps starting in Python 3.x.

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

CoCoPy Beta released

2007-12-01 Thread Ron Provost
I would like to introduce CoCo/r to the Python world.  CoCo/r is an scanner 
generator and LL(k) parser generator which has already been ported to many 
languages.  CocoPy 1.0.3b1 can be found in the Python Package Index.

Features:
- The generated scanner and parser are completely independant.  Either is 
easily replaced by handwritten equivalents.

- The syntax for the target language specification is reminicent of the Pascal 
family of languages.

- The production syntax is not the usual UNIX regular expression syntax.  
Instead, CoCo uses the much more readable EBNF syntax introduced by Nicholas 
Wirth.  This same syntax is used for writing productions for both the regular 
(token syntax) and context free (phrase or statement syntax) grammars.

- The specification language supports botn inherited and synthetic attributes; 
as well as embedding semantic actions throughout a production.

- The generated scanners are DFAs.

- The generated parsers are recursive descent (hence the /r in CoCo/r)

- Features like comments and case (in)sensativity are handled automatically.

- Lexemes may be context dependant.

- CoCo provides a unique and easy to use error recovery system; a difficult 
problem in recursive descent parsers.

- The developer can customize error messages and event include his own.

What follows is a very simplistic example compiler included in the distribution.

# === Calc.atg

COMPILER Calc

   # ---
   # Everything here goes into the parser class

   VARS = [ 0 for x in xrange( 0, 1000 ) ]   # Create an array to hold the 
variables

   def getSpix( self ):
  varName = self.token.val.upper()   # Grab the most recently parsed lexeme

  if len(varName) = 2:
 return 26*(ord(varName[1])-ord('A'))+(ord(varName[0])-ord('A'))
  else:
 return ord(varName[0])-ord('A')

   def getNumber( self ):
  return int(self.token.val)

   def newVar( self, spix ):
  self.VARS[ spix ] = 0

   def getVar( self, spix ):
  return self.VARS[ spix ]

   def writeVal( self, val ):
  print val

   def readVal( self, spix ):
  self.VARS[ spix ] = int(raw_input( 'Read ' ))

   def setVar( self, spix, val ):
  self.VARS[ spix ] = val

   # End of definitions for parser class
   # -

IGNORECASE

CHARACTERS
  letter = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.
  digit  = 0123456789.
  eol= CHR(13) .
  lf = CHR(10) .

TOKENS
  ident  = letter {letter | digit} .
  number = digit {digit} .

COMMENTS
  FROM '--' TO eol

IGNORE eol + lf

PRODUCTIONS
  Calc =
[Declarations] StatSeq .

  Declarations
=
   'VAR'
   Identout spix(. self.newVar(spix)   .)
   { ',' Identout spix  (. self.newVar(spix)   .)
   } ';'
.

  StatSeq =
Stat {';' Stat}.

  Stat
=
READ  Identout spix   (. self.readVal(spix)  .)
  | WRITE Exprout val (. self.writeVal(val)  .)
  | Identout spix := Exprout val(. self.setVar(spix, val)  .)
.

  Exprout exprVal
=
  Termout exprVal
  {  '+' Termout termVal(. exprVal += termVal .)
  |  '-' Termout termVal(. exprVal -= termVal .)
  }
.

  Termout termVal
=
  Factout termVal
  {  '*' Factout factVal(. termVal *= factVal .)
  |  '/' Factout factVal(. termVal /= factVal .)
  }
.

  Factout factVal
=
 Identout spix  (. factVal = self.getVar(spix) .)
  |  number   (. factVal = self.getNumber()  .)
  | '(' Exprout factVal ')'
.

  Identout spix
= ident   (. spix = self.getSpix()   .)
.

END Calc.


# ---Sample input 
calc.inp

VAR
  A,B,C,D;
  WRITE 1+(2*3)+4;
  WRITE 100/10;
  READ  A;
  WRITE A;
  B := A*16;
  WRITE B*2

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

Tkinter container frames

2007-12-01 Thread Ron Provost
I've been trying to figure out how to use the container option in a frame 
widget in conjunction with the use option with a Toplevel widget.  Which 
according to the documentation I've read sounds like it will give me a Windows 
MDI like application with free-floating child windows within the container 
widget.  Has anyone successfully used this feature?  Here's the code I've been 
playing with.

Thanks for any help.



import Tkinter as Tk


tkRoot = Tk.Tk( )
f = Tk.Frame( tkRoot, container=True )
f.pack( )

t1 = Tk.Toplevel( use=f )
b1  = Tk.Button( t1, text=Pres me )
b1.pack( )

t2 = Tk.Toplevel( use=f )
b2  = Tk.Button( t2, text=No pres me! )
b2.pack( )


tkRoot.mainloop( )

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

Tk 8.5

2007-11-26 Thread Ron Provost
Hello,

According to the tk wiki, the final release of Tcl/Tk is just weeks away (see 
http://wiki.tcl.tk/12753).  Does anyone know if the Tk enhancements will be in 
Python 2.6?  Since I don't use tk but I do use Python and Tkinter (and Tix) 
extensively, I'm excited about these long-awaited changes.

Thanks,
Ron
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Creating Table using Tkinter

2007-09-27 Thread Ron Provost
Ankit,

Have you tried the HList (or one of the descendant widgets) in Tix?  The Tix 
library includes quite a few additional widgets and it's part of the 
standard python distribution.

Ron
- Original Message - 
From: Ankit [EMAIL PROTECTED]
Newsgroups: comp.lang.python
To: python-list@python.org
Sent: Thursday, September 27, 2007 2:42 PM
Subject: Creating Table using Tkinter


 Hi guys i need to make a table to store a certain data using
 Tkinter..I have searched on the group but i have not been able to find
 a solution that would work for me..The thing is that i want my table
 to be scrollable both horizontally and vertically and i also want to
 transmit the data from the table serially to a microcontroller so i
 also need to make sure that i am able to read all the data
 individually..I am writing my code on Windows..my table is dynamic
 that is the number of columns are fixed but the number of rows can
 vary that would depend on the user..Initially i ask him about the
 number of rows...Waiting for your replies..

 Regards
 Ankit Anand

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

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


Tix HList missing at least one method

2007-08-28 Thread Ron Provost
According to the Tix documentation online, HList has an info_bbox() method 
which returns the bounding box of a given item in the HList.  However, when I 
try to call this method, I get an attribute error.  Looking at Tix.py I see 
that info_bbox() is not implemented.

Hazarding a chance (mostly by looking at the other method implementation) I see 
if I can define it myself.

def info_bbox( self, entry ):
   return [ int(pos) for pos in self.tk.call( self._w, 'info', 'bbox', 
entry).split() ]

When I use this implementation it works.  Why's info_bbox() been left out of 
HList?

I can't formulate a work-around for what I'm trying to do.  I need info_bbox().

Here's why:

I'm currently working on a project which involves some fairly complex GUIs.  It 
displays data in the form of an outline which the user can edit, it also 
generates web pages.  To allow a natural feel to editing the order of the items 
in the outline, I decided to make use of the Tkinter drag and drop module: 
Tkdnd.  To do this correctly, I need to do a bit of arithmetic with screen 
coordinates while in a drag operation  (so I can change the cursor during the 
drag) so that I can determine if my current drag position (potential drop 
position) is above, below or as a child of some other item in the outline.  The 
easiest way to do this is to get the bounding box of the nearest items.


Thanks,
Ron-- 
http://mail.python.org/mailman/listinfo/python-list

idestudio

2007-06-27 Thread Ron Provost
Has anyone been able to download idestudio?  Any link I find on google is 
broken.

Thanks,
Ron-- 
http://mail.python.org/mailman/listinfo/python-list

implementing callback function

2007-05-31 Thread Ron Provost
Within an application I'm working on.  The app is written in multiple layers 
such that lower layers provided services to higher layers.  Ideally in such an 
architecture, the high-level objects know about lower-level ones, but 
lower-level objects know nothing about the higher-level ones.  There's only one 
problem.  When this software was originally wirtten, one of the low-level 
objects was given knowledge of a higher-level object.  This creates a really 
ugly dependency that I want to eliminate.

My solution (at least what I'm trying to implement) is a classic one.  When a 
low-level routine needs info from a higher-level routine, let the higher-level 
routine provide a callback which the lower-level routine can call.  In this 
way, the lower-level routine knows nothing about higher-level routines.

However, Python is complaining about my implementation.  It raises an 
exception:  TypeError: unbound method fn_impl() must be called with X instance 
as first argument (got int instance instead)

For simplicity, I've narrowed it down to a bit of sample code.  class X is my 
low-level service.

class X( object ):
   fn = None

   @staticmethod
   def callX( n ):
  return X.fn( n )


Now, the following global stuff represents my higher-level routines:

def fn_impl( n ):   # my callback
   return n + 1

X.fn = fn_impl  # register my callback

Now I can do something which forces my callback (fn_impl) to get called

print X.callX( 3 )


I think I would get '4' printed but instead get the above error.  What am I 
doing wrong?

Thanks,
Ron-- 
http://mail.python.org/mailman/listinfo/python-list

Circular imports

2007-05-28 Thread Ron Provost
Hello,

I'm in the process of porting a project from Java to python.  The original 
project is very poorly organized.  Nearly each class is depentant upon nearly 
every other class.  Before I go playing around with the logic by moving things 
around and cleaning up the code, I want to get it working.  However, because of 
all these dependancies, python is not happy about my circular imports.  Is 
there any way to force python to accept these imports for now?  the only 
solution I've come up with myself would be to combine all the files into one.  
This isn't really possible anyway because three of the files are actually 
automatically generated.

Thanks,
Ron-- 
http://mail.python.org/mailman/listinfo/python-list

Is python2.5's Tix wrapper broken?

2007-02-13 Thread Ron Provost
I have  a piece of software I wrote some time ago using Python and the Tix 
wrapper.  I just upgraded to Python 2.5 and to my surprise my software no 
longer functions.  There's a problem with the Tix wrapper.  Under a clean 
install of Python the following should display an empty root window on the 
screen and happily.

 import Tix
 root = Tix.Tk()

Under Python2.5, the empty root window is displayed but I also get a 
Traceback:

Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python25\lib\lib-tk\Tix.py, line 210, in __init__
self.tk.eval('package require Tix')
_tkinter.TclError: can't find package Tix

Of course I can fix this with a cheap try block, but wonder if there's a 
better way.

   try:
  root = Tix.Tk()
   except:
  print Tk exception caught

Is Tix now broken or is there a new proper way to get a Tk root window?

Thanks,
Ron 


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


Tkinter or Python issue?

2005-10-18 Thread Ron Provost
Hello,

I'm using python 2.4.2 on Win XP Pro.  I'm trying to understand a behavior 
I'm seeing in some Tkinter code I have.  I've reduced my question to a small 
piece of code:


#BEGIN CODE
#
import Tkinter as Tk
import tkFont

sampleText = Here is a test string.  This is more text
Here is a second line of text.  How much
more can I type.  I can't think of anything else to type.


root = Tk.Tk( )
t = Tk.Text( root )
t.pack( )

t.insert( Tk.END, sampleText )

t.tag_config( 'AB', font=tkFont.Font( family='ariel', size=24, 
weight=tkFont.BOLD ) )
t.tag_config( 'TBU', font=tkFont.Font( family='times', size=10, 
weight=tkFont.BOLD, underline=1 ) )

t.tag_add( 'AB', '1.8', '1.15' )
t.tag_add( 'TBU', '2.10', '2.30' )

root.mainloop( )
#
###END CODE

Now when I run this I expect to see a small bit of the sampleText in ariel 
bold and another bit in times bold underline, instead I see both bits in the 
later style.  Interestingly, if I create the Font objects before calling 
t.tag_config() (i.e. replace the two t.tag_config( ) lines with the 
following):


f1 = font=tkFont.Font( family='ariel', size=24, weight=tkFont.BOLD )
f2 = font=tkFont.Font( family='times', size=10, weight=tkFont.BOLD, 
underline=1 )
t.tag_config( 'AB', font=f1 )
t.tag_config( 'TBU', font=f2 )


In rerunning the code, I see each bit of text now styled differently.  This 
is the behavior that I both expect and want.  Does anybody know why the two 
bits of code result in different behavior?  Is it a Python thing or a 
Tkinter thing?

Thanks for your feedback.

Ron 


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


Synchronous/Asynchrnous Audio play with pymedia

2005-09-18 Thread Ron Provost
Hello,

I'm developing a piece of software to assist illiteraate adults to learn to 
read.  I'm trying to figure out how, if possible, to make audio playback 
asynchrnous but still controllable.  I'm using python 2.4 with pymedia on 
XP.  I started out with the example in the tutorials section of the pymedia 
website.  The pymedia docs imply to me that playback using Output's play() 
method should already be asynchronous and controllable.  I judge this 
because of the presence of the pause() and unpause() methods.  However, when 
I run the example I find that play() in fact is not returning until an 
entire frame has been played through the sound card.  This isn't entirely a 
problem since the frames are small, but I would prefer to give the entire 
sound file to the class and let it go on playing while I continue with other 
processing.  If, at some point during playback, I wish to pause, unpause or 
completely stop playback, I would like, again, to be able to make 
asynchronous calls to do so.  Doe anybody know if this is possible?  Am I 
using pymedia incorrectly?

I've attempted to construct a threaded class to handle my problem, but I'm a 
novice with threads and It's not working properly.  To use this class, first 
make an instance.  To assign an mp3 file for playback use myInst.select( 
myFileObj ).  To begin playback or to unpause use:  myInst.play( ).  to 
pause use:  myInst.pause( ).  to stop use:  myInst.stop( ).  Once stopped, 
myInst.play( ) should restart playback from the beginning.  The problem is 
that when I stop(), restarting with play() doesn't work.  Instead, the 
thread silently terminates.

Thanks for any help you can offer.  I've been trying to solve this on my own 
for days now and just know it shouldn't be this hard.




import time
import pymedia.audio.sound as sound
import pymedia.audio.acodec as acodec
import threading, Queue

class AudioPlayer( threading.Thread ):
   # States
   PLAY  =1
   PAUSE =2
   STOP  =3

   def __init__( self ):
  threading.Thread.__init__( self )

  self.setDaemon( 1 )
  self.requestQueue  = Queue.Queue( )
  self.start( )

   def select( self, filelikeObj ):
  self.requestQueue.put( filelikeObj )

   def play( self ):
  self.requestQueue.put( AudioPlayer.PLAY )

   def pause( self ):
  self.requestQueue.put( AudioPlayer.PAUSE )

   def stop( self ):
  self.requestQueue.put( AudioPlayer.STOP )

   def run( self ):
  state = AudioPlayer.STOP
  file  = None
  snd   = None

  while True:
 if (state == AudioPlayer.PLAY) and self.requestQueue.empty( ):
if not snd:
   cparams= { 'id': acodec.getCodecID( 'mp3' ) }
   codec = acodec.Decoder( cparams )
   file.seek( 0 )
   bytes = file.read( 8192 )
   frame = codec.decode( bytes )
   snd = sound.Output( frame.sample_rate, frame.channels, 
sound.AFMT_S16_LE )
else:
   bytes = file.read( 512 )
   if len(bytes)  0:
  frame = codec.decode( bytes )

if frame:
   snd.play( frame.data )
else:
   if snd:
  snd.stop( )
   snd   = None
   state = AudioPlayer.STOP
 else:
msg = self.requestQueue.get( )

if msg in ( AudioPlayer.PAUSE, AudioPlayer.PLAY ):
   state = msg
else:
   if snd:
  snd.stop( )
   snd   = None
   state = AudioPlayer.STOP
   if msg != AudioPlayer.STOP:
  file = msg

# Test application
if __name__ == '__main__':
   import time
   player = AudioPlayer( )
   snd = open( 'music.mp3', 'rb' )
   player.select( snd )
   player.play( )
   time.sleep( 3 )

   player.pause( )
   time.sleep( 3 )
   player.play( )
   time.sleep( 10 )
   player.stop( )
   time.sleep( 3 )
   player.play( )
 


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


custom Tkinter ListBox selectMode

2005-07-01 Thread Ron Provost
Hello,

I've written a simple GUI which contains a listbox to hold some information. 
I've found that the click-selection schemes provided by Tkinter are 
insufficient for my needs.  Essentiall I need to impletement a custom 
selectMode.  As a first go, I've attempted to implement a click-on-click-off 
mode.  So for each entry, a click on that entry toggels its selection mode. 
A click on any entry does not affect the selection mode of any other entry.

I attempted to implement this by binding

myListBoxWidget.bind( 'ButtonRelease-1', self.itemClicked )

Where my itemClicked() method determines which item was clicked on then 
toggels it's selection state.




So, what's my problem?  Well, it doesn't work.  The SINGLE selectMode 
(default) seems to always take over.  I'm tempted to set a simple timer 
callback for a short duration which redoes the selection set after the 
built-in hander has had a chance to do its thing, but that seems like such a 
kludge to me.  Any suggestions on how I can implement a custom selectMode?

Thanks for your input.

Ron 


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