How to define metaclass for a class that extends from sqlalchemy declarative base ?

2013-07-02 Thread Ven
I use: Python 2.6 and sqlalchemy 0.6.1

This is what I am trying to do:

from sqlalchemy.types import (
Integer,
String,
Boolean
)
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class SampleMeta(type):
def __new__(cls, name, bases, attrs):
attrs.update({   'id': Column('Id', Integer, primary_key=True),
'name': Column('Name', String),
'description': Column('Description', String),
'is_active': Column('IsActive', Boolean)
})
return super(SampleMeta, cls).__new__(cls, name, bases, attrs)

class Sample(Base):
__tablename__ = 'Sample'
__table_args__ = {'useexisting': True}
__metaclass__ = SampleMeta

def __init__(self, id, name, description, is_active):
self.id = id
self.name = name
self.description = description
self.is_active = is_active

def __repr__(self):
return "<(%d, '%s', '%s', %r)>" % (self.id, self.name, 
self.description, self.isactive)

And the error I am getting is this:

TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a 
(non-strict) subclass of the metaclasses of all its bases

Now, if I do the same thing above by using

class Sample(object)

instead of

class Sample(Base)

it works absolutely fine.

I need to update the attributes of the class dynamically. So, I will be using 
dynamic attribute and column names. And I need the above piece code to work in 
order to be able to get there.

**Please help** 
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling a matlab gui from python using pymatlab without allowing python to close it

2011-06-08 Thread Ven
Before proceeding further, my  system configuration is as follows:

Mac OS X 10.6.6
MATLAB 2010b
ActiveState Python 2.7

I have a gui built using matlab. I wrote the following python script
to open that matlab gui using pymatlab python module:

from pymatlab.matlab import MatlabSession

session = MatlabSession()
session.run('cd ~/ratter/ExperPort')
session.run('addpath(genpath(pwd))')
session.run('run Utility/WaterMeister/WaterMeister.m')

In the above python code, WaterMesiter.m is the matlab gui script. If
I run this in matlab shell, it opens the gui fine and I do whatever I
need to do with the gui and then close it. Now, instead, if I run the
above python script, everything goes fine but the GUI is closed
immediately as soon as it is opened, and the control is returned back
to python shell. I don't want this to happen. I want the GUI to stay
opened and I want the control to return back to python only when I
close the matlab GUI.

Any thoughts/suggestions will be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Button Label change on EVT_BUTTON in wxpython!!!

2011-08-28 Thread Ven
Some system info before proceeding further:

Platform: Mac OS X 10.7.1
Python Version: ActiveState Python 2.7.1
wxPython Version: [url=http://downloads.sourceforge.net/wxpython/
wxPython2.9-osx-2.9.2.1-cocoa-py2.7.dmg]wxPython2.9-osx-cocoa-py2.7[/
url]

I want the button label to be changed while performing a task

So, here is what I did/want:

self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install')
self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)

def OnRun(self,evt):
self.run_button.SetLabel('Installing..')
#call a function that does the installation task
installation_task()
#After task completion, set the button label back to "Install"
self.run_button.SetLabel('Install')

When I try doing this, it doesn't set the label to "Installing" while
the task is being performed. Any suggestions how do I achieve this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Item Checking not possible with UltimateListCtrl in ULC_VIRTUAL mode

2011-12-22 Thread Ven
Following is the system and software info

Platforms: Windows XP and OSX Lion
Activestate Python 2.7.2
wxPython2.9-osx-cocoa-py2.7 (for OSX)
wxPython2.9-win32-py27 (for Windows XP)

I am trying to create a UltimateListCtrl using ULC_VIRTUAL and
ULC_REPORT mode. I would like to know how can I put a checkbox beside
the first column of every row and catch the event when a user checks
the box. I was able to do the same using UltimateListCtrl without
VIRTUAL mode. But, with the ULC_VIRTUAL flag ON, I don't know how to
proceed. Following is the code I created, but this still doesn't allow
me to check the boxes associated with the first column. Please help.

import wx
import images
import random
import os, sys
from wx.lib.agw import ultimatelistctrl as ULC

class TestUltimateListCtrl(ULC.UltimateListCtrl):
def __init__(self, parent, log):

