Setting the time in Win7

2011-08-22 Thread Bob Greschke

Permissions!

We're running in an account as an administrator (the only account on 
the laptops) and the program just calls system(time ) and 
system(date ) after reading it from a connected GPS receiver.  I've 
fiddled with everything I could find in the registry and with the 
secpol.msc program and there doesn't seem to be any reason that it 
can't set the time, but it can't.  Any ideas?


Thanks!

Bob

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


Re: Setting the time in Win7

2011-08-22 Thread Bob Greschke

Hi!

Yup.  I've been from one end of that article to the other with no luck. 
It must be something to do with the shell that the system() call 
creates not having permission to set the time, but I can't figure out 
how to get around it.  Just using the GUI the account where the user is 
running the program from has permission to set the time.


On 2011-08-22 11:41:45 -0600, Tim Golden  said:


If memory serves, you need to enable a specific privilege to
set the time in Vista+. Just a moment...

Have a look here:

   http://support.microsoft.com/kb/300022

and look for SeSystemtimePrivilege generally. Sorry; I'm
a bit rushed at the moment. Feel free to post back if
that isn't clear

TJG

On 22/08/2011 17:35, Bob Greschke wrote:

Permissions!

We're running in an account as an administrator (the only account on the
laptops) and the program just calls system(time ) and system(date
) after reading it from a connected GPS receiver. I've fiddled with
everything I could find in the registry and with the secpol.msc program
and there doesn't seem to be any reason that it can't set the time, but
it can't. Any ideas?

Thanks!

Bob



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


Re: Setting the time in Win7

2011-08-22 Thread Bob Greschke
Several people have been hacking away on this computer we are testing 
on, so I'm not sure what settings -- other than all of them -- have 
been messed with, but popen("time ...") seems to work, but system("time 
...") does not.  I'm going to restore the machine to its original state 
and see what happens.


Bob

On 2011-08-22 11:41:45 -0600, Tim Golden  said:


If memory serves, you need to enable a specific privilege to
set the time in Vista+. Just a moment...

Have a look here:

   http://support.microsoft.com/kb/300022

and look for SeSystemtimePrivilege generally. Sorry; I'm
a bit rushed at the moment. Feel free to post back if
that isn't clear

TJG

On 22/08/2011 17:35, Bob Greschke wrote:

Permissions!

We're running in an account as an administrator (the only account on the
laptops) and the program just calls system(time ) and system(date
) after reading it from a connected GPS receiver. I've fiddled with
everything I could find in the registry and with the secpol.msc program
and there doesn't seem to be any reason that it can't set the time, but
it can't. Any ideas?

Thanks!

Bob



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


Re: Setting the time in Win7

2011-08-23 Thread Bob Greschke

On 2011-08-23 02:26:38 -0600, Tim Golden  said:


On 22/08/2011 20:42, Bob Greschke wrote:

Several people have been hacking away on this computer we are testing
on, so I'm not sure what settings -- other than all of them -- have been
messed with, but popen("time ...") seems to work, but system("time ...")
does not. I'm going to restore the machine to its original state and see
what happens.


Hoping that this helps: you can programatically set the system time
from within Python by using the pywin32 modules, or ctypes if you
prefer. The code below works for an already-elevated command prompt
by enabling the SystemTime privilege and (crudely) moving the time
forward by five minutes by way of showing what's happening before
resetting it back.

I've commented out the actual SetSystemTime calls just in case anyone
cuts-and-pastes indjudiciously. Ideally you should disable the
privilege afterwards but I've left that out so as not to clutter
the example.


import os, sys

import win32api
import win32security
import ntsecuritycon

hToken = win32security.OpenProcessToken (
   win32api.GetCurrentProcess (),
   ntsecuritycon.MAXIMUM_ALLOWED
)
time_privilege = win32security.LookupPrivilegeValue (None, 
win32security.SE_SYSTEMTIME_NAME)

win32security.AdjustTokenPrivileges (
   hToken, 0,
   [(time_privilege, win32security.SE_PRIVILEGE_ENABLED)]
)

current_time = win32api.GetSystemTime ()
print "Current time:", current_time
new_time = list (current_time)
new_time[5] += 5
## print win32api.SetSystemTime (*new_time)
print "Current time:", win32api.GetSystemTime ()
## print win32api.SetSystemTime (*current_time)
print "Current time:", win32api.GetSystemTime ()



TJG


Oooo.  Now I can be dangerous.  We kinda also solved the whole thing 
for us (just a few minutes ago) by checking the checkbutton "Run as 
administrator" in the Properties, Compatibility tab, for python.exe and 
pythonw.exe.  The account is an Administrator, so it's OK for this.


I thought there must be a way through pywin32, but I don't know much of 
anything about Windows API calls.  I have a Windows Programming book 
collecting dust somewhere...


Thanks!

Bob

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


Text() tags and delete()

2005-06-27 Thread Bob Greschke
Does Text.delete(0.0, END) delete all of the tags too?  Everything says it 
does not delete marks, but nothing about tags.

Thanks!

Bob


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


Re: Text() tags and delete()

2005-06-28 Thread Bob Greschke
"Christopher Subich" <[EMAIL PROTECTED]> wrote in 
message news:[EMAIL PROTECTED]
> Bob Greschke wrote:
>> Does Text.delete(0.0, END) delete all of the tags too?  Everything says 
>> it does not delete marks, but nothing about tags.
>
> Note to everyone else: this is a TKinter question.

Oops.  I meant to put that in the subject.

> Tags are attached to text ranges, in the Text widget.  If you delete all 
> of the text in the widget, all of the text ranges will go poof, so 
> therefore all of the tag attachments will likewise go poof.

That's what I thought, and that was what it looked like was happening (but 
just because you can't find something doesn't mean it hasn't been taken to 
the garbage :)

> This will not delete any tags that have been defined for the widget, 
> though, although why you'd want to do that is an open question.

We have all kinds. :)

Thanks, Christopher!


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


pySerial Windows write problem

2005-07-28 Thread Bob Greschke
We have some equipment that communicates at 57600 baud RS232.  The path from 
the PC is USB to a Phillips USB hub, then off of that a TUSB3410 USB/Serial 
converter.  The driver for the 3410 chip creates a "normal" comm port (like 
COM3).  There is a C++ program that has no problem talking to the equipment, 
but two Python programs have trouble.  One is a big, scary, controller 
program, and the other, since that is the one I'm having trouble with, is a 
while() loop.

The while loop program seems to be able to open and close the serial port 
all day.  It also seems to be able to open, send "blahblahblah", and close 
the port for the same length of time.  But writing anything to the port 
quickly (not always right away...like maybe 5-6 iterations through the 
loop?) causes the

win32file.CloseHandle(self.hComPort)

statement in the 'def close(self)' function of the serialwin32.py file of 
the pySerial package to hang for a few seconds, then return.  The next 
open() attempt fails with the 'could not open port: (995, 'CreateFile', 'The 
I/O operation has been aborted because of either a thread exit or an 
application request.') exception.

The failure mode with the large program is it opens the port successfully 
completes a bunch of back and forth talking, then hangs for a few seconds 
when the port is closed, and then can't reopen the port.  It never seems to 
fail in the middle of a bunch of reads and writes, but only when/after the 
port is closed.  It can also run for the better part of an hour with no 
problems then all of a sudden...  Like I said, the C++ program never fails.

I've looked at the settings in the C++ program, and in the serialwin32.py 
file and tried to set them the same as best I can, but no luck.  Digging 
into the win32all stuff gets me lost quite quickly.  I see all of the 
settings, but have no idea what to try.  This is all on WinXP, Python 2.4.1, 
the latest pySerial and win32all.

Does this ring any bells with anyone?

Thanks!

Bob


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


Re: pySerial Windows write problem

2005-07-28 Thread Bob Greschke
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Bob Greschke wrote:
> > But writing anything to the port
>> quickly (not always right away...like maybe 5-6 iterations through the 
>> loop?) causes the
>>
>> win32file.CloseHandle(self.hComPort)
>>
>> statement in the 'def close(self)' function of the serialwin32.py file of 
>> the pySerial package to hang for a few seconds, then return.
>
> Are you certain it is this line that is blocking, and not the preceding 
> line which is a call to SetCommTimeouts()?  How did you prove which line 
> it is?  (I don't have an answer to the problem, just wanted to be sure of 
> the information...)
>
> -Peter

Hi!

I had the SetCommTimeouts line commented out.  I just have a couple of 
prints before and after the CloseHandle line.

I didn't write the C++ program, but it looks like it never closes the serial 
port.  It opens it when it starts up, then keeps it open until it quits. 
Tsk tsk tsk.  Sloppy.  Maybe they did that to cover up this problem. :)

Bob


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


Re: pySerial Windows write problem

2005-07-28 Thread Bob Greschke
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message >
> Actually, I'm curious why you don't do the same.  I'd call it very unusual 
> (in my experience) to have a program open and close a serial port 
> repeatedly.  Among other things, this means that the DSR/DTR lines are 
> toggling high and low repeatedly, and that alone could cause undesirable 
> behaviour in certain devices.

I guess I could.  It's just that not releasing the port/not KNOWING that the 
port has been closed at predictible times is our chief complaint about the 
C++ program.   As an aside, when I left work I left a version of the 
while-loop program running, opening the port, writing to the equipment, 
getting a response, and closing the port.  It was up to about 180 sucessful 
cycles (in a row -- it will stop if it fails).  I think it's a hardware 
problem. :)


