Python + Shoutpy + Twisted Locks
Unfortunately I don't have the code at hand on this box, but maybe someone can give me a nudge in the right direction. Some background: Last year I began to write a jukebox system that provided a Telnet-like interface. I wrote this using socket. Later along the path I discovered Twisted, and due to various other problems, a re-write made sense. So I decided to use Twisted. The only thing I adapted was the class providing the telnet interface. In the background I use a few other threads. One for metadata-scanning, one for assuring continuous playback (periodic checks the player status and appends songs if necessary) and in the case the shoutcast backend is activated, there is also a built-in player thread. I remember having it running already, but I don't remember if it was before I started to use Twisted or after. Well, I beleive the problem lies withing the last named thread. This one uses shoutpy to stream data to the shoutcast server. What I found is that libshout is blocking, which should be fine as the whole thing runs in it's separate thread. But the application hangs nevertheless while streaming. This effectively blocks out the other thread that checks the player status, which then fails to append new songs to the queue. So only one song is played when streaming. I saw that there is another package called python-shout. But neither that nor shoutpy have any comprehensive documentation which might tell me anything about the libshout blocking problem. The documentation of libshout revealed a non-blocking mode, but even though I made the necessary adjustments to the code, I still had the same problem. The other threads in my application run fine and don't block the rest of the app. So I guess, that the main problem is that blocking occurs outside the python world and inside the libshout world. Maybe the combination of all this with Twisted is an unlucky marriage but I would be disappointed to be told: Nope, won't be possible Maybe Twisted's deferreds to the rescue? I don't know... I'm still quite green with Twisted ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Where's the Starship's crew?
On Oct 5, 10:31 am, Dick Moores [EMAIL PROTECTED] wrote: http://starship.python.net/crew/index.html I didn't check on all of them, but the only one I found was Mark Hammond http://starship.python.net/crew/mhammond/. Dick Moores Doing 6 random clicks, revealed: http://starship.python.net/crew/hooft/ all the others are dead links. I realised this fact as well some time ago already. I thought the page itself was still in development and did not find a single one page. These two obviously eluded me ;) Strange to see that the situation did not yet improve. But then again, we all probably know how much of a hassle it is to keep 10 different web-pages with personal info's up-to-date. I suppose that the starship crew all have som homes elsewhere and don't find the time to update yet another page. I myself don't even bother anymore at all. I have about 2 hours of free time per day (given that I like to sleep a lot!). What makes things worse, the network at work is completely cut off from the rest of the world for security reasons. I am happy that I at least can access usenet by using google-groups *sigh*. An interesting task might be to find the homes of the starship crew, and post them here? Maybe? If lucky, the right person picks this up and updates the crew-quarter labels of the starship. Or would Turbolift Buttons be a better analogy for hyperlinks? Args. Supposing, that these turbolifts *do* have buttons. How retro! ;) I'm babbling again... sorry for this long winded post. -- http://mail.python.org/mailman/listinfo/python-list
Re: Clustering text-documents in bundles
On Sep 25, 7:52 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: exhuma.twn [EMAIL PROTECTED] writes: Is it possible to calculate a distance between two chunks of text? I suppose one could simply do a simple word-count on the chunks (removing common noise words of course). And then go from there. Maybe even assigning different weighting to words. But maybe there is a well- tested and useful algorithm already available? There's a huge field of text mining that attempts to do things like this. http://en.wikipedia.org/wiki/Latent_semantic_analysisfor some info about one approach. Manning Schutz's book Foundations of Statistical Natural Language Processing (http://nlp.stanford.edu/fsnlp/) is a standard reference about text processing. They also have a new one about information retrieval (downloadable as a pdf) that looks very good: http://informationretrieval.org. Thanks a lot. This gives me some bed-time reading. -- http://mail.python.org/mailman/listinfo/python-list
Clustering text-documents in bundles
Hi, This *is* off-topic but with python being a language with a somewhat scientific audience, I might get lucky ;) I have a set of documents (helpdesk tickets in fact) and I would like to automatically collect them in bundles so I can visualise some statistics depending on content. A while ago I wrote a very simple clustering library which can cluster about everything where you can calculate some form of distance. Meaning: You can supply a function that calculates numeric value given two objects (helpdesk request text-body in this case). The closer the two objects are related, the smaller the returned value with 0.0 meaning that the two objects are identical. Is it possible to calculate a distance between two chunks of text? I suppose one could simply do a simple word-count on the chunks (removing common noise words of course). And then go from there. Maybe even assigning different weighting to words. But maybe there is a well- tested and useful algorithm already available? Text processing is a very blurry area for me. I don't expect any solutions for the problem right away. Maybe just some pointers as to *what* I can google for. I'll pick the rest up from there. Eventually I would like to have the possibility to say: This set of texts contains 20 requests dealing with emails, 30 requests dealing with Office Applications and 210 requests dealing with databases. I am aware that labelling the different text-bundles will have to be done manually I suppose. But I will aim for no more than 10 bundles anyway. So that's OK. -- http://mail.python.org/mailman/listinfo/python-list
(pyqt) Parameters when connecting a signal to a method?
Some code: -- def foobar(w): print w QtCore.QObject,connect( my_line_edit, QtCore.SIGNAL(returnPressed()), foobar ) -- How can I get this to work so foobar prints out the sender of the signal (i.e. my_line_edit)? -- http://mail.python.org/mailman/listinfo/python-list
Re: (pyqt) Parameters when connecting a signal to a method?
On Sep 24, 4:47 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: exhuma.twn wrote: Some code: -- def foobar(w): print w QtCore.QObject,connect( my_line_edit, QtCore.SIGNAL(returnPressed()), foobar ) -- How can I get this to work so foobar prints out the sender of the signal (i.e. my_line_edit)? I _think_ there is a way to get the signals sender in Qt itself. But I'm unsure how to get that. Alternatively, you can use a closure to create a reference: def foobar(source, w): print w def slotgen(source, slot): def _slot(*args): return slot(*((source,) + args)) return _slot my_slot = slotgen(my_line_edit, foobar) QtCore.QObject,connect( my_line_edit, QtCore.SIGNAL(returnPressed()), my_slot ) However, be careful to keep a reference to my_slot around! Otherwise, it will be garbage collected! diez Thanks diez. This works :) Although, I still have to digest *what* this closure does, but I will leave this as an exercise to myself. ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python to create windows apps that everyone can use?
On Sep 19, 9:46 pm, Simon Hibbs [EMAIL PROTECTED] wrote: On 9/18/07, Thomas Harding [EMAIL PROTECTED] wrote: Hi guys, sorry to post another topic on this, as I am aware that it has already been posted a few times, but not with specifically what I am looking for. I want an app that makes a gui interface for python (similar to Microsoft visual studio or qt designer, not a code based one) and/ or an app that can make this into a .exe that can be opened by any person on any computer without python installed. For windows only, there's always Iron Python. This allows you to use Visual Studio, the commercial or the express version, to create the GUI in VB or C# and from that call Python code that does all the heavy lifting. Any pointers to that. I might have to get started soon with Visual Studio, as our company *might* move to an all-windows development environment *sigh* /me still hopes that I can convince them that 1) developing on Linux is at all not too shabby, and that 2) Python is a great Language! ;) So far I am making good progress on point 2. :) I'd second the recommendation for QtDesigner if you want cross- platform capability. Simon Hibbs -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python to create windows apps that everyone can use?
On Sep 18, 9:22 pm, Matt McCredie [EMAIL PROTECTED] wrote: On 9/18/07, Thomas Harding [EMAIL PROTECTED] wrote: Hi guys, sorry to post another topic on this, as I am aware that it has already been posted a few times, but not with specifically what I am looking for. I want an app that makes a gui interface for python (similar to Microsoft visual studio or qt designer, not a code based one) and/or an app that can make this into a .exe that can be opened by any person on any computer without python installed. check out py2exe:http://py2exe.org matt I am currently building an application with Python using Qt4.3 as widget-toolkit. So I can use designer too ;) Links that might be of interest to you: - http://www.riverbankcomputing.co.uk/pyqt/ - http://www.py2exe.org/index.cgi/Py2exeAndPyQt This works quite well. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tutorial or Example (or Tutorial) of Using Canvas to Produce a Plot
On Sep 18, 11:58 pm, Richard Townsend [EMAIL PROTECTED] wrote: On Tue, 18 Sep 2007 13:18:36 -0700, W. Watson [EMAIL PROTECTED] wrote: Tk is it. I'm really not interested in the others at this point. John Grayson's book 'Python and Tkinter Programming' has a chapter on plotting Graphs and Charts. You can even download that chapter as a PDF file: http://www.manning-source.com/books/grayson/grayson_ch11.pdf Seehttp://www.manning.com/grayson/for more info about the book. Also, if the graph is really all you need, matplotlib might be a very interesting choice: http://matplotlib.sourceforge.net/ It's got some user-interface facilities as well. But I never used those so far. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using python to create windows apps that everyone can use?
On Sep 18, 9:22 pm, Matt McCredie [EMAIL PROTECTED] wrote: On 9/18/07, Thomas Harding [EMAIL PROTECTED] wrote: Hi guys, sorry to post another topic on this, as I am aware that it has already been posted a few times, but not with specifically what I am looking for. I want an app that makes a gui interface for python (similar to Microsoft visual studio or qt designer, not a code based one) and/or an app that can make this into a .exe that can be opened by any person on any computer without python installed. check out py2exe:http://py2exe.org matt Oh... I forgot. With newer versions of Qt, you have to adapt the setup script a bit. Here's an example (even with an icon-resource ) ;) setup(windows=['ide.py'], options={py2exe:{ includes:[sip, PyQt4._qt], icon_resources:[(1,gnucash.ico)]}}) The trick here, is to also add PyQt4._qt to the includes. -- http://mail.python.org/mailman/listinfo/python-list
Keeping a database connection with a Singleton?
I remember reading about the Singleton pattern in python and how it's an unpythonic pattern and all. At the time I did not need the Singleton anyways, so I just glanced over the document. But, setting this aside: I have an application where I have a connection to a database. At some point in the application I open up a new window. The new windows resides in a different module. So I have a directory structure like this: - mainapp.py - newwindow.py So I import newwindow in mainapp so I can instantiate and display it. Meanwhile, the main-app has an open connection to the database. What's the cleanest way to hand this connection to the new window? I can see several possibilities: 1) Simply pass the connection as paramtere to the constructor of new- window. 2) Use the Singleton deisign pattern to keep a reference to the connection 3) Open up a completely new connection to the database in the new window. Now, option 1) is clearly the easiest to implement, however, I somehow tend to use option 2 (the singleton) as it's more flexible. Option 3 looks ugly to me. This is a stuation I run into many times. And I am always faced with the same choice. And I never know which one to chose. And now that I am getting more and more comfortable with the basics of python, I would like to know if I am missing something more pythonic. So, what would you recommend? -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
On Sep 19, 3:45 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: [...] By the way, there is a pythonic (near) singleton: the module. So if you go with option 2, just move the connection setup into a separate module that you can import into client code. Peter You say (near) singleton. What's the difference then? -- http://mail.python.org/mailman/listinfo/python-list
Re: Keeping a database connection with a Singleton?
On Sep 19, 4:03 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: On Sep 19, 3:45 pm, Peter Otten [EMAIL PROTECTED] wrote: exhuma.twn wrote: [...] By the way, there is a pythonic (near) singleton: the module. So if you go with option 2, just move the connection setup into a separate module that you can import into client code. Peter You say (near) singleton. What's the difference then? I was thinking of the main script of an application. If you import that by its name import main # assuming the file is main.py you end up with two instances sys.modules[main] and sys.modules[__main__]. Peter I see. Thanks. I will give it a go. -- http://mail.python.org/mailman/listinfo/python-list
psycopg2 or pygresql?
Plain and simple. What would you use? So far I have written everything with psycopg2. One thing that annoys me is that I cannot easily access the column names from a query. I know that this is not part of the DBAPI2 so I cannot expect the model to suport it. I quite like the mogrify method of psycopg2 very much. It's very useful for debugging. And before someone says: Use the DictCursor-factory to access column names. Yes I can do that. But a dict does not guarantee the same order of keys as the columns were specified in the query. The reason: I wrote a very simple Qt-Widget (inherited from QTableWidget) that takes a SQL query and displays the results. And I would like to have the columns ordered the same way as I specified in the query *with* a header-label. For now I hava a method on the widget which takes a query, *and* a list of labels. I can live with that though. Although it itches me. Would pygresql solve my dilemma? Or would you rather say: Don't use pygresql! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 or pygresql?
On Sep 19, 5:47 pm, Steve Holden [EMAIL PROTECTED] wrote: exhuma.twn wrote: Plain and simple. What would you use? So far I have written everything with psycopg2. One thing that annoys me is that I cannot easily access the column names from a query. I know that this is not part of the DBAPI2 so I cannot expect the model to suport it. Yes it is. Execute a SELECT * FROM TABLE WHERE 1=0 and then examine cursor.description. This allows you to introspect on database structure. I quite like the mogrify method of psycopg2 very much. It's very useful for debugging. And before someone says: Use the DictCursor-factory to access column names. Yes I can do that. But a dict does not guarantee the same order of keys as the columns were specified in the query. See below. The reason: I wrote a very simple Qt-Widget (inherited from QTableWidget) that takes a SQL query and displays the results. And I would like to have the columns ordered the same way as I specified in the query *with* a header-label. For now I hava a method on the widget which takes a query, *and* a list of labels. I can live with that though. Although it itches me. Would pygresql solve my dilemma? Or would you rather say: Don't use pygresql! ;) Here's a psycopg2-based session: curs cursor object at 0x00B823C8; closed: 0 curs.execute(SELECT * FROM Person WHERE 1=0) curs.description (('psnid', 23, None, 4, None, None, None), ('psnfirstname', 1043, None, 50, None, None, None), ('psnlastname', 1043, None, 50, None, None, None), ('psndear', 1043, None, 50, None, None, None), ('psntitle', 1043, None, 50, None, None, None), ('psnworkphone', 1043, None, 30, None, None, None), ('psnworkextension', 1043, None, 20, None, None, None), ('psnhomephone', 1043, None, 30, None, None, None), ('psnmobilephone', 1043, None, 30, None, None, None), ('psnfaxnumber', 1043, None, 30, None, None, None), ('psnemailname', 1043, None, 50, None, None, None), ('psnreferredby', 1043, None, 50, None, None, None), ('psnlocid', 23, None, 4, None, None, None), ('psnnotes', 1043, None, -1, None, None, None)) I believe if you use specific column names in your query they will appear in the order given in the query also. I use this technique in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81189 to print arbitrary query outputs. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline Apparently I am deaf dumb and blind :( Sorry. I grepped several times through the PEP for various other reasons, and this little bit escaped me. Thanks for being nice guys and answering anyhow. Much appreciated. -- http://mail.python.org/mailman/listinfo/python-list
super, apply, or __init__ when subclassing?
This is something that keeps confusing me. If you read examples of code on the web, you keep on seeing these three calls (super, apply and __init__) to reference the super-class. This looks to me as it is somehow personal preference. But this would conflict with the There one way to do it mind-set. So, knowing that in python there is one thing to do something, these three different calls must *do* domething different. But what exactly *is* the difference? Exampel 1: - class B(A): def __init__(self, *args): A.__init__(self, args) Exampel 2: - class B(A): def __init__(self, *args): apply( A.__init__, (self,) + args) Exampel 3: - class B(A): def __init__(self, *args): super(A,self).__init__(*args) -- http://mail.python.org/mailman/listinfo/python-list
Re: super, apply, or __init__ when subclassing?
On Sep 18, 2:45 pm, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: exhuma.twn a écrit : This is something that keeps confusing me. If you read examples of code on the web, you keep on seeing these three calls (super, apply and __init__) to reference the super-class. This looks to me as it is somehow personal preference. But this would conflict with the There one way to do it mind-set. apply is deprecated. Chances are that code using it is somewhat old. super came with the new object model in Python 2.2.1 (IIRC), and is only useful for some corner cases involving multiple inheritence . Directly calling the superclass's method (__init__ or whatever) is the canonical way in the most common cases. And BTW, the sentence is there *should* be one - and *preferably* only one - *obvious* way to do it (emphasis is mine). In this case, there's _at least_ one way do to do it, and only one (direct call) is really obvious IMHO !-) So, knowing that in python there is one thing to do something, these three different calls must *do* domething different. Indeed. But mostly because you managed to get 2 examples wrong !-) But what exactly *is* the difference? Exampel 1: - class B(A): def __init__(self, *args): A.__init__(self, args) You want: class B(A): def __init__(self, *args): A.__init__(self, *args) Ah.. this was a typo in my original post. Oops ;) Exampel 2: - class B(A): def __init__(self, *args): apply( A.__init__, (self,) + args) is the same as the previous, using the deprecated apply function. Exampel 3: - class B(A): def __init__(self, *args): super(A,self).__init__(*args) You want: class B(A): def __init__(self, *args): super(B,self).__init__(*args) Hmmm... and suddenly it all makes sense! Great! Thanks all for clarifying this to a Java-Convert ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: super, apply, or __init__ when subclassing?
On Sep 18, 2:50 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 18 Sep 2007 04:33:11 -0300, exhuma.twn [EMAIL PROTECTED] escribi?: This is something that keeps confusing me. If you read examples of code on the web, you keep on seeing these three calls (super, apply and __init__) to reference the super-class. This looks to me as it is somehow personal preference. But this would conflict with the There one way to do it mind-set. So, knowing that in python there is one thing to do something, these three different calls must *do* domething different. But what exactly *is* the difference? There are a few typos in your examples. If you write them this way: Example 3 was not really a typo on my side. While I was browsing around for python, I saw this in a code-fragment. So I thought this was the way to do it. Even though I thought super(A... does not make sense in a semantic way. Instead of just accepting this as a fact I probably should have trusted my gut-feeling and investigate. Nonetheless the posts (and explanations) here were really helpful for me to understand what's happening under the hood. But seeing these three variants of doing (nearly) the same was an itch I finally decided to scratch. So far I blindly used Example 1 as it seemed to work for me. Exampel 1: - class B(A): def __init__(self, *args): A.__init__(self, *args) Exampel 2: - class B(A): def __init__(self, *args): apply( A.__init__, (self,) + args) Exampel 3: - class B(A): def __init__(self, *args): super(B,self).__init__(*args) then 2 is exactly the same as 1 but using a deprecated function. And 3 is the same as 1 only when there is single inheritance involved (and you are using new-style classes). But see the thread super() doesn't get superclass -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
easy_install only stable packages
easy_install is great. But it always automatically installs the *latest* version. Even if that is beta,alpha (or however else the developers call it). Is there no switch or possibility to disable this feature? So that it installs the latest *stable* version? I know that you can specify a specific version of a package with (for example) easy_install -U SQLAlchemy==0.3.10 This is undocumented on the web-page by the way ;) But having to specify the version number for each package is quite cumbersome. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing data in an QAbstractListModel
On Sep 7, 12:42 am, Jonathan Gardner [EMAIL PROTECTED] wrote: On Sep 6, 9:12 am, exhuma.twn [EMAIL PROTECTED] wrote: I defined a simple update method in the model which I call on certain events to fetch the new data in the DB. I tried to emit the dataChanged() signal of the Model without success. I don't know where I should get the two required index parameters from. Any hints? Shouldn't the index method give you the indexes you need? Right... The update method now looks like this: def update(self): c = db_con.cursor() # SELECT only the most recent entry for each company c.execute(SELECT DISTINCT ON (unit_id) nom FROM unit ORDER BY unit_id, year DESC) for unit in c.fetchall(): self.__units.append( unit[0] ) c.close() si = self.index(0) se = self.index(len(self.__units)-1) self.emit(Signal(dataChanged()), si, se) Still, nothing is happening when I call this method. Do I still need to handle the dataChanged signal somehow? Or does the ListView take care of this? -- http://mail.python.org/mailman/listinfo/python-list
Changing data in an QAbstractListModel
Hi, I want to create a very simple read-only ListView. As the same data is used on various places in the UI, I decided to create a new ListView with a new Model instead of using the QListWidget. So far, the data displays correctly after setting it with setModel on the ListView. But how do I tell the views that the data is updated in the model? I defined a simple update method in the model which I call on certain events to fetch the new data in the DB. I tried to emit the dataChanged() signal of the Model without success. I don't know where I should get the two required index parameters from. Any hints? Here's the model: #-- class UnitListModel(QtCore.QAbstractListModel): __units = [] def update(self): c = db_con.cursor() # SELECT only the most recent entry for each company c.execute(SELECT DISTINCT ON (unit_id) nom FROM unit ORDER BY unit_id, year DESC) for unit in c.fetchall(): self.__units.append( unit[0] ) c.close() def rowCount(self, parent = QtCore.QModelIndex()): return len(self.__units) def data(self, index, role): if not index.isValid(): return QtCore.QVariant() if index.row() = len(self.__units): return QtCore.QVariant() if role == QtCore.Qt.DisplayRole: return QtCore.QVariant(self.__units[index.row()]) else: return QtCore.QVariant() #-- -- http://mail.python.org/mailman/listinfo/python-list
twisted.web's xmlrpc with digest authencitation
I recently found a link[1] which demonstrates how to secure a xml-rpc service with basic HTTP-auth. But this get's send in clear-text over the net. There's also the HTTP-Digest auth mechanism which is apparently supported as well by twisted[2]. How do I secure an xml-rpc service using digest-auth then? If this works, all my troubles are suddenly gon and I am sold for twisted ;) [1]: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/526625 [2]: http://twistedmatrix.com/trac/ticket/1475 -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiline lamba implementation in python.
On Jun 12, 5:57 am, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 12 Jun 2007 00:02:37 -0300, Josh Gilbert [EMAIL PROTECTED] escribió: I don't expect multiline lambdas to be added to Python. I'm not so sure that that's a bad thing. Regardless, isn't it possible to write your own implementation of multiline lambdas as functions? Wouldn't that be a win-win for everyone? If you want to implement multiline lambdas as functions... why don't you use a plain old function? -- Gabriel Genellina I agree. lambdas are useful for simple things like lambda x: x^2 or so. Once you need more than that, you should consider refactoring things into a plain old function ;) In general I suppose that is a good idea anyhow to ensure future compatibility. lambdas are to be removed in Py3k IIRC. -- http://mail.python.org/mailman/listinfo/python-list
for ... else ?
On Jun 12, 6:57 am, Gabriel Genellina [EMAIL PROTECTED] wrote: [...] for number in range(10,100): is_prime = True for divisor in range(2,number): if number % divisor == 0: is_prime = False break if is_prime: print number, Next step: for loops have an optional else clause, that gets executed whenever the loop exits normally (in this case, when divisor goes up to number, and the break statement is never executed). So you don't need is_prime: for number in range(10,100): for divisor in range(2,number): if number % divisor == 0: break else: print number, Oh my. Would it not be an idea to rename this else into a finally? As Gabriel points out, the else-block gets executed after the for loop exits *normally*. In that case, is the else not semantically misleading? I would surely misunderstand it if I saw it the first time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pasting an image from clipboard in Tkinter?
On Jun 12, 11:24 am, Eric Brunel [EMAIL PROTECTED] wrote: On Mon, 11 Jun 2007 14:23:48 +0200,exhuma.twn [EMAIL PROTECTED] wrote: As many might know, windows allows to copy an image into the clipboard by pressing the Print Screen button on the keyboard. Is it possible to paste such an image from the clipboard into a Text widget in Tkinter? Here is my first attempt with just trying to print out the image data: - def pasteImg(tgt): global clipboardEnabled if not clipboardEnabled: return win32clipboard.OpenClipboard(0) print win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() - This works fine with selecting text, but comes up with the following error when trying to paste an image: - Exception in Tkinter callback Traceback (most recent call last): File C:\Python25\lib\lib-tk\Tkinter.py, line 1403, in __call__ return self.func(*args) File X:\development\testing\tkwiki\tkwiki.py, line 52, in lambda Button( root, command=lambda: pasteImg(txt) ).pack() File X:\development\testing\tkwiki\tkwiki.py, line 38, in pasteImg print win32clipboard.GetClipboardData() TypeError: Specified clipboard format is not available - Obviously the clipboard does not know about that format. Does that mean I have to wait until it's implemented or are there other ways to access the image data? According tohttp://msdn2.microsoft.com/en-us/library/ms649039.aspx, there is format that you should pass to GetClipboardData telling the data type you expect to get. The format you should specify to get a bitmap image is named CF_BITMAP in the Windows API. AFAIK, this constant is not exposed in the Python world, so you have to pass directly the numeric value, which is 2. But even if you do get the clipboard contents, you'll get it in BMP format, that tk/Tkinter does not understand by default. So you'll need a means to convert it to the only format known to tk/Tkinter by default, which is GIF. PIL is certainly able to do that (I don't use it myself); you may also rely on an external conversion utility. HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) Well, by inspecting the clipboard contents, I already suspected it might be 2. So I did a getData with the format set to 2. So, when I try to paste simple text, it does complain that the requested format is not on the clipboard. So far, correct. So I press the print screen button, which loads an image into th clipboard. When pasting I get this: Exception in Tkinter callback Traceback (most recent call last): File C:\Python25\lib\lib-tk\Tkinter.py, line 1403, in __call__ return self.func(*args) File X:\development\testing\tkwiki\tkwiki.py, line 55, in lambda Button( root, command=lambda: pasteImg(txt) ).pack() File X:\development\testing\tkwiki\tkwiki.py, line 39, in pasteImg print win32clipboard.GetClipboardData(2) error: (6, 'GetClipboardData:GlobalLock', 'The handle is invalid.') I'm not sure what this means. ... Ah... bugger. It won't work (yet): http://mail.python.org/pipermail/python-win32/2001-May/56.html -- http://mail.python.org/mailman/listinfo/python-list
Pasting an image from clipboard in Tkinter?
As many might know, windows allows to copy an image into the clipboard by pressing the Print Screen button on the keyboard. Is it possible to paste such an image from the clipboard into a Text widget in Tkinter? Here is my first attempt with just trying to print out the image data: - def pasteImg(tgt): global clipboardEnabled if not clipboardEnabled: return win32clipboard.OpenClipboard(0) print win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() - This works fine with selecting text, but comes up with the following error when trying to paste an image: - Exception in Tkinter callback Traceback (most recent call last): File C:\Python25\lib\lib-tk\Tkinter.py, line 1403, in __call__ return self.func(*args) File X:\development\testing\tkwiki\tkwiki.py, line 52, in lambda Button( root, command=lambda: pasteImg(txt) ).pack() File X:\development\testing\tkwiki\tkwiki.py, line 38, in pasteImg print win32clipboard.GetClipboardData() TypeError: Specified clipboard format is not available - Obviously the clipboard does not know about that format. Does that mean I have to wait until it's implemented or are there other ways to access the image data? -- http://mail.python.org/mailman/listinfo/python-list
Re: Pasting an image from clipboard in Tkinter?
On Jun 11, 3:47 pm, [EMAIL PROTECTED] wrote: On Jun 11, 7:23 am, exhuma.twn [EMAIL PROTECTED] wrote: As many might know, windows allows to copy an image into the clipboard by pressing the Print Screen button on the keyboard. Is it possible to paste such an image from the clipboard into a Text widget in Tkinter? Here is my first attempt with just trying to print out the image data: - def pasteImg(tgt): global clipboardEnabled if not clipboardEnabled: return win32clipboard.OpenClipboard(0) print win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() - This works fine with selecting text, but comes up with the following error when trying to paste an image: - Exception in Tkinter callback Traceback (most recent call last): File C:\Python25\lib\lib-tk\Tkinter.py, line 1403, in __call__ return self.func(*args) File X:\development\testing\tkwiki\tkwiki.py, line 52, in lambda Button( root, command=lambda: pasteImg(txt) ).pack() File X:\development\testing\tkwiki\tkwiki.py, line 38, in pasteImg print win32clipboard.GetClipboardData() TypeError: Specified clipboard format is not available - Obviously the clipboard does not know about that format. Does that mean I have to wait until it's implemented or are there other ways to access the image data? I don't think you can paste to a text widget, but I could be mistaken. This link talks about pasting an image into a window, but I don't think it's really what you want...however, it might give you some ideas: http://effbot.org/zone/wck-3.htm (see the Drawing Images section) This link also talks about some of the same things:http://www.wadsworth.org/spider_doc/spider/docs/python/spipylib/tkint... If I understand them correctly, it sounds like you could possibly catch the the paste operation and convert the image to a TkImage and then paste it. I think that since it is in the clipboard, then it is a file object and this may work. I just don't know how you intercept a paste. Mike Unfortunately, when they talk about pasting they talk about a PIL method called paste, which (if I understood correctly) deals with blitting one image onto another. Not pasting as in copy/paste from clipboard. -- http://mail.python.org/mailman/listinfo/python-list
Approaches of interprocess communication
Hi all, Supposing you have two separate processes running on the same box, what approach would you suggest to communicate between those two processes. Let me list the ones I know of: * Sockets Advantage: Supported per se in nearly every programming language without even the need to install additional packages Disadvantage: Lot's of code to write, and it's kind of silly to communicate via TCP/IP if the processes run on the same machine. * Webservices Advantage: Relatively easy to use, can work across different languages Disadvantage: Even more overhead on the TCP/IP side that simple sockets, as really bulky SOAP messages need to be passed around. * CORBA -- similar to webservices but more complicated to code. * Shared memory I don't know much about this subject. Supposing both processes are written in Python, is there any other way to achieve this? To me, shared memory sound the most suited approach. But as said, I am still fuzzy in this area. Where can I find more information on this subject? -- http://mail.python.org/mailman/listinfo/python-list
Re: Approaches of interprocess communication
On Feb 16, 1:33 pm, Duncan Grisby [EMAIL PROTECTED] wrote: In article [EMAIL PROTECTED], exhuma.twn [EMAIL PROTECTED] wrote: Supposing you have two separate processes running on the same box, what approach would you suggest to communicate between those two processes. [...] * Webservices Advantage: Relatively easy to use, can work across different languages Disadvantage: Even more overhead on the TCP/IP side that simple sockets, as really bulky SOAP messages need to be passed around. * CORBA -- similar to webservices but more complicated to code. Lots of people say that, but I don't think it's true. Obviously as the maintainer of a CORBA implementation I'm biased, but take a look at some examples of code that implement SOAP clients and servers and compare it to similar CORBA code. Especially in Python, the SOAP code tends to be incredibly verbose and complex, and the CORBA code really small and simple. My recommendation would be that for simple communications where performance isn't important use XML-RPC; for more complex cases where performance is a bit more important but you don't need anything except Python, use Pyro; for cases where performance is particularly important and/or you need cross-language communications, use CORBA. Maybe this line of mine was a bit too condensed ;) I fully agree with you on what you say about CORBA. It's just that for most people IDL looks a bit out of place. Especially because it resembles C. But once you actually wrote a few projects using CORBA, you actually begin to see it's elegance ;) I find Webservices easier as you can (although it's not recommendable) leave out the WSDL part. And some implementations actually generate the WSDL for you. But it's true, comparing WSDL and IDL I'd rather write some IDL than WSDL ;) But, returning back to topic, I first want to thank you all for your input. I appreciate all the ideas. Especially the idea of using the cmd module for sockets. That sound's very intriguing and I will very likely play around with that. But also PYRO seems quite useful. About Linda: Am I right that it looks very similar to JavaSpaces? If yes, are there any funcdamental differences between those two? -- http://mail.python.org/mailman/listinfo/python-list
ZSI + mod_python
Hi, I tried for the last 2 hours now to somehow grasp how to use ZSI over mod_python. It's nice that they have a code-example in the ZSI docs, but it's incomplete and you are left guessing. The ZSI docs I used as reference can be found on http:// pywebsvcs.sourceforge.net/zsi.html#SECTION00313 Here is where I am at so far: First I created the two files as described in the ZSI docs. Namely MyHandler.py and ws.py. The first name is obvious to someone who has coded at least a little bit of python, but it could be explicitly stated in the docs, so the beginners don't get stumped by a silly filename to start with ;) The second filename is my own concoction. I suppose it does not matter how it's named as you specify it in the apache conf anyhow. So. Now to the apache conf. I put the scripts into the document-root of my server. In this case: /var/www/localhost. So this is what I get (ommitting the unnecessary cruft -- marked it with [...]): /etc/apache2/sites-enables/000-default.conf --- VirtualHost * [...] DocumentRoot /var/www/localhost AddHandler mod_python .py [...] Directory /var/www/localhost/ [...] PythonHandler ws PythonDebug On /Directory [...] This is as far as I got. Now how do I call a service from this setting? What's the URI I need to specify in the client? I was trying http://server/foo.py; in the browser, and it was obviously doing *something* with the ws.py file. But I have no clue what. Here's the output: Browser output for http://server/foo.py - Mod_python error: PythonHandler ws Traceback (most recent call last): File /usr/lib/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch result = object(req) File /var/www/localhost/ws.py, line 9, in handler dispatch.AsHandler(modules=(MyHandler,), request=req) File /usr/lib/python2.4/site-packages/ZSI-2.0_rc3-py2.4.egg/ZSI/ dispatch.py, line 263, in AsHandler File /usr/lib/python2.4/site-packages/ZSI-2.0_rc3-py2.4.egg/ZSI/ parse.py, line 61, in __init__ File /usr/lib/python2.4/site-packages/PyXML-0.8.4-py2.4-linux- i686.egg/_xmlplus/dom/ext/reader/PyExpat.py, line 65, in fromStream success = self.parser.ParseFile(stream) ExpatError: no element found: line 1, column 0 No matter what I append to the URI, it does not make a difference in the output. And *why* am I forced to add a abracadabra.py to the URI? Could I not set Apache up in a way that it would use the ZSI handler for everything that calls -- let's say -- http:// webservices.server.tld/ instead of http://webservices.server.tld/ booh.py ? I'm off to a little bit more of testing. But any hints/input would be kindly appreciated ;) -- http://mail.python.org/mailman/listinfo/python-list
Survey environment for Python?
Hi, Just recently I had to take over support for legacy software written in Blaise (www.cbs.nl). As I did not know of this Programming Language until one year ago I started to learn it. Well more like read it as it's very very easy/simple. However, I don't feel comfortable in that language. As far not as comfy as in python ;) So I wanted to see if anyone knows of any surveying system written in or usable with python. For those that do not know Blaise: First of all, it's a simplified syntax of Pascal so the syntax is quite readable. And here is what you do with it: You define variables, then define routes. Those routes are simply definitions in which order those variables should be processed, and if some variables should be skipped. In addition to that it can perform a series of data-validation tests and some simple computations. It then uses these fields and routes to automatically generate a user-interface to fill in those fields. And that's about it. I am aware that something like this should be doable in python. Also, I think that a solid User Interface is very important for this task. Qt would be nice, but I still have trouble getting it to run properly with python. But that's a different story. And to avoid installing third-party libraries (on windows), Tk or a HTML-Interface seem to be the only choices. Is there anything like that around? If no, would anyone be interested in giving me a hand for this sort of project? Somebody that understands Tk would be useful, as I am mostly fluent in HTMLco. -- http://mail.python.org/mailman/listinfo/python-list
Re: Survey environment for Python?
Kay Schluehr wrote: exhuma.twn schrieb: Hi, Just recently I had to take over support for legacy software written in Blaise (www.cbs.nl). I don't understand the meaning of the link. Do you mean this language? http://blaise.sourceforge.net/ Not quite ;) Sorry for being too vague. This is the correct link: http://www.cbs.nl/en-GB/menu/informatie/onderzoekers/blaise-software/default.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to RuleDispatch
On Oct 18, 10:41 pm, Adam Jones [EMAIL PROTECTED] wrote: exhuma.twn wrote: Hi all, yesterday I wanted to install TurboGears, which depends on RuleDispatch. However, I failed to download it. First I got the error Bad Gateway from the server, today it's simply a Not Found error. So what happened to it? Does somebody know? I would really need to install TurboGears in the next couple of days. So if someone knows where I can find a mirror ofRuleDispatchI would be very grateful.The required files for TG are mirrored on the turbogears.org download page. You should be able to get an installation by looking up the files there. Try this command: easy_install -fhttp://www.turbogears.org/download/index.html TurboGears That is actually the recommended way to install TurboGears, as it is not always compatible with the latest version of the components. -Adam Hmmm... this is wat I get: Using /usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg Processing dependencies for TurboGears Searching for RuleDispatch Reading http://www.turbogears.org/download/index.html Best match: RuleDispatch 0.5a0.dev-r2115 Downloading http://files.turbogears.org/eggs/RuleDispatch-0.5a0.dev-r2115.tar.gz error: Can't download http://files.turbogears.org/eggs/RuleDispatch-0.5a0.dev-r2115.tar.gz: 502 Bad Gateway Could this be a local issue? -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to RuleDispatch
On Oct 19, 3:44 pm, exhuma.twn [EMAIL PROTECTED] wrote: On Oct 18, 10:41 pm, Adam Jones [EMAIL PROTECTED] wrote: exhuma.twn wrote: Hi all, yesterday I wanted to install TurboGears, which depends on RuleDispatch. However, I failed to download it. First I got the error Bad Gateway from the server, today it's simply a Not Found error. So what happened to it? Does somebody know? I would really need to install TurboGears in the next couple of days. So if someone knows where I can find a mirror ofRuleDispatchI would be very grateful.The required files for TG are mirrored on the turbogears.org download page. You should be able to get an installation by looking up the files there. Try this command: easy_install -fhttp://www.turbogears.org/download/index.html TurboGears That is actually the recommended way to install TurboGears, as it is not always compatible with the latest version of the components. -AdamHmmm... this is wat I get: Using /usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg Processing dependencies for TurboGears Searching forRuleDispatch Readinghttp://www.turbogears.org/download/index.html Best match:RuleDispatch0.5a0.dev-r2115 Downloadinghttp://files.turbogears.org/eggs/RuleDispatch-0.5a0.dev-r2115.tar.gz error: Can't downloadhttp://files.turbogears.org/eggs/RuleDispatch-0.5a0.dev-r2115.tar.gz: 502 Bad Gateway Could this be a local issue? Forgot to say I also tried to download it via the web-browser. This gave me the following error (generated by the proxy I have to use): Server response could not be decoded using encoding type returned by server. This is typically caused by a Web Site presenting a content encoding header of one type, and then encoding the data differently. -- http://mail.python.org/mailman/listinfo/python-list
Re: What happened to RuleDispatch
On Oct 19, 5:32 pm, Adam Jones [EMAIL PROTECTED] wrote: exhuma.twn wrote: On Oct 19, 3:44 pm, exhuma.twn [EMAIL PROTECTED] wrote: On Oct 18, 10:41 pm, Adam Jones [EMAIL PROTECTED] wrote: exhuma.twn wrote: Hi all, yesterday I wanted to install TurboGears, which depends on RuleDispatch. However, I failed to download it. First I got the error Bad Gateway from the server, today it's simply a Not Found error. So what happened to it? Does somebody know? I would really need to install TurboGears in the next couple of days. So if someone knows where I can find a mirror ofRuleDispatchI would be very grateful.The required files for TG are mirrored on the turbogears.org download page. You should be able to get an installation by looking up the files there. Try this command: easy_install -fhttp://www.turbogears.org/download/index.html TurboGears That is actually the recommended way to install TurboGears, as it is not always compatible with the latest version of the components. -AdamHmmm... this is wat I get: Using /usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg Processing dependencies for TurboGears Searching forRuleDispatch Readinghttp://www.turbogears.org/download/index.html Best match:RuleDispatch0.5a0.dev-r2115 Downloadinghttp://files.turbogears.org/eggs/RuleDispatch-0.5a0.dev-r2115.tar.gz error: Can't downloadhttp://files.turbogears.org/eggs/RuleDispatch-0.5a0.dev-r2115.tar.gz: 502 Bad Gateway Could this be a local issue? Forgot to say I also tried to download it via the web-browser. This gave me the following error (generated by the proxy I have to use): Server response could not be decoded using encoding type returned by server. This is typically caused by a Web Site presenting a content encoding header of one type, and then encoding the data differently.I just tried it for myself (with my workplace's proxy) and had no problems. You might want to check on the TurboGears mailing list (http://groups.google.com/group/turbogears) to see if someone there can help you figure out what is going on. Downloading the eggs at another location and installing locally is also an option. -Adam I'll do that. Thanks anyway. -- http://mail.python.org/mailman/listinfo/python-list
What happened to RuleDispatch
Hi all, yesterday I wanted to install TurboGears, which depends on RuleDispatch. However, I failed to download it. First I got the error Bad Gateway from the server, today it's simply a Not Found error. So what happened to it? Does somebody know? I would really need to install TurboGears in the next couple of days. So if someone knows where I can find a mirror of RuleDispatch I would be very grateful. Cheers, Mich. -- http://mail.python.org/mailman/listinfo/python-list
combining mod_python handlers publisher and psp problem
Simple problem: When I define a funtion the way you would with the publisher handler (without using psp), all works as expected. However when I define a publisher-like function and instantiate a PSP object in it ( as suggested on http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html ) mod_python seems to fail to tell the browser which content-type the document has. The output is what I expect it to be, but instead of rendering the page I see the source code, so I suppose the browser sees it as text/python or text/plain. I tried to do a print Content-Type: text/html print as first statement, but then it only outputs that as normal text too. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: combining mod_python handlers publisher and psp problem
exhuma.twn wrote: Simple problem: When I define a funtion the way you would with the publisher handler (without using psp), all works as expected. However when I define a publisher-like function and instantiate a PSP object in it ( as suggested on http://www.onlamp.com/pub/a/python/2004/02/26/python_server_pages.html ) mod_python seems to fail to tell the browser which content-type the document has. The output is what I expect it to be, but instead of rendering the page I see the source code, so I suppose the browser sees it as text/python or text/plain. I tried to do a print Content-Type: text/html print as first statement, but then it only outputs that as normal text too. Any ideas? Update: I got it working. My old code was as follows: def index(req, name='John'): s = 'Hello, there!' if name: names = ['a', 'b', 'c'] s = 'Hello, %s!' % name.capitalize() tmpl = psp.PSP(req, filename='index.psp') tmpl.run(vars = { 'greet': s, 'names': names }) return Now I did this: def index(req, name='John'): s = 'Hello, there!' if name: names = ['a', 'b', 'c'] s = 'Hello, %s!' % name.capitalize() tmpl = psp.PSP(req, filename='index.psp', vars = { 'greet': s, 'names': names }) return tmpl So basically I assigned the variables on instantiation of the PSP object and returned the resulting reference. This is different to what is noted at onlamp.com -- http://mail.python.org/mailman/listinfo/python-list
mod_python + publisher + psp + session problems
Hi again, as soon as I try to make use of the session object inside a psp-template file, I get the following error: Mod_python error: PythonHandler mod_python.publisher Traceback (most recent call last): File /usr/lib/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch result = object(req) File /usr/lib/python2.4/site-packages/mod_python/publisher.py, line 143, in handler result = str(result) File /usr/lib/python2.4/site-packages/mod_python/psp.py, line 228, in __str__ self.run() File /usr/lib/python2.4/site-packages/mod_python/psp.py, line 191, in run session = Session.Session(req) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 389, in Session timeout=timeout, lock=lock) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 294, in __init__ timeout=timeout, lock=lock) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 132, in __init__ Cookie.add_cookie(self._req, self.make_cookie()) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 160, in make_cookie c.path = dirpath[len(docroot):] TypeError: unsubscriptable object Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: combining mod_python handlers publisher and psp problem
[EMAIL PROTECTED] wrote: You could also have done: def index(req, name='John'): s = 'Hello, there!' if name: names = ['a', 'b', 'c'] s = 'Hello, %s!' % name.capitalize() tmpl = psp.PSP(req, filename='index.psp') req.content_type = 'text/html' tmpl.run(vars = { 'greet': s, 'names': names }) return Try the mod_python mailing list if you want an explaination of why. Graham Thanks, that worked. -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python + publisher + psp + session problems
[EMAIL PROTECTED] wrote: exhuma.twn wrote: Hi again, as soon as I try to make use of the session object inside a psp-template file, I get the following error: Mod_python error: PythonHandler mod_python.publisher Traceback (most recent call last): File /usr/lib/python2.4/site-packages/mod_python/apache.py, line 299, in HandlerDispatch result = object(req) File /usr/lib/python2.4/site-packages/mod_python/publisher.py, line 143, in handler result = str(result) File /usr/lib/python2.4/site-packages/mod_python/psp.py, line 228, in __str__ self.run() File /usr/lib/python2.4/site-packages/mod_python/psp.py, line 191, in run session = Session.Session(req) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 389, in Session timeout=timeout, lock=lock) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 294, in __init__ timeout=timeout, lock=lock) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 132, in __init__ Cookie.add_cookie(self._req, self.make_cookie()) File /usr/lib/python2.4/site-packages/mod_python/Session.py, line 160, in make_cookie c.path = dirpath[len(docroot):] TypeError: unsubscriptable object Any ideas? Upgrade to mod_python 3.2.8 and your problem will go away. See: http://issues.apache.org/jira/browse/MODPYTHON-50 I suggest that in future you use the mod_python mailing list for questions as that is where most knowledgeable people on mod_python hang out. Graham Thanks a lot Graham. This solved the problem. -- http://mail.python.org/mailman/listinfo/python-list