ULC.UltimateListCtrl.__init__(self, parent, -1,
agwStyle=ULC.ULC_AUTO_CHECK_CHILD|ULC.ULC_VIRTUAL|ULC.ULC_REPORT|
ULC.ULC_SINGLE_SEL|ULC.ULC_VRULES|ULC.ULC_HRULES)
self.SetItemCount(1000)
self.table_fields=['First','Second','Third']
field_index=0
for field in self.table_fields:
info = ULC.UltimateListItem()
info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE |
wx.LIST_MASK_FORMAT | ULC.ULC_MASK_CHECK
info._image = []
info._format = wx.LIST_FORMAT_CENTER
info._kind = 1
info._text = field
info._font= wx.Font(13, wx.ROMAN, wx.NORMAL, wx.BOLD)
self.InsertColumnInfo(field_index, info)
self.SetColumnWidth(field_index,175)
field_index += 1

def getColumnText(self, index, col):
item = self.GetItem(index, col)
return item.GetText()

def OnGetItemText(self, item, col):
return "Item %d, Column %d" % (item,col)

def OnGetItemColumnImage(self, item, col):
return []

def OnGetItemImage(self, item):
return []

def OnGetItemAttr(self, item):
return None

def OnGetItemTextColour(self, item, col):
return None

#def OnGetItemColumnCheck(self, item, col):
#return True

#def OnGetItemCheck(self, item):
#item=self.GetItem(item)
#return item.IsChecked()

def OnGetItemToolTip(self, item, col):
return None

def OnGetItemKind(self, item):
return 1

def OnGetItemColumnKind(self, item, col):
if col==0:
return self.OnGetItemKind(item)
return 0

class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "UltimateListCtrl in
wx.LC_VIRTUAL mode", size=(700, 600))
panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
listCtrl = TestUltimateListCtrl(panel, log)
sizer.Add(listCtrl, 1, wx.EXPAND)
panel.SetSizer(sizer)
sizer.Layout()
self.CenterOnScreen()
self.Show()

if __name__ == '__main__':
import sys
app = wx.PySimpleApp()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
app.MainLoop()

Btw, following is the code I used to create the same thing without the
VIRTUAL mode. And in this case, I can check the boxes beside the first
column data in every row. But, I will be working with tens of
thousands of items and I cannot rely on loading the items like below
because it is very slow. Hence, I want to use the Virtual List, but I
don't know how to get the same functionality in it.

import wx
import images
import random
import os, sys
from wx.lib.agw import ultimatelistctrl as ULC

class TestUltimateListCtrl(ULC.UltimateListCtrl):
def __init__(self, parent, log):

ULC.UltimateListCtrl.__init__(self, parent, -1,
agwStyle=ULC.ULC_REPORT|ULC.ULC_SINGLE_SEL|ULC.ULC_VRULES|
ULC.ULC_HRULES)

self.table_fields=['First','Second','Third']
field_index=0
for field in self.table_fields:
info = ULC.UltimateListItem()
info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE |
wx.LIST_MASK_FORMAT | ULC.ULC_MASK_CHECK
info._image = []
info._format = wx.LIST_FORMAT_CENTER
info._kind = 1
info._text = field
info._font= wx.Font(13, wx.ROMAN, wx.NORMAL, wx.BOLD)
self.InsertColumnInfo(field_index, info)
self.SetColumnWidth(field_index,175)
field_index += 1

for record_index in range(0,1000):
for field in self.table_fields:
if self.table_fields.index(field)==0:
self.InsertStringItem(record_index, 'Item %d, Column %d' %
(record_index,self.table_fields.index(field)),it_kind=1)
else:
self.SetStringItem(record_index, 
self.table_fields.index(field),
'Item %d, Column %d' % (record_index,self.table_fields.index(field)))