> In none of my own serial-based programs (perhaps a few dozen such to date) 
> have I ever opened and closed a port other than at startup and shutdown 
> (just as your C++ program does).  Unless you've got a good reason to do 
> otherwise, if this solves your problem it's certainly the most direct 
> approach to do so.

One of the serial ports (there are actually two) is used to read some NMEA 
sentences from a GPS.  It is only rarely read.  If it is also opened when 
the program starts and kept open would you just dump the buffer and then 
read to get the most current info?  What happens when the buffer fills up? 
The "main" port is just commands sent, responses received kind of traffic.

I'd write a C extension to do the serial stuff, but I don't know a thing 
about Windows programming.

Thanks!


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


Tkinter, Menu(bar) font size

2005-08-01 Thread Bob Greschke
Option adding "Menu*font" changes the font size of the _commands, 
_radiobuttons, etc., but not the "File", "Edit", etc. labels on the menubar 
itself.  What is the name for those labels?  If I go

   Top.add_cascade(Label = "File", menu = Fi, font = "Courier 20")

they change, but I can't figure out the name for the option_add.

I'm not really trying to use Courier 20. :)

Thanks!

Bob


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


Re: Tkinter, Menu(bar) font size

2005-08-02 Thread Bob Greschke
Yeah.  It works on a Sun and Linux, but not Windows.  That stinks.  We got a 
bunch of 1400x1050 display laptops in and now I have to run around changing 
a bunch of programs that looked fine on 1024x768 displays.

Thanks!

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

Tk tries to use the "native" menu control on Windows (and, I think, MacOS).
One result seems to be that for the application's menu bar you can't change 
the
font.

Of course, Windows provides a way for users to select a uniform font for
menu bars in all applications, in the Display control panel.

Jeff


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


Setting a drive's volume label

2005-08-02 Thread Bob Greschke
...the name for a drive (hard or removable) that shows up when, for example, 
a USB flash drive is recognized by the system.  I don't know if this shows 
up somewhere in Linux.

Can this be set from Python?  I guess it would be some MFC call in Windows 
(I don't know anything about doing that), and some ??? call in Linux?  Could 
use both.

Thanks!

Bob


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


Re: Setting a drive's volume label

2005-08-02 Thread Bob Greschke
Looks like the "label" system command will do it in Windows.  That's good 
enough for this exercise.  So, in Linux...???


"Bob Greschke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> ...the name for a drive (hard or removable) that shows up when, for 
> example, a USB flash drive is recognized by the system.  I don't know if 
> this shows up somewhere in Linux.
>
> Can this be set from Python?  I guess it would be some MFC call in Windows 
> (I don't know anything about doing that), and some ??? call in Linux? 
> Could use both.
>
> Thanks!
>
> Bob
>
> 


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


Re: Setting a drive's volume label

2005-08-04 Thread Bob Greschke
"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in 
message news:[EMAIL PROTECTED]
> Bob Greschke wrote:
>> Looks like the "label" system command will do it in Windows.  That's good
>> enough for this exercise.  So, in Linux...???
>
> "mlabel" in the "mtools" package will do what you need. "mkfs.vfat" can 
> also
> be given a volume label, but it will not allow you to set the label 
> without
> creating a new filesystem :)
>
> Reinhold

Perfect!  (Never heard of them :)  Thanks!

Bob


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


Tkinter add_cascade option_add

2005-09-13 Thread Bob Greschke
Root.option_add("*?*font", "Helvetica 12 bold")

Want to get rid of the "font =":
Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold")

Does anyone know what ? should be to control the font of the cascade 
menus (the labels on the menu bar)?  "*Menu*font" handles the part that 
drops down, but I can't come up with the menu bar labels part.

Thanks!

Bob


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


Re: Tkinter add_cascade option_add

2005-09-14 Thread Bob Greschke
You can set the font for the labels on the menu bar, and you can set the 
font of the items in the drop down portion independently (except on Windows 
where you cannot control the font of the menu bar labels).  I just don't 
know how to set the font for the menu bar labels using an option_add 
command.

...option_add("*Menu*font", "Helvetica 12 bold")  works fine
...option_add("*Cascade*font", "Helvetica 12 bold")  does not,

because I can't figure out what to put in for "Cascade".  There must be 
something, because I can use font = "Helvetica 12 bold" in the add_cascade 
command OK (see below).

The program runs on Windows, Linux, Solaris, Mac.

Bob

"Eric Brunel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Tue, 13 Sep 2005 22:31:31 -0600, Bob Greschke <[EMAIL PROTECTED]> wrote:
>
>> Root.option_add("*?*font", "Helvetica 12 bold")
>>
>> Want to get rid of the "font =":
>> Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold")
>>
>> Does anyone know what ? should be to control the font of the cascade
>> menus (the labels on the menu bar)?  "*Menu*font" handles the part that
>> drops down, but I can't come up with the menu bar labels part.
>
> option_add('*Menu.font', 'helvetica 12 bold') works for me for all sorts 
> of menu items (cascade, commands, checkbuttons, whatever...).
>
> What is your platform? There may be a few limitations for menu fonts on 
> Windows.
>
> HTH
> -- 
> python -c "print ''.join([chr(154 - ord(c)) for c in 
> 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])" 


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


Re: Tkinter add_cascade option_add

2005-09-15 Thread Bob Greschke
nt = CascadeFont)
Op = Menu(Top, tearoff = 0)
Op.add_radiobutton(label = "Set Time From GPS", variable = SetTimeRVar, 
\
value = "gps", command = Command(subCont, "Rgps,pc", "time", \
SetTimeRVar))
Op.add_radiobutton(label = "Set Time From PC", variable = SetTimeRVar, \
value = "pc", command = Command(subCont, "Rgps,pc", "time", \
SetTimeRVar))
Op.add_separator()
Op.add_radiobutton(label = "Memory Units In KBs", \
variable = MemUnitsRVar, value = "k")
Op.add_radiobutton(label = "Memory Units In Blocks", \
variable = MemUnitsRVar, value = "blocks")
Op.add_separator()
Op.add_checkbutton(label = "Wait For USB Drive Responses", \
variable = DriveRpCVar, command = Command(subCont, "C1,0", 
"drv", \
DriveRpCVar))
Op.add_separator()
Op.add_checkbutton(label = "Record Commands To Log", variable = LogCVar, 
\
command = cmdLog)
Op.add_separator()
Op.add_checkbutton(label = "Debug Mode", variable = DebugCVar, \
command = cmdDebug)
Top.add_cascade(label = "Options", menu = Op, font = CascadeFont)
Help = Menu(Top, tearoff = 0)
Help.add_command(label = "Reset Commands", command = resetButtons)
Help.add_command(label = "Current Working Directory", command = cmdCWD)
Help.add_command(label = "Serial Port Scan", command = cmdPortScan)
# TESTING
#Help.add_command(label = "Test", command = cmdTest)
Help.add_separator()
Help.add_command(label = "Help", command = showHelp)
Help.add_command(label = "About", command = about)
Top.add_cascade(label = "Help", menu = Help, font = CascadeFont)
return
# END: makeMenu

Do you see the CascadeFont variable?  I want to get rid of that and turn 
setting the font of the .add_cascade items into an option_add function. 
Does anyone know how to do that?  What key word and tricky phrase does the 
option_add function need?

Bob


"Bob Greschke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Root.option_add("*?*font", "Helvetica 12 bold")
>
> Want to get rid of the "font =":
> Widget.add_cascade(label = "File", menu = Fi, font = "Helvetica 12 bold")
>
> Does anyone know what ? should be to control the font of the cascade 
> menus (the labels on the menu bar)?  "*Menu*font" handles the part that 
> drops down, but I can't come up with the menu bar labels part.
>
> Thanks!
>
> Bob
>
> 


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


Tkinter option_add for menu radiobutton

2005-02-13 Thread Bob Greschke
Root.option_add("*Menu.Font", "Veranda 9")

as an example, works fine in my program.

Root.option_add("*Radiobutton*selectColor", "black")

also works fine for regular radiobuttons.  What I can't
do is get the selectColor of the radiobutton's in the
menu to be black...the x.add_radiobutton() ones.

Root.option_add("*Menu.Radiobutton*selectColor", "black")...nope
Root.option_add("*Menu*selectColor", "black")...no change
Others...no luck yet.

What would the correct command be?  I can do a selectcolor = "black"
in the declaration of each button, but...

Thanks!

Bob


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


Re: Tkinter option_add for menu radiobutton

2005-02-14 Thread Bob Greschke
"Eric Brunel" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sun, 13 Feb 2005 15:31:18 -0700, Bob Greschke <[EMAIL PROTECTED]> 
> wrote:
> [snip]
>> Root.option_add("*Radiobutton*selectColor", "black")
>>
>> also works fine for regular radiobuttons.  What I can't
>> do is get the selectColor of the radiobutton's in the
>> menu to be black...the x.add_radiobutton() ones.
>>
>> Root.option_add("*Menu.Radiobutton*selectColor", "black")...nope
>> Root.option_add("*Menu*selectColor", "black")...no change
>
> Strange... The last one works for me (as it should - see 
> http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm). What platform are you on and 
> what is your tcl/tk version?
>  - Eric Brunel -

Doh!  You're right.  Now it is here too.  I must have been typing something 
wrong...again.  This was Python2.3 and whatever version of tcl/tk that comes 
with it on Linux.

Thanks! 


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


StringVar() IntVar() vs. Dictionary of same

