Fwd: [wxpython-users] Setting up global keybindings without corresponding menu items

2008-11-24 Thread mercado mercado
Forwarded conversation
Subject: Setting up global keybindings without corresponding menu items


From: *mercado mercado* <[EMAIL PROTECTED]>
Date: Fri, Aug 1, 2008 at 4:15 PM
To: [EMAIL PROTECTED]


I'm trying to set up a global keyboard shortcut for my application.  I know
how to do this by associating the shortcut with a menu item, but I want to
do it without a corresponding menu item.  As per the instructions here (
http://lists.wxwidgets.org/pipermail/wxpython-users/2003-August/021655.html),
I should be able to do this with an accelerator table, but I can't get it to
work.

I've included a small, self-contained sample that attempts to bind an event
handler with the Ctrl-L shortcut.  Can anybody see what I'm doing wrong?
Thanks in advance.

I am running wxPython 2.8.8.1 on Ubuntu 8.04.1 Hardy.
-
import wx

class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__ (self, parent, -1, title, size=(500,200))
self.panel = wx.Panel(self, -1)

EVT_TEST_ID = wx.NewId()

wx.EVT_MENU(self, EVT_TEST_ID, self.OnTestEvent)

aTable = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('L'), EVT_TEST_ID)
])

self.SetAcceleratorTable(aTable)

self.Show(True)

def OnTestEvent(self, event):
print "OnTestEvent fired"

app = wx.App()
frame = MainWindow(None, -1, "Test")
app.MainLoop()

--
From: *Mike Driscoll* <[EMAIL PROTECTED]>
Date: Sat, Aug 2, 2008 at 12:15 PM
To: [EMAIL PROTECTED]


mercado mercado wrote:

> I am running wxPython 2.8.8.1 <http://2.8.8.1> on Ubuntu 8.04.1 Hardy.


Hmmm...this works on Windows XP, '2.8.7.1 (msw-unicode)', Python 2.5.2.

Try changing the event binding to this instead:

self.Bind(wx.EVT_MENU, self.OnTestEvent, id=EVT_TEST_ID)

That's the way I was told to do it...by Robin, I think.

---
Mike Driscoll

Blog:   http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

___
wxpython-users mailing list
[EMAIL PROTECTED]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
From: *mercado mercado* <[EMAIL PROTECTED]>
Date: Sat, Aug 2, 2008 at 4:02 PM
To: [EMAIL PROTECTED]



Thanks for the response Mike.  Unfortunately, the alternative syntax doesn't
work for me either.

???


--
From: *Mike Driscoll* <[EMAIL PROTECTED]>
Date: Mon, Aug 4, 2008 at 8:56 AM
To: [EMAIL PROTECTED]


mercado mercado wrote:

> On Sat, Aug 2, 2008 at 1:15 PM, Mike Driscoll <[EMAIL PROTECTED] [EMAIL PROTECTED]>> wrote:
>
>Hmmm...this works on Windows XP, '2.8.7.1 <http://2.8.7.1>
>(msw-unicode)', Python 2.5.2. <http://2.5.2.>


I loaded Ubuntu Hardy in my VM and confirmed that it does not work with your
sample code. Weird. I did find a recipe in the wiki that might work for you:

http://wiki.wxpython.org/Using%20Multi-key%20Shortcuts

It's a little bit above my head, but it seems to be using an alternative
technique. Maybe it can be modified to work for you?

--
From: *Robin Dunn* <[EMAIL PROTECTED]>
Date: Mon, Aug 4, 2008 at 1:31 PM
To: [EMAIL PROTECTED]


Try adding a widget to the frame that can have the keyboard focus.  The
focus needs to be on some widget within the frame for accelerators attached
to the frame to be active.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

--
From: *mercado mercado* <[EMAIL PROTECTED]>
Date: Mon, Aug 4, 2008 at 1:48 PM
To: [EMAIL PROTECTED]


I tried adding a button to the panel, and giving the button focus, and now
the accelerator table is working as expected.

Thanks Mike and Robin, for your prompt and helpful responses.


--
From: *mercado mercado* <[EMAIL PROTECTED]>
Date: Mon, Nov 24, 2008 at 6:58 PM
To: python dev <[EMAIL PROTECTED]>
--
http://mail.python.org/mailman/listinfo/python-list


Importing different versions of a module

2008-07-17 Thread mercado mercado
I have two versions of a script on my machine. One version is for new
development and the other version is a production version.  This script
imports a module from a different directory, and this module again has two
versions (a development version and a production version).  What I want is
for the development script to import the development module, and the
production script to import the production module, without making any
changes to the code in the script.

For example, suppose the development script is in ~/dev/rss.py, and the
production script is in ~/prod/rss.py.  I want the dev version to import
/usr/lib/python2.5/site-packages/lib_dev/parse.py, and the prod version to
import usr/lib/python2.5/site-packages/lib_prod/parse.py.