class TestFrame(wx.Frame):
def __init__(self, parent, log):
wx.Frame.__init__(self, parent, -1, "UltimateListC

Re: Freesoftware for auto/intelligent code completing in Python

2008-07-02 Thread Ivan Ven Osdel
The free Python editors/IDEs really do need work as far as code completion goes 
but I am hopeful. 

IMO Stani's Python Editor comes closest by providing some code sense through a 
combination of history and doc strings for Python built-ins. Where it falls 
short is the ability to scan doc strings for your own code and non built-in 
modules in the Python path. Python already has the ground work in place to 
accomplish something similar to VS's XML commenting/intellisense system. With a 
Python interpretor you can type help(myModule) and get the doc string 
documentation. So I imagine implementing code sense for code being developed as 
well as non built-in modules would just be a matter of finding the appropriate 
module at the right time and piping the output of help([module]) to a popup 
window.

If your willing to help work on something like that I suggest contacting Stani 
directly http://pythonide.stani.be/ or creating a plugin for Geany 
http://geany.uvena.de/

Ivan Ven Osdel
Software Engineer
http://www.datasyncsuite.com/

- Original Message -
From: "Ali Servet Dönmez" <[EMAIL PROTECTED]>
To: python-list@python.org
Sent: Wednesday, July 2, 2008 3:33:59 AM GMT -06:00 US/Canada Central
Subject: Re: Freesoftware for auto/intelligent code completing in Python

On Jul 1, 12:15 am, Fuzzyman <[EMAIL PROTECTED]> wrote:
> On Jun 30, 10:46 pm, Ali Servet Dönmez <[EMAIL PROTECTED]> wrote:
>
>
>
> > I don't want to be so mean here, but how hard it could be be writing a
> > freesoftware which would automatically/intelligently auto complete
> > Python code? (I mean something that really does the job, like
> > Microsoft's Visual Studio or Sun's NetBeans or something else, you
> > name it, but just don't give me PyDev please...)
>
> > This could be an extension, a plugin, an Emacs mode, a new editor or
> > even a brand new huge all-fancy IDE, I don't care, but what am I
> > missing here?
>
> > Could someone please point me out something that I'm really missing
> > which is already present in the wild, otherwise I'd like discuss with
> > whoever is willing to help me to get this thing done. I made my mind
> > and I could volunteer to make this happen as thesis project for my
> > incoming graduation in the next year.
>
> > Regards you all,
> > Ali Servet Dönmez
>
> Vim, Emacs, Wing, Komodo, ... more?
>
> Yeah, I guess you're missing something. :-)
>
> Michael Foordhttp://www.ironpythoninaction.com/http://www.trypython.org/

I've checkout Wing IDE's license and it doesnt' seem to be a
freesoftware; am I wrong?

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

Re: Freesoftware for auto/intelligent code completing in Python

2008-07-02 Thread Ivan Ven Osdel
Not really, I have just worked with them more.

- Original Message -
From: "Ali Servet Dönmez" <[EMAIL PROTECTED]>
To: python-list@python.org
Sent: Wednesday, July 2, 2008 1:15:04 PM GMT -06:00 US/Canada Central
Subject: Re: Freesoftware for auto/intelligent code completing in Python

On Jul 2, 7:55 pm, Ivan Ven Osdel <[EMAIL PROTECTED]> wrote:
> The free Python editors/IDEs really do need work as far as code completion 
> goes but I am hopeful.
>
> IMO Stani's Python Editor comes closest by providing some code sense through 
> a combination of history and doc strings for Python built-ins. Where it falls 
> short is the ability to scan doc strings for your own code and non built-in 
> modules in the Python path. Python already has the ground work in place to 
> accomplish something similar to VS's XML commenting/intellisense system. With 
> a Python interpretor you can type help(myModule) and get the doc string 
> documentation. So I imagine implementing code sense for code being developed 
> as well as non built-in modules would just be a matter of finding the 
> appropriate module at the right time and piping the output of help([module]) 
> to a popup window.
>
> If your willing to help work on something like that I suggest contacting 
> Stani directlyhttp://pythonide.stani.be/or creating a plugin for 
> Geanyhttp://geany.uvena.de/
>
> Ivan Ven Osdel
> Software Engineerhttp://www.datasyncsuite.com/
>
> - Original Message -
> From: "Ali Servet Dönmez" <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Sent: Wednesday, July 2, 2008 3:33:59 AM GMT -06:00 US/Canada Central
> Subject: Re: Freesoftware for auto/intelligent code completing in Python
>
> On Jul 1, 12:15 am, Fuzzyman <[EMAIL PROTECTED]> wrote:
> > On Jun 30, 10:46 pm, Ali Servet Dönmez <[EMAIL PROTECTED]> wrote:
>
> > > I don't want to be so mean here, but how hard it could be be writing a
> > > freesoftware which would automatically/intelligently auto complete
> > > Python code? (I mean something that really does the job, like
> > > Microsoft's Visual Studio or Sun's NetBeans or something else, you
> > > name it, but just don't give me PyDev please...)
>
> > > This could be an extension, a plugin, an Emacs mode, a new editor or
> > > even a brand new huge all-fancy IDE, I don't care, but what am I
> > > missing here?
>
> > > Could someone please point me out something that I'm really missing
> > > which is already present in the wild, otherwise I'd like discuss with
> > > whoever is willing to help me to get this thing done. I made my mind
> > > and I could volunteer to make this happen as thesis project for my
> > > incoming graduation in the next year.
>
> > > Regards you all,
> > > Ali Servet Dönmez
>
> > Vim, Emacs, Wing, Komodo, ... more?
>
> > Yeah, I guess you're missing something. :-)
>
> > Michael Foordhttp://www.ironpythoninaction.com/http://www.trypython.org/
>
> I've checkout Wing IDE's license and it doesnt' seem to be a
> freesoftware; am I wrong?
>
>

Ivan, thanks for your reply. I am curious how come you're suggesting
me those two, but not others. Is there a good/particular reason for
that?

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

Re: Freesoftware for auto/intelligent code completing in Python

2008-07-03 Thread Ivan Ven Osdel

>From: "Fuzzyman" <[EMAIL PROTECTED]>
>To: python-list@python.org
>Sent: Thursday, July 3, 2008 12:41:11 PM GMT -06:00 US/Canada Central
>Subject: Re: Freesoftware for auto/intelligent code completing in Python
>
>On Jul 2, 9:33 am, Ali Servet Dönmez <[EMAIL PROTECTED]> wrote:
> On Jul 1, 12:15 am, Fuzzyman <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jun 30, 10:46 pm, Ali Servet Dönmez <[EMAIL PROTECTED]> wrote:
>
> > > I don't want to be so mean here, but how hard it could be be writing a
> > > freesoftware which would automatically/intelligently auto complete
> > > Python code? (I mean something that really does the job, like
> > > Microsoft's Visual Studio or Sun's NetBeans or something else, you
> > > name it, but just don't give me PyDev please...)
>
> > > This could be an extension, a plugin, an Emacs mode, a new editor or
> > > even a brand new huge all-fancy IDE, I don't care, but what am I
> > > missing here?
>
> > > Could someone please point me out something that I'm really missing
> > > which is already present in the wild, otherwise I'd like discuss with
> > > whoever is willing to help me to get this thing done. I made my mind
> > > and I could volunteer to make this happen as thesis project for my
> > > incoming graduation in the next year.
>
> > > Regards you all,
> > > Ali Servet Dönmez
>
> > Vim, Emacs, Wing, Komodo, ... more?
>
> > Yeah, I guess you're missing something. :-)
>
> > MichaelFoordhttp://www.ironpythoninaction.com/http://www.trypython.org/
>
> I've checkout Wing IDE's license and it doesnt' seem to be a
> freesoftware; am I wrong?
>
>
>Wing 101 is free. The software is good enough though that it is worth
>supporting its development by paying for it.
>
>Michael Foord
>--
>http://www.ironpythoninaction.com/
>http://www.trypython.org/


According to the site, Wings 101 doesn't support "Auto-completion for Python 
and extension modules" but I agree that Wings is worth it if he (or his 
company) can afford the license(s). 

If not then he should at least contribute time or money to one of the free (as 
in free speech, not free beer) alternatives.

Ivan Ven Osdel

http://www.datasyncsuite.com/

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

Re: Freesoftware for auto/intelligent code completing in Python

2008-07-07 Thread Ivan Ven Osdel
>- Original Message - 
>From: "Python Nutter" <[EMAIL PROTECTED]> 
>To: "Ivan Ven Osdel" <[EMAIL PROTECTED]> 
>Cc: python-list@python.org 
>Sent: Thursday, July 3, 2008 5:56:32 PM GMT -06:00 US/Canada Central 
>Subject: Re: Freesoftware for auto/intelligent code completing in Python 
>
>If you guys can get your head out of IDE land, you'll find iPython 
>does a fantastic job at introspection and Auto-completion, you can 
>launch shell commands and editors and when done saving be back in the 
>iPython shell, save memory/variable space to disk so you can come back 
>the next day and continue off where you were. It puts IDEs to shame. 
>
>If you can't get your Windows-centric IDE need eliminated, then Wing 
>IDE 101 will not auto-complete, its been deliberately disabled to 
>force students (hence 101) to memorize python/function names. 
>
>Komodo Edit is a free download and will Auto-complete. 

>Cheers, 
>PN 



Thanks for the suggestion. I'll take a look at iPython today.

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


Re: Using Python To Launch Python

2008-07-14 Thread Ivan Ven Osdel
>Hello All,
>  I have a situation where I can count on a Python installation being
>available on a system, but I can't count on it being a version of
>Python needed by my application.  Since my application has it's own
>version of Python installed with it how should I use the system Python
>to launch the version of Python that launches my Application.  Yes,
>this is a convoluted process, but not all Pythons are built the
>same :)
>
>Right now I am leaning towards using exec to start a new process, but
>I thought I would check to see if anyone else has had the need to
>perform a task similar to this one.

>AHA

Simplest case:

>>> import os
>>> os.system("/path/to/your/python app.py")

Obviously things can be shortened by adding to the PATH.

Ivan Ven Osdel
Software Engineer
http://datasyncsuite.com

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


Re: Framework recommendations for web service?

2008-07-16 Thread Ivan Ven Osdel
>What we *do* need is a lightweight, simple framework that will allow
>us to create a RESTful interface and throw code together fast. We'll
>probably go with SQLObject (unless we can extract the ORM from django
>- lazy evaluation would be very useful), and we're just looking for
>something fast and light to sit between that and the thrift interfaces
>we'll create.
>
>So, can anyone suggest a lightweight python framework which just does
>the essentials?

Have you looked at CherryPy? It's very simple to get up and running and can be 
changed to go through Apache if you need it to be fast. 

I don't think RESTful interfaces are built in but I know people have 
succesfully built RESTful apps on top of CherryPy. Also plans for REST in 
CherryPy 3 look promising. Here is a post I ran across from one of the 
contributers.

"Hey there,

CherryPy 3 is currently under brainstorming before being first draft. There 
some feature we do want such as the ability to change the URL dispatching at 
will depending on what is required for a given application.

One dispatching rule I do want is the one based on HTTP verbs. So it might take 
a few months to get there but eventually it will be a built-in :)

- Sylvain"


-- 
Ivan Ven Osdel
Senior Software Engineer
http://datasyncsuite.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Framework recommendations for web service?

2008-07-16 Thread Ivan Ven Osdel
>I don't think RESTful interfaces are built in but I know people have 
>succesfully built RESTful apps on top of CherryPy. Also plans >for REST in 
>CherryPy 3 look promising. Here is a post I ran across from one of the 
>contributers.

>"Hey there,

>CherryPy 3 is currently under brainstorming before being first draft. There 
>some feature we do want such as the ability to change >the URL dispatching at 
>will depending on what is required for a given application.
>
>One dispatching rule I do want is the one based on HTTP verbs. So it might 
>take a few months to get there but eventually it will be >a built-in :)
>
>- Sylvain"