2006-01-16 Thread Bob Greschke
Let's say I have a program with roughly 1 bazillion StringVars and IntVars 
(a lot of tkinter forms).  Can anyone guess what the performance hit may or 
may not be by going from "global" StringVars and IntVars and accessing them 
directly (like barcode = StringVar()) to putting all of the StringVars and 
IntVars into a dictionary (like Vars = {"barcode":StringVar()...}) and 
accessing them that way?  Just roughly what do you think the effect would 
be?

Thanks!

Bob


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


Re: StringVar() IntVar() vs. Dictionary of same

2006-01-17 Thread Bob Greschke
"Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Bob Greschke" <[EMAIL PROTECTED]> writes:
>> Just roughly what do you think the effect would be?
>
> Either extremely slight or else nonexistent.

I kinda thought so.  Thanks!

Bob


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


Tkinter StringVar mystery

2006-07-17 Thread Bob Greschke
First off I have this class (thanks to whoever came up with this way back 
when):

##
# BEGIN: class Command
# LIB:Command():2006.110
#Pass arguments to functions from button presses and menu selections,
#bind's.  Nice!
#In your declaration:
#...command = Command(func, args,...)
class Command:
def __init__(self, func, *args, **kw):
self.func = func
self.args = args
self.kw = kw
def __call__(self, *args, **kw):
args = self.args+args
kw.update(self.kw)
apply(self.func, args, kw)
# END: class Command


Then in the setup part of an entry form I have:

# CHBCBarcodeLastVar is the variable for an Entry() field
Button(SubFrame, text = "Print Barcode", \
command = Command(test, "other", CHBCBarcodeLastVar.get(), \
"CHBC")).pack(side = LEFT)


Then this is a/the test function:

def test(What, BC, Where, e = None):
# Does print the correct value
print CHBCBarcodeLastVar.get()
# Does change the field on the form
CHBCBarcodeLastVar.set("5")
# BC is ""
print ":"+What+":", ":"+BC+":", ":"+Where+":"
return

Everything works as it should, except when the Button is clicked BC is an 
empty str in test().  How come?  (I really have NO clue how that Command 
class works, but I use it like crazy.  Is it the problem?)

Thanks!

Bob


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


Re: Coding style

2006-07-17 Thread Bob Greschke

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> PTY wrote:
>> Which is better?
>>
>> lst = [1,2,3,4,5]
>>
>> while lst:
>>   lst.pop()
>>
>> OR
>>
>> while len(lst) > 0:
>>   lst.pop()
>
> A dozen posts, but nobody has posted the right
> answer yet, so I will :-)
>
> It doesn't matter -- use whichever you prefer (*)
> This is an angels on the head of a pin issue.
>
> (*) -- If your code is part of an existing body of
> code that uses one or the other style consistently,
> then you should do the same.
>

I'd go even one step further.  Turn it into English (or your favorite 
non-computer language):

1. While list, pop.

2. While the length of the list is greater than 0, pop.

Which one makes more sense?  Guess which one I like.  CPU cycles be damned. 
:)

Bob


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


tkinter: Button color Solaris/Linux

2006-08-14 Thread Bob Greschke
I have a GUI where the background of the "GO" button, for example, turns 
green while the associated action is running.  On Windows it works fine, but 
on Solaris and Linux the button background turns white (or whatever) when 
the mouse pointer enters the button, the background stays that color while 
Button-1 is being held down, and the background continues to stay that color 
when Button-1 is released.  The background only turns green when the user 
moves the pointer off of the button.  Can that be fixed, or is that an 
X-Windows thing?

Thanks!

Bob


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


Re: tkinter: Button color Solaris/Linux

2006-08-14 Thread Bob Greschke
"Bob Greschke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I have a GUI where the background of the "GO" button, for example, turns 
>green while the associated action is running.  On Windows it works fine, 
>but on Solaris and Linux the button background turns white (or whatever) 
>when the mouse pointer enters the button, the background stays that color 
>while Button-1 is being held down, and the background continues to stay 
>that color when Button-1 is released.  The background only turns green when 
>the user moves the pointer off of the button.  Can that be fixed, or is 
>that an X-Windows thing?
>
> Thanks!
>
> Bob


activebackground.  At least this time it was a couple of minutes after the 
Return key was pressed. :)

Bob


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


Overriding traceback print_exc()?

2006-10-31 Thread Bob Greschke
I want to cause any traceback output from my applications to show up in one 
of my dialog boxes, instead of in the command or terminal window (between 
running on Solaris, Linux, OSX and Windows systems there might not be any 
command window or terminal window to show the traceback messages in).  Do I 
want to do something like override the print_exc (or format_exc?) method of 
traceback to get the text of the message and call my dialog box routine?  If 
that is right how do I do that (monkeying with classes is all still a grey 
area to me)?

I kind of understand using the traceback module to alter the output of 
exceptions that I am looking for, but I'm after those pesky ones that should 
never happen. :)

Thanks!

Bob


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


Extracting 3-byte integers

2006-06-26 Thread Bob Greschke
I have some binary data read from a file that is arranged like

   <3-byte int> <3-byte int> <3-byte int> etc.

The "ints" are big-endian and there are 169 of them.  Is there any clever 
way to convert these to regular Python ints other than (struct) unpack'ing 
them one at a time and doing the math?

Thanks!

Bob


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


Re: Extracting 3-byte integers

2006-06-27 Thread Bob Greschke
>I have some binary data read from a file that is arranged like
>
>   <3-byte int> <3-byte int> <3-byte int> etc.
>
> The "ints" are big-endian and there are 169 of them.  Is there any clever 
> way to convert these to regular Python ints other than (struct) unpack'ing 
> them one at a time and doing the math?

Thanks guys!  I was looking for a 'one liner' of some kind, but I guess 
there isn't one (too bad you can't tell array or struct.unpack how many 
bytes you want an integer to be).  Yeah, these are signed ints so I'll have 
to convert them.

To me balancing my checkbook involves higher "math". :)

Bob


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



Subclassing Tkinter Buttons

2006-08-31 Thread Bob Greschke
I don't use classes much (mainly because I'm stupid), but I'd like to make a 
subclass of the regular Tkinter Button widget that simply adds spaces to the 
passed "text=" when the program is running on Windows (Linux, Solaris, Mac 
add a little space between the button text and the right and left edges of a 
button, Windows does not and it looks bad/can be hard to read).  Below is 
some pseudo code.  What should the guts of the BButton class be?  I can't 
work out how all of the arguments that would be passed to a regular Button 
call get handled.  *args and **kw confuse me and I can't seem to find simple 
enough examples in my mountain of books.

Thanks!

Bob


System = platform[:3].lower()
.
.
class BButton(Button):
if System == "win":
Make a button with " " before and after text
else:
Make a button using the passed text as is
.
.
BButton(Sub, text = "Hello", bg = "blue", fg = "yellow").pack(side = TOP)
BButton(Sub, bg = "yellow", bg = "blue", text = "World").pack(side = TOP)


On "lin", "sun", "dar":
[Hello]
[World]

On "win":
[ Hello ]
[ World ]


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


Tkinter window focusing or selecting

2006-09-04 Thread Bob Greschke
I have a program with many "forms" (Toplevel windows with entry fields). 
Sometimes when I .deiconify() and .lift() a form that is a child of another 
form, but that just got buried under other forms it comes up 'not active' 
(dimmed).  I have to click on the title bar (or anywhere in the window) 
before I can start entering stuff into the entry fields.  It doesn't seem to 
happen all of the time, which I don't understand.  Doing a .focus_set() 
after the .lift() fixes it, but then Tkinter loses track of which entry 
field the cursor was in when the window got covered up.  Is there something 
else I should be calling after the .deiconify() and .lift() to make sure the 
window get 'activated' (or what ever that state is)?  This is on Linux at 
this point.

Thanks!

Bob


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


Two ethernet cards/networks (still)

2006-09-07 Thread Bob Greschke
There is a lot to stuff that seems to skirt around this issue (most of which 
has to do with finding your IP address), but I can't find anything that 
explains how to write a client that (in my case) needs to collect some 
information from some equipment on a private network/Ethernet card, then 
transmit that info on the other Ethernet card/"outside" network to another 
program (which will put it into a db).

"binding to a specific address is almost never used for a client", sez 
Foundations of Python Network Programming, but is that how it's done??  Each 
card has a fixed IP address.  It's on Windows at this time if that makes any 
difference.

Thanks!

Bob


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


Re: Two ethernet cards/networks (still)

2006-09-10 Thread Bob Greschke

"Steve Holden" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Bob Greschke wrote:
> The reason that "binding to a specific address is almost never used for a 
> client" is because it's the server destination address that the network 
> layer will use to determine which interface is used to communicate with a 
> specific server host.
>
> Suppose your network setup looks like this:
>
>
> +---++ Network A
> |
> |
> |
> | 192.168.12.34/24
> |
>+++
>| |
>| |
>| YOUR HOST   |
>| |
>| |
>+++
> |
> | 201.46.34.22/24
> |
> |
> |
> +---+--+-+ Network B
>|
>+
>   +++
>   |  router |
>   |   to internet   |
>   +-+
>
> If your client program tries to communicate with, say, 192.168.12.18 then 
> by the IP network layer will automatically select network A as the medium, 
> since the destination is local to that network. If you then want to 
> communicate the results to 201.46.34.118 then network B will be used, 
> again because the destination is local to that network (its first 24 bits 
> are the same as the first 24 bits of the destination).
>
> In this case the router on network B will almost certainly be the default 
> route for the host, as it's the way to everywhere else.
>
> This isn't really Python-related, so I hope it answers your question!
>
> regards
>  Steve
> -- 
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenweb   http://holdenweb.blogspot.com
> Recent Ramblings http://del.icio.us/steve.holden
>