My first instinct was to place a .pth file in ~/dev that points to
/usr/lib/python2.5/site-packages/lib_dev, and a .pth file in ~/prod that
points to /usr/lib/python2.5/site-packages/lib_prod, but it seems that
site.py doesn't look at .pth files in the current working directory.  My
next attempt was to create a symbolic link in ~/dev called parse.py,
pointing to /usr/lib/python2.5/site-packages/lib_dev/parse.py, and a
symbolic link in ~/prod called parse.py, pointing to
/usr/lib/python2.5/site-packages/lib_prod/parse.py, but that didn't work
either.

Can anybody suggest a way to achieve my goal?  Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list

Re: Importing different versions of a module

2008-07-18 Thread mercado mercado
Thanks norseman for the reply.

You're right that I didn't like it though.  :-)

Also note that my original question has to do with importing modules from
different locations.  If all I had to do was use different paths within the
script (e.g. for sending to os.path.join or whatever), then I could just put
those in a config file.  That's not a problem...
--
http://mail.python.org/mailman/listinfo/python-list

Re: Importing different versions of a module

2008-07-22 Thread mercado mercado
It seems that you can specify the name of the module to be imported at
runtime using the following syntax:

X = __import__('X')

(from http://effbot.org/zone/import-confusion.htm)

Of course, I would rather specify the path to the module at runtime, not the
module name itself, but at least this is a start...
--
http://mail.python.org/mailman/listinfo/python-list

Importing different versions of a module

2008-07-23 Thread mercado mercado
Thank you Fredrik.  This is exactly what I was looking for.


> cannot you just insert the appropriate directory in sys.path the first
> thing you do in the scripts?  e.g.
>
>  import os, sys
>
>  lib = "lib_dev" # change this for prod/rss.py
>
>  sys.path.insert(0,
>  os.path.join(
>  os.path.dirname(os.__file__), "site-packages", lib
>  ))
>
>  import parse # picks the right one
--
http://mail.python.org/mailman/listinfo/python-list

Retrieving the name of the class calling an instance method

2008-09-05 Thread mercado mercado
In Python, is it possible for an instance method to know the name of the
class which is calling it? For example, in the sample below, I would like
for the someMethod method to print the name of the class calling it ("bar"
in the first case, "again" in the second).

---
class foo():
def someMethod(self):
print x

class bar():
def __init__(self):
f = foo()
f.someMethod()

class again():
def __init__(self):
f = foo()
f.someMethod()

bar()
again()
---
--
http://mail.python.org/mailman/listinfo/python-list

Passing a variable number of arguments to a function

2009-02-12 Thread mercado
I have the following piece of code that is bugging me:

#---
def someFunc(arg1, arg2=True, arg3=0):
print arg1, arg2, arg3

someTuple = (
("this is a string",),
("this is another string", False),
("this is another string", False, 100)
)

for argList in someTuple:
if len(argList) == 1:
someFunc(argList[0])
elif len(argList) == 2:
someFunc(argList[0], argList[1])
elif len(argList) == 3:
someFunc(argList[0], argList[1], argList[2])
#---

Is it possible to rewrite this code so I don't have that awkward if
statement at the bottom that passes every variation in the number of
arguments to the function?  I know that it's possible to define a function
to accept a variable number of parameters using *args or **kwargs, but it's
not possible for me to redefine this function in the particular project I'm
working on.

What I would really like to do is something like this (pseudocode) and do
away with the if statement completely:

#---
def someFunc(arg1, arg2=True, arg3=0):
print arg1, arg2, arg3

someTuple = (
("this is a string",),
("this is another string", False),
("this is another string", False, 100)
)

for argList in someTuple:
someFunc(expandArgList(argList))
#---

Is this possible?  Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Testing against different versions of Python

2008-12-12 Thread mercado
What is the best way to go about testing against different versions of
Python?  For example, I have 2.5.2 installed on my machine (Ubuntu Hardy
8.04), and I want to test a script against 2.5.2 and 2.5.1 (and possibly
other versions as well).

Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list


Using struct to read binary files

2009-11-26 Thread mercado
Hello,

I am writing a Python program to read the Master Boot Record (MBR),
and I'm having trouble because I have no previous experience reading
binary files.

First off, I've written a binary file containing the MBR to disk using
the following command:
sudo dd if=/dev/sda of=/tmp/mbrcontent bs=1 count=512

Then I want to read the MBR file and parse out its information.  For
example, I know that bytes 454-457 contain the address of the first
sector of the first partition, and bytes 458-461 contain the number of
sectors in the first partition (see
http://en.wikipedia.org/wiki/Master_boot_record for more information
on the structure of the MBR).

So far what I have is this:


f = open("/tmp/mbrcontent", "rb")
contents = f.read()
f.close()

firstSectorAddress = contents[454:458]
numSectors = contents[458:462]


On my machine, the bytes contained in firstSectorAddress are
"\x3F\x00\x00\x00", and the bytes contained in numSectors are
"\x20\x1F\x80\x01".  I know from doing a pen and paper calculation
that the first sector address is 63, and the number of sectors is
25,173,792 (the numbers are stored in little-endian format).

How do I figure that out programmatically?  I think that I can use
struct.unpack() to do this, but I'm not quite sure how to use it.

Can anybody help me out?  Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using struct to read binary files

2009-11-27 Thread mercado
Thanks Tim and Gabriel!  That was exactly what I needed
-- 
http://mail.python.org/mailman/listinfo/python-list