Re: classes on GladeGen
On Aug 16, 2006, at 8:05 AM, Rafal Janas wrote: > Hi. > > I create simple program using glade and GladeGen. > In main.py is main class and in wind.py is wind class. > In main class is entry1 and button1. When I click on button1 I open > wind > class wind.Wind() > In wind class is entry1 field when I type some values and how can I > send > this value to main class. > When I type main.Main().widgets['entry1'].set_text("something") it > open > new class but I want do it in window which is open > How to do it? I assume you're referring to GladeGen that was in Linux Journal (July 2004 I think) - I'm the person who wrote it. main.Main() creates a new instance of the class, but you want to use the existing instance. A simple way around this is to pass the instance of the main class to the wind class when you create it. Assuming you're in a method of the main class when you create it do something like: self.wind = wind(self) and then your wind constructor includes: def __init__(self, main): self.main = main and then in your wind method that you want to set the text entry, you write: self.main.widgets['entry1].set_text('something') HTH, Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an elegant way to dir() module from inside?
On Aug 24, 2006, at 10:18 AM, volcano wrote: > I am looking for a way to discover which classes a module contains > from > "inside". I am building a testing class that should, when > instatntiated > within any module, locate certain classes within the containing > module. > Words of wisdom? Anybody? Check out the inspect module. http://docs.python.org/lib/module-inspect.html Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Read from .glade
On Wednesday, September 06, 2006, at 10:36AM, <[EMAIL PROTECTED]> wrote: >Hello, > >I've got the following problem: I've got a Userinterface that is made >in Glade, so i've got a >.glade file. What I want is to get the id's of every widget from the >class GtkEntry from a given window. > >The glade file is like > > >"http://glade.gnome.org/glade-2.0.dtd";> > > > > >Kind regards, > >Ralf Brand > You want to use one of the XML processing libraries. The simplest (and should be fine for this use) is dom. Here is some code I wrote as part of GladeGen - see http://www.linuxjournal.com/article/7421 that you should be able to easily extract the piece you need: doc = xml.dom.minidom.parse(self.glade_file) # look for widgets and get their widget type and name for node in doc.getElementsByTagName('widget'): widget = str(node.getAttribute('class')) name = str(node.getAttribute('id')) if self.top_window is None and widget == 'GtkWindow': self.top_window = name # if the widget type is in list of widgets user specified # in config file, include it in the list if widget in GladeGenConfig.include_widget_types: # (widget type, name) # ('GtkWindow', 'window1') self.widgets.append((widget, name)) HTH, Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple but fast 2D lib for drawing pixels
On Oct 1, 2006, at 6:28 PM, Peter Mexbacher wrote: > Hello, > > we want to teach absolute programming newbies > a first language, so they can start programming > simple scientific models. > > We thought Python would make a good choice for > a first language; but where pretty stumped when > we found out that there is no simple way to draw > pixels to a screen. (This is needed for fractals, > agent-based models etc -> like Conways Game of Life) > > Our requirements: > > -) easy to learn (newbs!) > -) not too slow (after all, the models should simulate something) > -) python :-) > > Any ideas? > > Best Regards, > Peter You might check out John Zelle's Python book - he uses a simple graphics library on top of Tk (which Python comes with). You can find information on his book and the graphics.py file he uses at: http://mcsp.wartburg.edu/zelle/python/ It certainly meets your easy to learn and Python requirements - and of course speed is subjective so it may or may not be fast enough for you. Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: running python scripts via crontab
On Jun 9, 2007, at 9:10 AM, Mr SZ wrote: > Hello all, > I wrote a simple python script to send mail via smtp to my gmail > acc.I can run it as python /home/phil/Desktop/smtp.py but when I > add the same to my crontab as > > * * * * * /usr/bin/python2.5 /home/phil/Desktop/smtp.py > > ,it doesn't run.I checked the process by using top command and > python did start a thread but died soon. > > I need some help here. > > The python script uses tls-lite lib to use tls over smtp. > One possible issue is that I believe the crontab entries to not run with the same environment that your normal user login does. If you set any environment variables in your .bashrc or .bash_profile file, try including those lines at the top of your crontab file. Here's the first line in my crontab file (this is on OS X, but the issue is likely the same on Linux). PATH=/opt/local/bin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/ usr/X11R6/bin:/Users/dreed/bin And are you really wanting to run the script every single minute (or is that just for testing)? Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Why isn't this query working in python?
On May 27, 2007, at 4:01 PM, Steve Holden wrote: > erikcw wrote: >> On May 26, 8:21 pm, John Machin <[EMAIL PROTECTED]> wrote: >>> On May 27, 5:25 am, erikcw <[EMAIL PROTECTED]> wrote: >>> >>> >>> On May 25, 11:28 am, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-05-25 at 09:51 -0500, Dave Borne wrote: >>> I'm trying to run the following query: >> ... >>> member_id=%s AND expire_date > NOW() AND completed=1 AND >>> (product_id >> Shouldn't you be using the bind variable '?' instead of '%s' ? > The parameter placeholder for MySQLdb is, indeed and > unfortunately, %s. > The OP is using parameter substitution correctly, though in an > obfuscated fashion. 'sql' is a misnamed tuple containing both > the query > string *and* the parameters, which is being unpacked with '*' > into two > arguments to the execute call. > The only problem I see is that the parameters should be a > sequence, i.e. > (self.uid,) instead of just (self.uid). > HTH, > -- > Carsten Haesehttp://informixdb.sourceforge.net I tried adding the comma to make it a sequence - but now change. ('SELECT payment_id FROM amember_payments WHERE member_id=%s AND expire_date > NOW() AND completed=1 AND (product_id >11 AND product_id <21)', (1608L,)) () What else could it be? >>> Possibly a type mismatch. How is member_id declared in the CREATE >>> TABLE? For diagnostic purposes, try passing in (1608,) and >>> ('1608',). >> >> Here is a copy of the table schema and the first 2 rows. >> >> -- phpMyAdmin SQL Dump >> -- version 2.9.0.2 >> -- http://www.phpmyadmin.net >> -- >> -- Host: localhost >> -- Generation Time: May 27, 2007 at 11:29 AM >> -- Server version: 5.0.27 >> -- PHP Version: 4.4.2 >> -- >> -- Database: `lybp_lybp` >> -- >> >> -- >> >> -- >> -- Table structure for table `amember_payments` >> -- >> >> CREATE TABLE `amember_payments` ( >> `payment_id` int(11) NOT NULL auto_increment, >> `member_id` int(11) NOT NULL default '0', >> `product_id` int(11) NOT NULL default '0', >> `begin_date` date NOT NULL default '-00-00', >> `expire_date` date NOT NULL default '-00-00', >> `paysys_id` varchar(32) NOT NULL default '', >> `receipt_id` varchar(32) NOT NULL default '', >> `amount` decimal(12,2) NOT NULL default '0.00', >> `completed` smallint(6) default '0', >> `remote_addr` varchar(15) NOT NULL default '', >> `data` text, >> `time` timestamp NOT NULL default CURRENT_TIMESTAMP on update >> CURRENT_TIMESTAMP, >> `aff_id` int(11) NOT NULL default '0', >> `payer_id` varchar(255) NOT NULL default '', >> `coupon_id` int(11) NOT NULL default '0', >> `tm_added` datetime NOT NULL default '-00-00 00:00:00', >> `tm_completed` datetime default NULL, >> `tax_amount` decimal(12,2) NOT NULL default '0.00', >> PRIMARY KEY (`payment_id`), >> KEY `member_id` (`member_id`), >> KEY `payer_id` (`payer_id`), >> KEY `coupon_id` (`coupon_id`), >> KEY `tm_added` (`tm_added`,`product_id`), >> KEY `tm_completed` (`tm_completed`,`product_id`) >> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11020 ; >> >> -- >> -- Dumping data for table `amember_payments` >> -- >> >> INSERT INTO `amember_payments` VALUES (423, 107, 1, '2004-10-01', >> '2004-10-21', 'authorize_aim', '5687944', 3.95, 1, '', NULL, >> '2004-11-30 19:21:43', 0, '', 0, '2004-11-30 19:21:43', '2004-11-30 >> 19:21:43', 0.00); >> INSERT INTO `amember_payments` VALUES (422, 107, 1, '2004-10-22', >> '2004-11-21', 'authorize_aim', '5873225', 9.95, 1, '', NULL, >> '2004-11-30 19:22:18', 0, '', 0, '2004-11-30 19:20:13', '2004-11-30 >> 19:20:13', 0.00); >> >> Thanks for your help! >> Erik >> > I feel obliged to point out that there ARE no rows meeting the > criteria > you query specified! > > mysql> SELECT expire_date, NOW() FROM amember_payments; > +-+-+ > | expire_date | NOW() | > +-+-+ > | 2004-10-21 | 2007-05-27 15:59:21 | > | 2004-11-21 | 2007-05-27 15:59:21 | > +-+-+ > 2 rows in set (0.02 sec) > > mysql> > > So I am not sure how you managed to get a manual query to work, but do > be sure that the Python query you mentioned at the start of the thread > > sql = """SELECT payment_id FROM amember_payments WHERE > member_id=%s AND expire_date > NOW() AND completed=1 AND (product_id >>> 11 AND product_id <21)""", (self.uid) > And doesn't the above comma, need to be a percent symbol? Dave > doesn't stand a chance of returning any results unless you use a time > machine to go back almost three years! > > regards > Steve -- http://mail.python.org/mailman/listinfo/python-list
convert time string in UTC to time in local time
I'm guessing there is an easy way to do this but I keep going around in circles in the documentation. I have a time stamp that looks like this (corresponding to UTC time): start_time = '2007-03-13T15:00:00Z' I want to convert it to my local time. start_time = time.mktime(time.strptime(start_time, '%Y-%m-%dT%H:%M: 00Z')) start_time -= time.timezone This was working fine now, but if I do it for a date next week (such as March 13th in the above example), it breaks because my local time moves to daylight savings time this weekend. So my time is now off by an hour. I'm guessing if I try this next week it will work okay because time.timezone will be give a different value next week - is that correct? Is there a direct way to convert that timestamp in UTC to a local time stamp that will always work? TIA, Dave -- http://mail.python.org/mailman/listinfo/python-list