Nice explanation!  Thanks!  You mean I don't have to do anything special?? 
That sounds suspiciously easy. :)

To muddy the water a little the equipment I want to get info from (some 
seismic digitizing/recording equipment) comes back to us from the field with 
the IP addresses set to whatever that last user needed.  What we do now is 
put the unit(s) on the bench, connect them to the private network and use a 
broadcast address (like 255.255.255.255) and a specific port number to query 
and see who is connected.  Then we (a program) can get in (login, basically) 
and reset the all of the IPs to the same subnet to proceed with checkout, 
calibration, etc.  We have to disconnect from (or disable the card for) the 
outside network when we do this discovery or else the program discovers all 
of these instruments that we have running in the building (monitoring a 
seismic pier, in people's offices, etc.).  I'm guessing here we will still 
need to do this?  It's not a biggie, but finding a way to not have to do 
this was what started this whole thing.  Once the program knows which 
instruments it found on the private network it doesn't matter.  It will only 
work on those ones.

Thanks!

Bob


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


Re: Python on handhelds

2006-09-11 Thread Bob Greschke

"Luke Dunstan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> "Paul Rubin"  wrote in message 
> news:[EMAIL PROTECTED]
>> "Nick" <[EMAIL PROTECTED]> writes:
>>> I have never programmed in Python a day in my life. My group is working
>>> on developing an application on the Dell Axim hand held that has a
>>> tight deadline. I have heard that Python is particularly advantageous
>>> in rapid prototyping and deployment. I would like to lean this way if I
>>> can. Does anyone know if I can run Python on the Dell Axim handheld. It
>>> runs Windows CE. If so, what all is needed to make this possible.
>>
>> Someone did a WinCE port a while back, but I don't think it's actively
>> used much.  The approach might be reasonable if you're an expert with
>> some time on your hands, but for a newcomer with an onrushing
>> deadline, you may be better off using whatever you're already using
>> (VB or whatever), and keeping Python in mind for some future project.
>
> I agree that it is much less active than Python on other platforms, and in 
> some areas it lags behind the PC, e.g. in GUI toolkits. However, if you 
> want to try it go here:
>
> http://sourceforge.net/projects/pythonce
>
> See also the mailing list:
>
> http://mail.python.org/mailman/listinfo/pythonce
>
>
> Luke Dunstan
>

NSBasic (which has a CE version) is pretty nice for PalmOS.  Making 
applications is pretty straightforward if you don't need to access serial 
ports and stuff like that.  Nice IDE too.

Bob


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


Tkinter Text widget incremental search

2006-09-28 Thread Bob Greschke
I want to create a search function on a Text() widget full of text like the 
incremental search in emacs -- if you type an "f" emacs goes to the first 
"f", type another "f" and it goes to the first place where "ff" shows up in 
the text, etc.

How would you search the text of the Text() for a string like "ff" and get 
back the proper index position (line.char) AND have that take into account 
word wrapping?  Text().get(0.0, END).split("\n") returns a bunch of lines, 
but one line in the List may be many text widget/screen lines.

Thanks!

Bob


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


Need old pywin32/win32all for Win95

2007-01-02 Thread Bob Greschke
Does anyone have an old version of this?  I've got some old OEM stuff that 
will only handle Win95 because of some custom hardware drivers.  The build 
200 on sourceforge of pywin32 isn't old enough.  I'm trying to get pyserial 
up and running.  Python/Tkinter does OK at 233MHz! :)

Thanks!

Bob


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


Getting Tkinter Text contents before destruction

2006-02-06 Thread Bob Greschke
Hi!

I want to grab the contents of a Text widget when the frame it's on gets 
destroyed.  I tried TextWidget.bind(""... , but the widget is gone 
before the call gets made, and I'd really hate to do something with the 
function that gets called with TextWidgetsFrame.bind("", ..., since 
that one function handles all of the frames in the program...or would that 
even work?

How can I do this?

Thanks!

Bob


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


Re: Tkinter, X-windows and ebay

2006-02-10 Thread Bob Greschke

"Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Bob Greschke" <[EMAIL PROTECTED]> writes:
>> What I came up with was the user can just create a text file (a kind
>> of a transaction log of what things were done to the copy of the
>> database on his machine), then cut and paste that text into a window
>> created on their machine by the main database program (using
>> X-windows, ssh, etc.), then the main program can read the contents
>> of that text field and update the main copy of the database.
>>
>> It should work. :)
>
> Yuck!  Why not use an http interface instead of the remote tkinter
> interface?  Then the user would interact with your app through a web
> browser, giving a familiar UI as well as giving that upload button
> (which tells the browser to upload the file).

Mainly because the user may be in the middle of the Himalayas trying to 
create paperwork for equipment being shipped to Japan and Chile.  The 
Internet is not always an option in our line of work.  We need to have 
standalone everythings.  We don't live in your real world. :)

The two databases (the one on the user's laptop, and the one back at the 
office) don't need to be reconciled until the user gets back.  We just need 
to (eventually) know which pieces of equipment were sent to Japan, and which 
went to Chile.

Bob


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


A C-like if statement

2006-02-23 Thread Bob Greschke
I miss being able to do something like this in Python

1f (I = a.find("3")) != -1:
print "It's here: ", I
else:
print "No 3's here"

where I gets assigned the index returned by find() AND the if statement gets 
to do its job in the same line.  Then you don't have to have another like 
that specifically gets the index of the "3".  Is there a way to do this in 
Python?

Thanks!

Bob


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


Re: A C-like if statement

2006-02-23 Thread Bob Greschke

"Roy Smith" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Bob Greschke <[EMAIL PROTECTED]> wrote:
>>I miss being able to do something like this in Python
>>
>>1f (I = a.find("3")) != -1:
>>print "It's here: ", I
>>else:
>>print "No 3's here"
>>
>>where I gets assigned the index returned by find() AND the if statement 
>>gets
>>to do its job in the same line.  Then you don't have to have another like
>>that specifically gets the index of the "3".  Is there a way to do this in
>>Python?
>
> It is a deliberate and fundamental design decision in Python that
> assignment is a statement, not an expression with side effects.  This
> means you often need an "extra" line compared to a classic C "assign
> and test" idiom such as you have above.  I, like you, often miss the
> compactness of the C idiom, but there it is.
>
> It's also unpythonic to return magic values to indicate failure.
> Throwing an exception would be the more normal way of doing it.  So,
> I'd expect the above to translate into something like:
>
> try:
>i = a.find("3")
>print "It's here: ", i
> except NotFound:
>print "No 3's here"

Nuts.  I guess you're right.  It wouldn't be proper.  Things are added or 
proposed every day for Python that I can't even pronounce, but a simple 'if 
(I = a.find("3")) != -1' isn't allowed.  Huh.  It might be time to go back 
to BASIC. :)

I think your way would work if .find() were replaced with .index().  I'm 
just trying to clean up an if/elif tree a bit, so using try would make 
things bigger.

Thanks!

Bob


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


Tkinter Return/Enter key handling

2005-05-18 Thread Bob Greschke
I have a Tkinter Text() widget in a program that the user can type stuff 
into.  Most of our keyboards have the regular keys with a "Return" key, and 
a numeric keypad with an "Enter" key.  The Return key generates events with 
"" for the keysym, and the Enter key generates events with 
"" as the keysym.  The Text() widget does a carriage 
return/linefeed when the Return key is pressed, but does nothing when the 
Enter key is pressed.  So I did a

Text.bind("http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Return/Enter key handling

2005-05-18 Thread Bob Greschke
Sorry. Yeah, Linux.  Eww. Ick.  Don't want to mess with .Xdefaults.  It 
works, so I guess I'll just keep the .bind.  Thanks, Phil!

"phil" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> If you are talking Linux there's .Xdefaults
> Which I had to resort to for tn5250.
> For Tkinter apps its a LOT easier to just use bind.
>
> Win32? dunno.


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


tkinter, option_add, entry field trouble

2005-06-05 Thread Bob Greschke
I can't get

Root.option_add("*Entry*highlightthickness", "2")
Root.option_add("*Entry*highlightcolor", "green")

to work.  Anyone know why?  Setting the font, background color, etc.
this way works OK.

Are there some options that can't be set "globally"?  Setting these two
options in the Entry() statements themselves works OK.  I've just got
about 200 Entry statements that I was hoping to not have to edit. :)

This is on Linux FC1, Python 2.3.

Thanks!

Bob


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


Re: tkinter, option_add, entry field trouble

2005-06-05 Thread Bob Greschke
Yahoo!  That was it.  When is Grayson coming out with a new version of 
"Python and Tkinter Programming"?  Mine is getting pretty full of pen & ink 
changes. :)

Nice tip, too!

Thanks!

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

I think you have to spell it
 Root.option_add("*Entry*highlightThickness", "2")
 Root.option_add("*Entry*highlightColor", "green")

When you're not sure of the capitalization, do something like this
interactively:
 >>> e.configure('highlightcolor')
 ('highlightcolor', 'highlightColor', 'HighlightColor',
  'SystemWindowFrame', 'green')
