UpdateLayeredWindow in pywin32
Hi! I am trying to making an On-Screen Display, which is implemented by wx.Frame. Basically I created a wx.Frame with style like super(OSDBase, self).__init__(parent, id, title, style = wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR | wx.TRANSPARENT_WINDOW | wx.NO_BORDER) self.SetTransparent(128) But if I try to draw an image with alpha channel(like PNG format), I always get a background behind this image. But I don't want the background. Then I read this article, http://www.codeproject.com/csharp/OSDwindow.asp The demo program is written in C#. I understand that I need to use UpdateLayeredWindow to update visual content of a layered window. But I always got an error: Traceback (most recent call last): File "osd_post.py", line 60, in osd.Update() File "osd_post.py", line 56, in Update 2) pywintypes.error: (87, 'UpdateLayeredWindow', 'The parameter is incorrect.') I am not sure did I use UpdateLayeredWindow correctly. Any help would be appreciated. My Python is 2.5, pywin32 is 210, wxPython is 2.8.1 UpdateLayeredWindow Function Help from MSDN: http://msdn2.microsoft.com/en-us/library/ms633556.aspx UpdateLayeredWindow Function Help from pywin32: http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32gui__UpdateLayeredWindow_meth.html My source code: """pyitctrl - OSD""" # Created Date : 2007/03/14 # Author: livibetter import wx, winxpgui, win32con class OSDBase(wx.Frame): def __init__(self, parent, id, title): super(OSDBase, self).__init__(parent, id, title, style = wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR | wx.TRANSPARENT_WINDOW | wx.NO_BORDER) self.SetTransparent(128) print hex(winxpgui.GetWindowLong(self.GetHandle(), win32con.GWL_EXSTYLE)) print winxpgui.GetLayeredWindowAttributes(self.GetHandle()) self.img = wx.Image("icon.png") self.bmp = self.img.ConvertToBitmap() w, h = self.bmp.GetWidth(), self.bmp.GetHeight() self.SetClientSize( (w, h) ) def Update(self): print "Update" screenDC = winxpgui.GetDC(winxpgui.GetDesktopWindow()) print screenDC cScreenDC = winxpgui.CreateCompatibleDC(0) print cScreenDC (w, h) = self.GetSizeTuple() bmp = wx.EmptyBitmap(w, h) tmpDC = wx.MemoryDC() tmpDC.SelectObject(bmp) tmpDC.SetBackground(wx.Brush("BLACK")) tmpDC.Clear() tmpDC.DrawBitmap(self.bmp,0,0, True) tmpDC.Destroy() del tmpDC winxpgui.SelectObject(cScreenDC, bmp.GetHandle()) winxpgui.UpdateLayeredWindow(self.GetHandle(), screenDC, self.GetPositionTuple(), self.GetSizeTuple(), cScreenDC, (0,0), 0, (0,0,128,1), win32con.ULW_ALPHA) app = wx.App(False) osd = OSDBase(None, wx.ID_ANY, 'OSD Frame') osd.Update() osd.Show() app.MainLoop() -- http://mail.python.org/mailman/listinfo/python-list
Re: strange behaviour with keyword arguments and inheritance
On Apr 17, 8:56 am, "matthewperpick" <[EMAIL PROTECTED]> wrote: > Check out this toy example that demonstrates some "strange" behaviour > with keyword arguments and inheritance. > > = > > class Parent: > def __init__(self, ary = []): > self.ary = ary > This should work: class Parent: def __init__(self, ary = []): self.ary = list(ary) And FYI http://groups.google.com/group/comp.lang.python/browse_thread/thread/e203f9cd64125a78/8d89b250ceca1458#8d89b250ceca1458 -- http://mail.python.org/mailman/listinfo/python-list
Re: UpdateLayeredWindow in pywin32
I have found the cause "Please note that after SetLayeredWindowAttributes has been called, subsequent UpdateLayeredWindow calls will fail until the layering style bit is cleared and set again." from http://msdn2.microsoft.com/en-us/library/ms632599.aspx#layered But I still can't use winxpgui.UpdateLayeredWindow, Now I am using ctypes to enable calling UpdateLayeredWindow, and this works. -- http://mail.python.org/mailman/listinfo/python-list
Re: v = json.loads("{'test':'test'}")
On Jan 26, 5:12 am, gert wrote: > raise ValueError(errmsg("Expecting property name", s, > end))http://docs.python.org/library/json.html > What am I doing wrong ? You use wrong quotes, it should be wrapped by double quotes not single quotes. Read http://json.org/: "A string is a collection of zero or more Unicode characters, wrapped in double quotes, ..." >>> v = json.loads('{"test":"test"}') >>> v {u'test': u'test'} -- http://mail.python.org/mailman/listinfo/python-list
Re: Bullshit Generator
This is fun. I tried to add speech synthesis on Linux, hope you don't mind. If you have speech-dispatcher [1] worked normally, you can replace the main program with # -- # main program # -- try: import win32com.client voice = win32com.client.Dispatch("sapi.SPVoice") except: try: import speechd voice = speechd.SSIPClient('bullshit.py') # Choose one module you have on your system voice.set_output_module('espeak') voice.set_punctuation(speechd.PunctuationMode.SOME) except: voice = None print "press to resume, 'q'+ to quit\n" while True: print for i in xrange(8): generatedSentence = sentence.getString() print generatedSentence, if voice: voice.speak(generatedSentence) if raw_input().strip().lower() == "q": voice.cancel() import sys sys.exit(0) # End of Main Program [1] http://cvs.freebsoft.org/doc/speechd/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Validation with domain
> If you want to validate the domain, do a DNS lookup on the domain or > some such. I don't think there are standard modules to provide this > functionality included with python. You could try using the socket > module, and reading up on the relevant protocols, or making calls to > external programs. I agreed. I made quick code for this. # Email address validator # # This module is in Public Domain # # This module was written for replying to # http://groups.google.com/group/comp.lang.python/browse_thread/thread/80d7d31bebc09190 # * It requires dnspython (http://www.dnspython.org/). # * It is a simple prototype. # * It would be slow if query mass email addresses, having cache mechanism #would be very helpful. # * It only checks hostname of email address. # # Author : Yu-Jie Lin # Creation Date: 2008-07-02T20:09:07+0800 import dns.resolver def CheckEmail(email): """This function directly extracts the hostname and query it""" email_parts = email.split('@') if len(email_parts) != 2: return False # Start querying try: answers = dns.resolver.query(email_parts[1], 'MX') except dns.resolver.NoAnswer: # This host doesn't have MX records return False except dns.resolver.NXDOMAIN: # No such hostname return False # Possible a valid hostname return True I also wrote a short blog post for this post and the code, if you are interested, you can read it at http://thetinybit.com/Blog/2008-07-02-2047-EmailHostnameCheck -- http://mail.python.org/mailman/listinfo/python-list
Re: Ann: Validating Emails and HTTP URLs in Python
First, it's good to see a library has URL and email validator. But I found there might be a problem in your validator, the problems I found are these URLs: http://example.com/path http://example.com/path) http://example.com/path] http://example.com/path} By my understanding from RFCs, only first two are valid. >>> from lepl.apps.rfc3696 import * >>> v = HttpUrl() >>> v('http://example.com/') True >>> v('http://example.com/path') True >>> v('http://example.com/path)') True >>> v('http://example.com/path]') True >>> v('http://example.com/path}') True You use RFC 3969 [1] to write your code (I read your source code, lepl.apps.rfc3696._HttpUrl()), I think your code should only return True for first case, but all return True. Maybe I use it incorrectly? And I think that has a slight issue because RFC 3969 was written based on RFC 2396 [2], which is obsoleted by RFC 3986 [3]. I never really read RFC 3969, I am not sure if there is problem. But in RFC 3969, it writes The following characters are reserved in many URIs -- they must be used for either their URI-intended purpose or must be encoded. Some particular schemes may either broaden or relax these restrictions (see the following sections for URLs applicable to "web pages" and electronic mail), or apply them only to particular URI component parts. ; / ? : @ & = + $ , ? However in RFC 2396 (the obsoleted RFC), "3.3. Path Component," The path component contains data, specific to the authority (or the scheme if there is no authority component), identifying the resource within the scope of that scheme and authority. path = [ abs_path | opaque_part ] path_segments = segment *( "/" segment ) segment = *pchar *( ";" param ) param = *pchar pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | "," Here is unreserved of pchar: unreserved = alphanum | mark mark= "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" In RFC 3986, they are a bit different, but my point here is "(" and ")". The Uri from 4Suite return the results I expect: >>> import Ft.Lib.Uri as U >>> U.MatchesUriSyntax('http://example.com/path') True >>> U.MatchesUriSyntax('http://example.com/path)') True >>> U.MatchesUriSyntax('http://example.com/path}') False >>> U.MatchesUriSyntax('http://example.com/path]') False I think you should use (read) RFC 3986 not RFC 3696 for URL validation. One more thing, HttpUrl()'s docstring should s/email/url/. [1]: http://tools.ietf.org/html/rfc3696 [2]: http://tools.ietf.org/html/rfc2396 [3]: http://tools.ietf.org/html/rfc3986 -- http://mail.python.org/mailman/listinfo/python-list
Re: Plain simple unix timestamp with an HTTP GET
I don't know what tools do you have on embedded system, but I really don't think this has to be using Python. Here is what I would do on a normal desktop using your unique way to set up time: date -s "$(curl -s -I http://example.com | grep Date | cut -d \ -f 2-)" On Jun 4, 8:05 am, Ross wrote: > I'd like to just quickly and with a minimum of parsing (ie no screen- > scraping) get a unix epoch timestamp (or another format if necessary). > > I thought with a quick second search on Google I'd find a URL where I > could do a simple urllib2 based HTTP GET and have a timestamp > returned to me. I don't want to use NTP. > I need this because I want to run it on an embedded system where I > don't have a local timesource, but do have a network service. I'm very > low on memory tho. > > I can set up my own service on django I suppose, and just render back > the timestamp from datetime.time() but SURELY someone else is already > doing that? > > My googling has fallen flat. Any suggestions. > > Thanks in advance! > > -Ross. -- http://mail.python.org/mailman/listinfo/python-list
Re: Plain simple unix timestamp with an HTTP GET
This? hwclock --utc --set --date="$(datestr="$(curl http://208.66.175.36:13/ 2>/dev/null | cut -d \ -f 2-3)" ; echo ${datestr//-//})" Only hwclock, curl, cut, and Bash. PS. I didn't know I can set the time via hwclock, learned from Paul's post, but still didn't try to see if it does work. On Jun 4, 8:57 am, Ross wrote: > No - it's not really a python specific need, it's just what I'm using > just now, and can't think of where else to ask. It's also my fav test- > bed, as it's so easy. > > Your curl example is using grep and date which I don't have available. > I have no fancy libraries, just core parsing capability. > > I found that NIST has some capability on various servers. > > RFC 868 and 867. I can get this > > > curlhttp://208.66.175.36:13/ > > 55351 10-06-04 00:24:46 50 0 0 8.3 UTC(NIST) * > > But I'd have a lot of parsing to pull it together. > > Apparently RFC868 provides a 32bit unformated binary response, but I > can't make much out of it. I think my TCP client library is expecting > chars and is screwed by bit-boundary expectations. > The number is supposed to be seconds since 1900, which is just as good > as seconds since 1970. > > Still hunting. Tho' maybe getting a bit off topic for a python msg > board :) > > On Jun 3, 8:36 pm, livibetter wrote: > > > > > I don't know what tools do you have on embedded system, but I really > > don't think this has to be using Python. > > > Here is what I would do on a normal desktop using your unique way to > > set up time: > > > date -s "$(curl -s -Ihttp://example.com|grep Date | cut -d \ -f > > 2-)" -- http://mail.python.org/mailman/listinfo/python-list
Re: Plain simple unix timestamp with an HTTP GET
I forgot to mention I redirect stderr to /dev/null, because curl returns error code 56 to me with this message "curl: (56) Failure when receiving data from the peer" On Jun 4, 11:20 am, livibetter wrote: > This? > > hwclock --utc --set --date="$(datestr="$(curlhttp://208.66.175.36:13/ > 2>/dev/null | cut -d \ -f 2-3)" ; echo ${datestr//-//})" > > Only hwclock, curl, cut, and Bash. > > PS. I didn't know I can set the time via hwclock, learned from Paul's > post, but still didn't try to see if it does work. > > On Jun 4, 8:57 am, Ross wrote: > > > > > No - it's not really a python specific need, it's just what I'm using > > just now, and can't think of where else to ask. It's also my fav test- > > bed, as it's so easy. > > > Your curl example is using grep and date which I don't have available. > > I have no fancy libraries, just core parsing capability. > > > I found that NIST has some capability on various servers. > > > RFC 868 and 867. I can get this > > > > curlhttp://208.66.175.36:13/ > > > 55351 10-06-04 00:24:46 50 0 0 8.3 UTC(NIST) * > > > But I'd have a lot of parsing to pull it together. > > > Apparently RFC868 provides a 32bit unformated binary response, but I > > can't make much out of it. I think my TCP client library is expecting > > chars and is screwed by bit-boundary expectations. > > The number is supposed to be seconds since 1900, which is just as good > > as seconds since 1970. > > > Still hunting. Tho' maybe getting a bit off topic for a python msg > > board :) > > > On Jun 3, 8:36 pm, livibetter wrote: > > > > I don't know what tools do you have on embedded system, but I really > > > don't think this has to be using Python. > > > > Here is what I would do on a normal desktop using your unique way to > > > set up time: > > > > date -s "$(curl -s -Ihttp://example.com|grep Date | cut -d \ -f > > > 2-)" -- http://mail.python.org/mailman/listinfo/python-list
Re: toy list processing problem: collect similar terms
Here is mine for Python: l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1, 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'], [5, 's', 't']] d = {} for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items if idx in d else items print d.values() Output: [['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'], ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']] -- http://mail.python.org/mailman/listinfo/python-list