My apologies, it appears that post was from 2006!

-- 
Ivan Ven Osdel
Senior Software Engineer
http://datasyncsuite.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Agnostic fetching

2008-08-04 Thread Ivan Ven Osdel
>- Original Message -
>From: "Diez B. Roggisch" <[EMAIL PROTECTED]>
>To: python-list@python.org
>Sent: Saturday, August 2, 2008 11:05:07 AM GMT -06:00 US/Canada Central
>Subject: Re: Agnostic fetching

>Bruce Frederiksen schrieb:
> On Fri, 01 Aug 2008 17:05:00 -0700, jorpheus wrote:
> 
>> OK, that sounds stupid. Anyway, I've been learning Python for some
>> time now, and am currently having fun with the urllib and urllib2
>> modules, but have run into a problem(?) - is there any way to fetch
>> (urllib.retrieve) files from a server without knowing the filenames?
>> For instance, there is smth like folder/spam.egg, folder/
>> unpredictable.egg and so on. If not, perhaps some kind of glob to
>> create a list of existing files? I'd really appreciate some help,
>> since I'm really out of my (newb) depth here.
> 
> You might try the os.path module and/or the glob module in the standard
> python library.

>Not on remote locations. The only work on your local filesystem.

>Diez

Here's a function I wrote for checking remote or local file existence. It works 
for me but admittedly I haven't tested many cases with it. Also its currently 
specific to an http URI scheme.

def fileExists(self, fileUrlPath):
fileExists = False
if "http:" in fileUrlPath.lower():
#We don't want to open the file so ask the header if the
#file exists
urlParts = urlparse(fileUrlPath)
host = urlParts[1]
http = httplib.HTTP(host)
http.putrequest("HEAD", fileUrlPath)
http.putheader("Host", host)
http.endheaders()
errorcode, errormessage, headers = http.getreply()
if errorcode == 200:
fileExists = True
else:
fileExists = path.exists(fileUrlPath)

return fileExists

-- 
Ivan Ven Osdel
http://datasyncsuite.com
--
http://mail.python.org/mailman/listinfo/python-list