When you use 'configure' this way, the *second* string has the correct
capitalization for use in option_add.  The fourth is the system default 
before
taking into account the option database, and the last is the current value.

Jeff


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


Want to build a binary header block

2007-04-30 Thread Bob Greschke
This is the idea

   Block = pack("240s", "")
   Block[0:4] = pack(">H", W)
   Block[4:8] = pack(">H", X)
   Block[8:12] = pack(">B", Y)
   Block[12:16] = pack(">H", Z))

but, of course, Block, a str, can't be sliced.  The real use of this is a 
bit more complicated such that I can't just fill in all of the "fields" 
within Block in one giant pack().  I need to build it on the fly.  For 
example the pack(">H", X) may be completely skipped some times through the 
function.  There are many more fields in Block than in this example and they 
are all kinds of types not just H's and B's.  What I really want is a C 
struct union. :)

How would I do this?

Thanks!

Bob


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


Python on Intel A110?

2007-10-23 Thread Bob Greschke
Will the "stock" Windows version of Python install on a Samsung Q1U-EL 
UMPC running Vista and with an Intel A110 processor?  I want to do some 
development and just happened to think about this.  I don't know what 
these processors are compatible with at the binary level.

Thanks!

Bob

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


Fixed length lists from .split()?

2007-01-26 Thread Bob Greschke
I'm reading a file that has lines like

bcsn; 100; 1223
bcsn; 101; 1456
bcsn; 103
bcsn; 110; 4567

The problem is the line with only the one semi-colon.
Is there a fancy way to get Parts=Line.split(";") to make Parts always 
have three items in it, or do I just have to check the length of Parts 
and loop to add the required missing items (this one would just take 
Parts+=[""], but there are other types of lines in the file that have 
about 10 "fields" that also have this problem)?

Thanks!

Bob

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


Re: time series data and NumPy

2007-01-26 Thread Bob Greschke
On 2007-01-26 10:54:02 -0700, "BBands" <[EMAIL PROTECTED]> said:

> On Jan 26, 9:29 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> 
>> What you could do would be to convert the date-column into a timestamp,
>> which is a int/long, and use that. Would that help?
> 
> Actually that might help, as all I need the date for is to index
> values.
> 
> Thanks, I'll give it a spin.
> 
>  jab

You're using the Python-MySQL module mysqldb, right?  You can select 
the data from the database and have MySQL do the conversion with an SQL 
command.

select to_days(),  from 
;

Bob


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


Re: Fixed length lists from .split()?

2007-01-26 Thread Bob Greschke
On 2007-01-26 11:13:56 -0700, Duncan Booth <[EMAIL PROTECTED]> said:

> Bob Greschke <[EMAIL PROTECTED]> wrote:
> 
>> Is there a fancy way to get Parts=Line.split(";") to make Parts always 
>> have three items in it, or do I just have to check the length of Parts 
>> and loop to add the required missing items (this one would just take 
>> Parts+=[""], but there are other types of lines in the file that have 
>> about 10 "fields" that also have this problem)?
> 
>>>> def nsplit(s, sep, n):
>   return (s.split(sep) + [""]*n)[:n]
> 
>>>> nsplit("bcsn; 101; 1456", ";", 3)
> ['bcsn', ' 101', ' 1456']
>>>> nsplit("bcsn; 101", ";", 3)
> ['bcsn', ' 101', '']

That's fancy enough. :)  I didn't know you could do  [""]*n.  I never 
thought about it before.

Thanks!

Bob

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


Re: Tkinter Scrolling

2007-02-01 Thread Bob Greschke
On 2007-02-01 05:35:30 -0700, "D" <[EMAIL PROTECTED]> said:

> I'm sure this is a simple question to the Tkinter experts - I have a
> very basic Tkinter application that consists of 1 master window and
> buttons within that window.  My problem is that, I need to be able to
> scroll (up and down) when I get to the point that the buttons go off
> the screen.  What's the easiest way to do this?  Thanks in advance.

The super-easiest way is to make the "background" a Text() widget, add 
its scrollbars, then add the buttons and whatever else to it.  Of 
course you are then limited to the 'typewriter layout' of widget 
placement.  The typical way to do it is to make a scrolling canvas and 
pack the buttons and other stuff into an empty Frame() and then pack 
the frame on to the canvas, which I haven't had to do yet.

Bob

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


Re: Fixed length lists from .split()?

2007-02-01 Thread Bob Greschke
This idiom is what I ended up using (a lot it turns out!):

Parts = Line.split(";")
Parts += (x-len(Parts))*[""]

where x knows how long the line should be.  If the line already has 
more parts than x (i.e. [""] gets multiplied by a negative number) 
nothing seems to happen which is just fine in this program's case.

Bob

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


Re: Writing backwards compatible code - when?

2006-04-18 Thread Bob Greschke
Is there a list of all of the Python commands and modules that tell when 
(what version) they were added to Python?  I was hoping the new Essential 
Reference would have it, but it doesn't.

Thanks!

Bob


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


Canvas items into widgets?

2006-05-23 Thread Bob Greschke
I have a "tooltip" class that is used like

   Lab = Label(Sub, text = "Temp:")
   Lab.pack()
   Tooltip(Lab, "The temperature of the reactor core")

When the mouse pointer is placed over the "Temp:" label the associated 
message pops up in a small window near the pointer.

I want to use the same thing with a canvas item, but the "create_x" calls 
return an ID number not a widget 'handle' like Label() does.  Is there a way 
to turn these IDs into widgets?  I mean the ovals and rectangles are, 
technically, widgets already, aren't they?  I don't think the tag_bind stuff 
will quite work (but I don't fully grasp the concept, except in cases where 
you want to do something like drag the items around on the canvas) since 
each item will have a different message, like, for example, each point on a 
graph will have a tooltip that reports what the temperature of that point 
was.

The concept:

   Rec = can.create_rectangle()
   Wig = (Then a miracle occurs)
   Tooltip(Wig, "1500C - She's gonna blow!!")


Thanks!

Bob :)


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


Re: Don't wish to give up on a Tkinter GUI Builder :(

2006-05-23 Thread Bob Greschke
"vbgunz" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thank you very much for the link and info. It looks promising but I am
> still on the lookout for a drag-n-drop Gui builder like vltc so if
> anyone has more links to new projects I am definitely interested!
>
> PS. I do love the code generated from rapyd!
>

What are you building?  I routinely do things like these by hand

www.greschke.com/unlinked/images/changeo.jpg
www.greschke.com/unlinked/images/pocus.jpg
www.greschke.com/unlinked/images/pis.jpg
www.greschke.com/unlinked/images/petm.jpg

and I can't imagine using a builder for anything 'simpler'.  If you are just
starting out I'd go the long-hand route first until you really have a good
grasp of Tkinter, then go the easier route.  Once you find your own "style"
it becomes easier to just do it rather than try to get some other program
to do it for you.

I tried rapyd today, too.  Started it, drug a button to the frame, but then
couldn't figure out how to set the text of the button.  Deleted it. :)

Bob


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


Tkinter canvas zooming (sortof)

2006-05-26 Thread Bob Greschke
I have a program that sucks in a list of equipment positions (Lats/Longs), 
opens a Toplevel frame with a canvas set to, for example, 700x480 pixels, 
and then does all of the calculations and plots the objects with 10-pixel 
wide ovals and rectangles.  Now I want to zoom in (or out), but I don't want 
the ovals and rectangles to change size.  I just want them to spread out or 
get closer together.  So scale() doesn't seem to be the way to go.  What I 
want to do is just make the "logical" canvas bigger and replot everything, 
but when I reconfigure the canvas size to make it bigger the Toplevel frame 
itself gets bigger.  I want the frame to stay the same size, but still be 
resizable.  I have scrollbars, and they seem to work ok, and scrollregion 
seems to do what it should, but I can't figure out how to get them to all 
work together to do what I want.  Help?

Thanks!

Bob


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


Re: Tkinter canvas zooming (sortof)

2006-05-26 Thread Bob Greschke
"Bob Greschke" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I have a program that sucks in a list of equipment positions (Lats/Longs), 
>opens a Toplevel frame with a canvas set to, for example, 700x480 pixels, 
>and then does all of the calculations and plots the objects with 10-pixel 
>wide ovals and rectangles.  Now I want to zoom in (or out), but I don't 
>want the ovals and rectangles to change size.  I just want them to spread 
>out or get closer together.  So scale() doesn't seem to be the way to go. 
>What I want to do is just make the "logical" canvas bigger and replot 
>everything, but when I reconfigure the canvas size to make it bigger the 
>Toplevel frame itself gets bigger.  I want the frame to stay the same size, 
>but still be resizable.  I have scrollbars, and they seem to work ok, and 
>scrollregion seems to do what it should, but I can't figure out how to get 
>them to all work together to do what I want.  Help?
>
> Thanks!
>
> Bob

After further fiddling...

I think I kind of figured this out.  I could tell my plotting routine that 
the canvas was twice as large as I originally made it, and it would draw 
everything (i.e. if I drug the frame larger I could see more stuff off the 
edge of the canvas), but the scrollbars would not "activate" so I could 
scroll over to stuff off the edge of the canvas.  What I was doing wrong was 
not setting the scrollregion to the whole new canvas size that I used for 
plotting.  I kept setting it to the size of the visible canvas in the frame 
or not setting it at all.  I almost understand. :)  Now all I have to do is 
be able to grab the canvas and drag it around with the mouse and click on a 
spot and have it center that spot and zoom in there.

Bob


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


List of disk drives on Windows?

2008-05-20 Thread Bob Greschke
This MUST have been asked before, but I can't seem to Google the right 
thing.  How can I get a list of drives on a Windows box, like ["C:\", 
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?


Thanks!

Bob

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


Re: List of disk drives on Windows?

2008-05-22 Thread Bob Greschke

On 2008-05-20 13:18:08 -0600, Bob Greschke <[EMAIL PROTECTED]> said:

This MUST have been asked before, but I can't seem to Google the right 
thing.  How can I get a list of drives on a Windows box, like ["C:\", 
"D:\"], like I can if I do something like listdir("/Volumes") on a Mac?


Thanks!

Bob


Thanks for the ideas, guys!  It's off to the emacs...


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


2's complement conversion. Is this right?

2008-04-18 Thread Bob Greschke
I'm reading 3-byte numbers from a file and they are signed (+8 to 
-8million).  This seems to work, but I'm not sure it's right.

# Convert the 3-characters into a number.
Value1, Value2, Value3 = unpack(">BBB", Buffer[s:s+3])
Value = (Value1*65536)+(Value2*256)+Value3
if Value >= 0x80:
Value -= 0x100
print Value

For example:
16682720 = -94496

Should it be Value -= 0x101 so that I get -94497, instead?

Thanks!

Bob

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


Re: 2's complement conversion. Is this right?

2008-04-18 Thread Bob Greschke
On 2008-04-18 14:37:21 -0600, Ross Ridge 
<[EMAIL PROTECTED]> said:

> Bob Greschke  <[EMAIL PROTECTED]> wrote:
>> I'm reading 3-byte numbers from a file and they are signed (+8 to 
>> -8million).  This seems to work, but I'm not sure it's right.
>> 
>> # Convert the 3-characters into a number.
>> Value1, Value2, Value3 = unpack(">BBB", Buffer[s:s+3])
>> Value = (Value1*65536)+(Value2*256)+Value3
>> if Value >= 0x80:
>> Value -= 0x100
>> print Value
>> 
>> For example:
>> 16682720 = -94496
>> 
>> Should it be Value -= 0x101 so that I get -94497, instead?
> 
> Your first case is correct, "Value -= 0x100".  The value 0xFFF
> should be -1 and 0xFFF - 0x100 == -1.
> 
> An alternative way of doing this:
> 
>   Value = unpack(">l", Buffer[s:s+3] + "\0")[0] >> 8
> 
>   Ross Ridge

Good to know (never was good on the math front).

However, in playing around with your suggestion and Grant's code I've 
found that the struct stuff is WAY slower than doing something like this

 Value = (ord(Buf[s])*65536)+(ord(Buf[s+1])*256)+ord(Buf[s+2])
 if Value >= 0x80:
 Value -= 0x100

This is almost twice as fast just sitting here grinding through a few 
hundred thousand conversions (like 3sec vs. ~5secs just counting on my 
fingers - on an old Sun...it's a bit slow).  Replacing *65536 with <<16 
and *256 with <<8 might even be a little faster, but it's too close to 
call without really profiling it.

I wasn't planning on making this discovery today! :)

Bob



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


Re: 2's complement conversion. Is this right?

2008-04-18 Thread Bob Greschke
On 2008-04-18 16:04:37 -0600, George Sakkis <[EMAIL PROTECTED]> said:

> On Apr 18, 5:26 pm, Bob Greschke <[EMAIL PROTECTED]> wrote:
> 
>> On 2008-04-18 14:37:21 -0600, Ross Ridge
>> <[EMAIL PROTECTED]> said:
>> 
>> 
>> 
>>> Bob Greschke  <[EMAIL PROTECTED]> wrote:
>>>> I'm reading 3-byte numbers from a file and they are signed (+8 to
>>>> -8million).  This seems to work, but I'm not sure it's right.
>> 
>>>> # Convert the 3-characters into a number.
>>>> Value1, Value2, Value3 = unpack(">BBB", Buffer[s:s+3])
>>>> Value = (Value1*65536)+(Value2*256)+Value3
>>>> if Value >= 0x80:
>>>> Value -= 0x100
>>>> print Value
>> 
>>>> For example:
>>>> 16682720 = -94496
>> 
>>>> Should it be Value -= 0x101 so that I get -94497, instead?
>> 
>>> Your first case is correct, "Value -= 0x100".  The value 0xF
> FF
>>> should be -1 and 0xFFF - 0x100 == -1.
>> 
>>> An alternative way of doing this:
>> 
>>>    Value = unpack(">l", Buffer[s:s+3] + "\0")[0] >> 8
>> 
>>>                                    R
> oss Ridge
>> 
>> Good to know (never was good on the math front).
>> 
>> However, in playing around with your suggestion and Grant's code I've
>> found that the struct stuff is WAY slower than doing something like this
>> 
>>  Value = (ord(Buf[s])*65536)+(ord(Buf[s+1])*256)+ord(Buf[s+2])
>>  if Value >= 0x80:
>>      Value -= 0x100
>> 
>> This is almost twice as fast just sitting here grinding through a few
>> hundred thousand conversions (like 3sec vs. ~5secs just counting on my
>> fingers - on an old Sun...it's a bit slow).  
> 
> You'd better use a more precise timing method than finger counting,
> such as timeit. Twice as fast is probably a gross overestimation; on
> my box (Python 2.5, WinXP) avoiding unpack is around 10% and 40%
> faster from Ross's and Grant's method, respectively:
> 
> python -m timeit "for i in xrange(1000):from3Bytes_bob(s)" \
>-s "from bin import *; s=pack('>i',1234567)[1:]"
> 1000 loops, best of 3: 1.02 msec per loop
> 
> python -m timeit "for i in xrange(1000):from3Bytes_grant(s)" \
>-s "from bin import *; s=pack('>i',1234567)[1:]"
> 1000 loops, best of 3: 1.43 msec per loop
> 
> python -m timeit "for i in xrange(1000):from3Bytes_ross(s)" \
>-s "from bin import *; s=pack('>i',1234567)[1:]"
> 1000 loops, best of 3: 1.12 msec per loop
> 
> ### bin.py ##
> 
> from struct import unpack
> 
> def from3Bytes_bob(s):
> Value = (ord(s[0])<<16) + (ord(s[1])<<8) + ord(s[2])
> if Value >= 0x80:
> Value -= 0x100
> return Value
> 
> def from3Bytes_grant(s):
> if ord(s[0]) & 0x80:
> s = '\xff'+s
> else:
> s = '\x00'+s
> return unpack('>i',s)[0]
> 
> def from3Bytes_ross(s):
> return unpack(">l", s + "\0")[0] >> 8
> 
> 
>> Replacing *65536 with <<16
>> and *256 with <<8 might even be a little faster, but it's too close to
>> call without really profiling it.
> 
>> I wasn't planning on making this discovery today! :)
>> 
>> Bob
> 
> If you are running this on a 32-bit architecture, get Psyco [1] and
> add at the top of your module:
> import psyco; psyco.full()
> 
> Using Psyco in this scenatio is up to 70% faster:
> 
> python -m timeit "for i in xrange(1000):from3Bytes_bob(s)" \
>-s "from bin import *; s=pack('>i',1234567)[1:]"
> 1000 loops, best of 3: 624 usec per loop
> 
> python -m timeit "for i in xrange(1000):from3Bytes_grant(s)" \
>-s "from bin import *; s=pack('>i',1234567)[1:]"
> 1000 loops, best of 3: 838 usec per loop
> 
> python -m timeit "for i in xrange(1000):from3Bytes_ross(s)" \
>-s "from bin import *; s=pack('>i',1234567)[1:]"
> 1000 loops, best of 3: 834 usec per loop
> 
> 
> George
> 
> [1] http://psyco.sourceforge.net/

I'm on a Solaris 8 with Python 2.3.4 and when crunching through, 
literally, millions and millions of samples of seismic data fingers 
point out the difference nicely. :)  I'll look into this more on some 
of our bigger better faster machines (there is no -m option for timeit 
on the Sun :).  The Sun is just what I develop on.  If stuff runs fast 
enough to keep me awake on there over an ssh'ed X11 connection it 
should run even better on the real field equipment (Macs, Linuxes, 
WinXPs).

Never heard of Psyco.  That's nice!

Thanks!

Bob



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


Re: 2's complement conversion. Is this right?

2008-04-18 Thread Bob Greschke
On 2008-04-18 17:55:32 -0600, Ross Ridge 
<[EMAIL PROTECTED]> said:

> George Sakkis  <[EMAIL PROTECTED]> wrote:
>> You'd better use a more precise timing method than finger counting,
>> such as timeit. Twice as fast is probably a gross overestimation; on
>> my box (Python 2.5, WinXP) avoiding unpack is around 10% and 40%
>> faster from Ross's and Grant's method, respectively:
> ...
>> def from3Bytes_ross(s):
>> return unpack(">l", s + "\0")[0] >> 8
> 
> If you have Python 2.5, here's a faster version:
> 
>   from struct import *
>   unpack_i32be = Struct(">l").unpack
> 
>   def from3Bytes_ross2(s):
>   return unpack_i32be(s + "\0")[0] >> 8
> 
>   Ross Ridge

That's not even intelligible.  I wanna go back to COBOL. :)

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


Re: 2's complement conversion. Is this right?

2008-04-19 Thread Bob Greschke
On 2008-04-18 23:35:12 -0600, Ivan Illarionov <[EMAIL PROTECTED]> said:

> On Sat, 19 Apr 2008 04:45:54 +, Ivan Illarionov wrote:
> 
>> On Fri, 18 Apr 2008 22:30:45 -0500, Grant Edwards wrote:
>> 
>>> On 2008-04-18, Bob Greschke <[EMAIL PROTECTED]> wrote:
>>> 
>>>> However, in playing around with your suggestion and Grant's code I've
>>>> found that the struct stuff is WAY slower than doing something like
>>>> this
>>>> 
>>>> Value = (ord(Buf[s])*65536)+(ord(Buf[s+1])*256)+ord(Buf[s+2]) if
>>>> Value
>>>>> = 0x80:
>>>> Value -= 0x100
>>>> 
>>>> This is almost twice as fast just sitting here grinding through a few
>>>> hundred thousand conversions (like 3sec vs. ~5secs just counting on my
>>>> fingers - on an old Sun...it's a bit slow).  Replacing *65536 with
>>>> <<16 and *256 with <<8 might even be a little faster, but it's too
>>>> close to call without really profiling it.
>>> 
>>> I didn't know speed was important.  This might be a little faster
>>> (depending on hardware):
>>> 
>>> Value = (ord(Buf[s])<<16) | (ord(Buf[s+1])<<8) | ord(Buf[s+2])
>>> 
>>> It also makes the intention a bit more obvious (at least to me).
>>> 
>>> A decent C compiler will recognize that <<16 and <<8 are special and
>>> just move bytes around rather than actually doing shifts.  I doubt the
>>> Python compiler does optimizations like that, but shifts are still
>>> usually faster than multiplies (though, again, a good compiler will
>>> recognize that multiplying by 65536 is the same as shifting by 16 and
>>> just move bytes around).
>> 
>> So why not put it in C extension?
>> 
>> It's easier than most people think:
>> 
>> 
>> from3bytes.c
>> 
>> #include 
>> 
>> PyObject*
>> from3bytes(PyObject* self, PyObject* args) {
>> const char * s;
>> int len;
>> if (!PyArg_ParseTuple(args, "s#", &s, &len))
>> return NULL;
>> long n = (s[0]<<16) | (s[1]<<8) | s[2]; if (n >= 0x80)
>> n -= 0x100;
>> return PyInt_FromLong(n);
>> }
>> 
>> static PyMethodDef functions[] = {
>> {"from3bytes",(PyCFunction)from3bytes, METH_VARARGS}, {NULL,
>> NULL, 0, NULL},
>> };
>> 
>> 
>> DL_EXPORT(void)
>> init_from3bytes(void)
>> {
>> Py_InitModule("_from3bytes", functions);
>> }
>> 
>> buildme.py
>> ==
>> import os
>> import sys
>> from distutils.core import Extension, setup
>> 
>> os.chdir(os.path.dirname(os.path.abspath(__file__))) sys.argv =
>> [sys.argv[0], 'build_ext', '-i'] setup(ext_modules =
>> [Extension('_from3bytes', ['from3bytes.c'])]) 
>> 
>> 'python buildme.py' will create '_from3bytes.so' file 'from _from3bytes
>> import from3bytes' will import C-optimized function
>> 
>> Hope this helps.
> 
> Sorry,
> the right code should be:
> 
> PyObject* from3bytes(PyObject* self, PyObject* args)
> {
> const char * s;
> int len;
> if (!PyArg_ParseTuple(args, "s#", &s, &len))
> return NULL;
> long n = unsigned char)s[0])<<16) | (((unsigned char)s[1])<<8) |
> ((unsigned char)s[2]));
> if (n >= 0x80)
> n -= 0x100;
> return PyInt_FromLong(n);
> }

No thanks.  Being able to alter and install these programs on whatever 
computer they are installed on is more important than speed.  I went 
down the C-extension path years ago and it turned into a big mess.  
Everything has to run on Sun's, Mac's, Linux and Windows without any 
major hassels if they have to be changed.  I can't reley on everything 
the program needs to be rebuilt being installed beyond Python and 
Tkinter (and pySerial and PIL for a couple of programs), which they 
need to run.  So no compiling and everything is in one file, in case a 
new version has to be upgraded by a user by emailing it to them while 
they're sitting on some mountain in Tibet.  Just unzip, stick the .py 
somewhere logical, (usually) double-click, and they are off and running.

Bob


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


Re: 2's complement conversion. Is this right?

2008-04-19 Thread Bob Greschke
On 2008-04-18 21:33:34 -0600, Grant Edwards <[EMAIL PROTECTED]> said:

> On 2008-04-18, Bob Greschke <[EMAIL PROTECTED]> wrote:
> 
>> I'm on a Solaris 8 with Python 2.3.4 and when crunching
>> through, literally, millions and millions of samples of
>> seismic data fingers point out the difference nicely. :) I'll
>> look into this more on some of our bigger better faster
>> machines (there is no -m option for timeit on the Sun :).  The
>> Sun is just what I develop on.  If stuff runs fast enough to
>> keep me awake on there over an ssh'ed X11 connection it should run even 
>> better on the real field equipment (Macs,
>> Linuxes, WinXPs).
> 
> If time is an issue, I might write a C program to convert the
> files from 24-bit numbers to 32-bit numbers.  Then you can use
> numpy to load huge arrays of them in a single whack.

Yes you could. :)  But this is all in real time (as in 'gotta have it 
right now' real time).  Plus we're dealing with 100's of files 
(instruments) at a time.  It'll be 1000's of instruments this summer up 
in Canada.

Here's the program having happily crunched away at nearly twice the 
speed it was the day before yesterday.

www.greschke.com/unlinked/files/pocus.png

The white dots come from the 3-byte integers and make up the green line 
which makes up one 'logical' chunk (in this case they recorded for 
60mins at a time) of a whole data file with one file per instrument.  
Generally we just take a quick look at the green lines to make sure the 
instruments were working, and pull out the bad ones so they don't get 
used again until they've been looked at.  Zooming in to the level where 
you can see the individual samples is used to (more) accurately 
determine the time when an [intentional] explosion was set off.  You 
use instruments placed near the shot holes for that.  Simple. :)

Bob



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


Re: 2's complement conversion. Is this right?

2008-04-19 Thread Bob Greschke
> 
> 
> www.greschke.com/unlinked/files/pocus.png
> 
> 
> Darnit.

www.greschke.com/unlinked/images/pocus.png

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


Re: 2's complement conversion. Is this right?

2008-04-21 Thread Bob Greschke
On 2008-04-21 14:50:13 -0600, Ivan Illarionov <[EMAIL PROTECTED]> said:

> On 22 апр, 00:10, Ivan Illarionov <[EMAIL PROTECTED]>  wrote:
>> On 20 ÁÐÒ, 04:10, George Sakkis <[EMAIL PROTECTED]> w
> rote:
>> 
>> 
>> 
>>> On Apr 18, 9:36 pm, Ross Ridge <[EMAIL PROTECTED]>
>>> wrote:
>> 
>>>> Ross Ridge <[EMAIL PROTECTED]> said:
>> 
>>>>> If you have Python 2.5, here's a faster version:
>> 
>>>>> from struct import *
>>>>> unpack_i32be = Struct(">l").unpack
>> 
>>>>> def from3Bytes_ross2(s):
>>>>> return unpack_i32be(s + "\0")[0] >> 8
>> 
>>>> Bob Greschke  <[EMAIL PROTECTED]> wrote:
>> 
>>>>> That's not even intelligible.  I wanna go back to COBOL. :)
>> 
>>>> It's the same as the previous version except that it "precompiles"
>>>> the struct.unpack() format string.  It works similar to the way Python
> 
>>>> handles regular expressions.
>> 
>>> I didn't know about the Struct class; pretty neat. It's amazing that
>>> this version without Psyco is as fast Bob's version with Psyco! Adding
>>> Psyco to it though makes it *slower*, not faster. So here's how I'd
>>> write it (if I wanted or had to stay in pure Python):
>> 
>>> try: import psyco
>>> except ImportError:
>>> from struct import Struct
>>> unpack_i32be = Struct(">l").unpack
>>> def from3Bytes(s):
>>> return unpack_i32be(s + "\0")[0] >> 8
>>> else:
>>> def from3Bytes(s):
>>> Value = (ord(s[0])<<16) + (ord(s[1])<<8) + ord(s[2])
>>> if Value >= 0x80:
>>> Value -= 0x100
>>> return Value
>>> psyco.bind(from3Bytes)
>> 
>>> HTH,
>>> George
>> 
>> I was able to get even faster pure-python version using array module:
>> 
>> a = array.array('l', ''.join(('\0' + s[i:i+3] for i in xrange(0,
>> len(s), 3
>> if sys.byteorder == 'little':
>> a.byteswap()
>> 
>> It actually moves bytes around on C level.
>> 
>> test code:
>> import struct
>> import array
>> import sys
>> 
>> unpack_i32be = struct.Struct(">l").unpack
>> s = ''.join(struct.pack('>i', 1234567)[1:]*1000)
>> 
>> def from3bytes_ord(s):
>> values = []
>> for i in xrange(0, len(s), 3):
>> Value = (ord(s[i])<<16) | (ord(s[i+1])<<8) | ord(s[i+2])
>> if Value >= 0x80:
>> Value -= 0x100
>> values.append(Value)
>> return values
>> 
>> def from3bytes_struct(s):
>> return [unpack_i32be(s[i:i+3] + "\0")[0] >> 8 for i in xrange(0,
>> len(s), 3)]
>> 
>> def from3bytes_array(s):
>> a = array.array('l', ''.join(('\0' + s[i:i+3] for i in xrange(0,
>> len(s), 3
>> if sys.byteorder == 'little':
>> a.byteswap()
>> return a.tolist()
>> 
>> from timeit import Timer
>> 
>> t1 = Timer("from3bytes_ord(s)", "from __main__ import s,
>> from3bytes_ord")
>> t2 = Timer("from3bytes_struct(s)", "from __main__ import s,
>> from3bytes_struct")
>> t3 = Timer("from3bytes_array(s)", "from __main__ import s,
>> from3bytes_array")
>> 
>> print 'ord:\t', t1.timeit(1000)
>> print 'struct:\t', t2.timeit(1000)
>> print 'array:\t', t3.timeit(1000)
>> 
>> Output:
>> ord:7.08213110884
>> struct: 3.7689164405
>> array:  2.62995268952
>> 
>> Inspired by Guido's essayhttp://www.python.org/doc/essays/list2str/
> 
> And even faster:
> a = array.array('i', '\0' + '\0'.join((s[i:i+3] for i in xrange(0,
> len(s), 3
> if sys.byteorder == 'little':
> a.byteswap()
> 
> I think it's a fastest possible implementation in pure python

Geeze! :)  How did struct get so fast?  I'm guessing there have been 
improvements since 2.3 (which is what I've been working on).  I'm going 
to be able to go back to my IBM PC XT pretty soon. :)

Thanks!

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

Re: 2's complement conversion. Is this right?

2008-04-21 Thread Bob Greschke
Something is fishy.  I just ran this simple-minded thing and I'm, 
again, getting better times for ord() than I am for unpack() on a 
2.8GHz OSX iMac with 2.5.1.  This is the iterate so many times you can 
use your wristwatch method:




#! /usr/bin/env python

from os import system
from struct import unpack

print "unpack 1"
system("date")
for x in xrange(0, 1):
   Value = unpack(">B", "a")
system("date")
print

print "ord 1"
system("date")
for x in xrange(0, 1):
   Value = ord("a")
system("date")
print

print "unpack 3"
system("date")
for x in xrange(0, 1):
   Value = unpack(">BBB", "abc")
system("date")
print

print "ord 3"
system("date")
for x in xrange(0, 1):
   Value = (ord("a") << 16)+(ord("b") << 8)+ord("c")
system("date")




Unpack 1 is about 1m20s
Ord 1 is about 20s
Unpack 3 is about 1m20s
Ord 3 is about 1m03s
after averaging a few runs.

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


Re: 2's complement conversion. Is this right?

2008-04-21 Thread Bob Greschke

On 2008-04-21 16:51:13 -0600, Bob Greschke <[EMAIL PROTECTED]> said:
JUST COMPLETELY IGNORE THAT LAST ONE.  What a dope.  Here:

#! /usr/bin/env python

from os import system
from struct import unpack

print "unpack 1"
system("date")
for x in xrange(0, 1):
   Value = unpack(">B", "a")[0]
   if Value > 0x80:
   Value -= 0x100
system("date")
print

print "ord 1"
system("date")
for x in xrange(0, 1):
   Value = ord("a")
   if Value > 0x80:
   Value -= 0x100
system("date")
print

print "unpack 3"
system("date")
for x in xrange(0, 1):
   Value1, Value2, Value3 = unpack(">BBB", "abc")
   Value = (Value1 << 16)+(Value2 << 8)+Value3
   if Value > 0x80:
   Value -= 0x100
system("date")
print

print "ord 3"
system("date")
for x in xrange(0, 1):
   Value = (ord("a") << 16)+(ord("b") << 8)+ord("c")
   if Value > 0x80:
   Value -= 0x100
system("date")


Still, the differences between unpack and ord are significant (I just 
threw in the if's for fun).



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


Re: 2's complement conversion. Is this right?

2008-04-21 Thread Bob Greschke

On 2008-04-21 17:06:39 -0600, Bob Greschke <[EMAIL PROTECTED]> said:


On 2008-04-21 16:51:13 -0600, Bob Greschke <[EMAIL PROTECTED]> said:
JUST COMPLETELY IGNORE THAT LAST ONE.  What a dope.  Here:

#! /usr/bin/env python

from os import system
from struct import unpack

print "unpack 1"
system("date")
for x in xrange(0, 1):
Value = unpack(">B", "a")[0]
if Value > 0x80:
Value -= 0x100
system("date")
print

print "ord 1"
system("date")
for x in xrange(0, 1):
Value = ord("a")
if Value > 0x80:
Value -= 0x100
system("date")
print

print "unpack 3"
system("date")
for x in xrange(0, 1):
Value1, Value2, Value3 = unpack(">BBB", "abc")
Value = (Value1 << 16)+(Value2 << 8)+Value3
if Value > 0x80:
Value -= 0x100
system("date")
print

print "ord 3"
system("date")
for x in xrange(0, 1):
Value = (ord("a") << 16)+(ord("b") << 8)+ord("c")
if Value > 0x80:
Value -= 0x100
system("date")


Still, the differences between unpack and ord are significant (I just 
threw in the if's for fun).


I just ran this on my SunBlade 1000 with 2.3.4 and

unpack 1: 7m53s
ord 1: 2m00s
unpack 3: 14m20s
ord 3: 5m30s

timeit looks broken somehow to me.

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


PIL ImageDraw line not long enough

2006-03-30 Thread Bob Greschke
I've resorted to actually drawing all of the characters of the alphabet on a 
graph to avoid having to drag around font files.  It's mostly just uppercase 
characters, so it's not too bad.

But I noticed that some of the line segments have to be extended one pixel 
longer than they should be in order for the last pixel to show up.

The character cells are 6 pixels wide by 8 pixels high.  An "L" is drawn 
with

   Graph.line((x,y, x,y+7, x+5,y+7), Color)

where the starting x and y are supplied to the function.  An L works OK, but 
to get a "T" to look right I have to do

   Graph.line((x+1,y, x+5,y), Color)
   Graph.line((x+3,y, x+3,y+8), Color)

I have to extend the vertical line to y+8, instead of y+7 to get the line 
segment to be drawn long enough.  This is on Linux, Solaris, 2.x versions of 
Python, 1.1.5 version of PIL, and on Windows with the latest of everything. 
Am I missing a setting somewhere?

Thanks!

Bob




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


Re: PIL ImageDraw line not long enough

2006-04-01 Thread Bob Greschke
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Bob Greschke wrote:
>
>> I have to extend the vertical line to y+8, instead of y+7 to get the line
>> segment to be drawn long enough.  This is on Linux, Solaris, 2.x versions
>> of
>> Python, 1.1.5 version of PIL, and on Windows with the latest of
>> everything.
>> Am I missing a setting somewhere?
>
> I recently got another bug reported that talked about the same thing, so
> it's probably a bug in 1.1.5 that nobody has noticed before.
>
> (as nikie mentions, the low-level line segment drawer avoids drawing over-
> lapping points, but the "line" wrapper should add the last pixel)
>
> 

Hey! It's not ME for once. :)  It seems to only happen with lines that have
a vertical-ness to them (straight up-down or diagonal).  It doesn't seem to
happen when the line segment is just horizontal.

These are the characters that I am drawing

www.greschke.com/unlinked/images/graphs.png

It works really well.

Thanks!

Bob



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


Windows and My Documents

2010-06-03 Thread Bob Greschke

I know this must have been asked before, but today Google is not my friend.

How do I do a "listdir" (or whatever I need to use) of the Desktop on a 
Windows machine and have "folders" like My Documents show up in the 
result?


I'm specifically trying to get a link to VMWare Shared Folders to show 
up so I can navigate to files in OSX from WinXP running in VMWare, but 
My Documents doesn't show up, either.


The docs for listdir says it doesn't follow links and I don't think I 
want to tell os.walk to followlinks as that could be zillions of files.


Thanks!

Bob

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


Re: Windows and My Documents

2010-06-03 Thread Bob Greschke

On 2010-06-03 09:57:11 -0600, Tim Golden  said:


On 03/06/2010 16:39, Bob Greschke wrote:

How do I do a "listdir" (or whatever I need to use) of the Desktop on a
Windows machine and have "folders" like My Documents show up in the result?

I'm specifically trying to get a link to VMWare Shared Folders to show
up so I can navigate to files in OSX from WinXP running in VMWare, but
My Documents doesn't show up, either.

The docs for listdir says it doesn't follow links and I don't think I
want to tell os.walk to followlinks as that could be zillions of files.


Depends exactly what '"folders" like My Documents' means (since I'm unfamiliar
with VMWare Shared Folders) but you almost certainly want to use the Shell
functions to walk the shell from the Desktop root. There was a short thread
recently about it which I'll try to dig up (digs...):

   http://mail.python.org/pipermail/python-win32/2010-May/010475.html

TJG


Well, My Documents is not a normal folder.  It's not the same as 
right-clicking and creating a new folder.  I don't know what it is, 
exactly.  VMWare Shared Folders seems to be a normal sort of link to 
'\\.host\Share Folders', but not quite, however, beyond that I'm not 
sure what it is.  If I create Shortcuts to My Documents and VSF those 
show up with listdir, but I cannot follow them; Python does not think 
they are directories, which they aren't  (they show up from listdir as 
'Shortcut to My Documents.lnk', for example).


I'll take a look at the link above.  Thanks!

Bob

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