NSTimer python code

Hi,
Just wondering if someone could point me in the right
direction ....
I am looking for a good example of the use of NSTimer
with NSrunloop in order to have a background job
run every minute but without tying up the UI by using
the 'sleep' statement.
thanks,

Threading might be a better solution than using a timer, but here's one way to use a timer (sorry, I don't know how to post code here to maintain the whitespace formatting).
def awakeFromNib(self):
self.timer = None
# etc.
def startTimer(self, interval): # your interval is 60 secs?
if self.timer == None:
self.timer = NSTimer.scheduledTimerWithTimeIntervaltarget_selector_userInfo_repeats(interval, self, self.backgroundJob, None, True)
def backgroundJob(self):
Do background job here.
If job takes awhile and you don't want to block the
UI, then call handleEvents periodically (especially
convenient if the background job is in a loop):
while doingJob == True:
# next job iteration... then
self.handleEvents(0.01) # that's 0.01 seconds
def endTimer(self): # when you want the timer to stop
if self.timer != None:
self.timer.invalidate()
self.timer = None
def handleEvents(self, expiration):
app = NSApplication.sharedApplication()
event = app.nextEventMatchingMaskuntilDate_inMode_dequeue( \
NSAnyEventMask, NSDate.dateWithTimeIntervalSinceNow_(expiration), \
NSDefaultRunLoopMode, True)
if event:
# Could put special event handling here
app.sendEvent_(event)
Hope this is what you were looking for!
Jim

Similar Messages

  • Binary files in Python, code snippet in Java to Python

    I'm trying to get data out of a game file (ITM/Baldurs Gate http://iesdp.gibberlings3.net/ieformats/itm_v1.htm). Some of variables can't be read directly (like dword) (won't show the data it should).
    A java based NearInfinity converts binary dword data in this way:
    public static int convertInt(byte buffer[], int offset)
    int value = 0;
    for (int i = 3; i >= 0; i--)
    value = (value << 8) | (buffer[offset + i] & 0xFF);
    return value;
    Now, how Python code would look like? I've checked binascii module with no luck.

    I have
    plik = open('bow08.itm', 'rb')
    try:
    tekst = plik.read()
    finally:
    plik.close()
    # char array - works
    print tekst[0x0004:0x0004+4]
    # resref - works
    print tekst[0x003a:0x003a+8]
    #dword
    print tekst[0x004c:0x004c+4]
    and the dword (and few other variables) won't show anything (will output binary something), the java snippet in my first post from NearInfinity converts that binary code into a normal data

  • Python code blocks in LV 8.2

    Is there anyway to put Python code nice and easily into LV8.2 
    Or will i have to build it or convert it into another codetype?
    Ta for help.

    http://labpython.sourceforge.net/
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • How to write python code in Data Services ?

    I read that you can use python programming to do tasks that custom SAP Data Services Designer components cannot do. Here is the link for that -
    SAP Data Services/BODS equivalent of Microsoft SSIS Script Task
    I don't know where I can type my code in DS / BODS. I see a script in the designer window, but it has nothing to do with python. Can someone show me
    where it is and how to do programming in SAP DS ?
    In SSIS, creating a script with programming language is very easy. Just drag and drop the Script component and start coding right away.
    Unfortunately, SAP does not seem to be so simple.

    Hi Terry,
    There is simple solution provided by Ramesh Murugan then why do you want go for hard way !! Not sure your intention
    For your questions
    Can we do the ENTIRE etl in python ?
    Not sure but  I didn't get any complicated scenarios so for  and also we need to consider performance as well
    Challenge with some complicated scenarios with BODS !! We happy to provide solutions
    But every tool has unique capability !!
    Regards,
    Manoj

  • Python: Code like a pythonista

    http://python.net/~goodger/projects/pyc … ndout.html
    Stumbled across that in a google search... some really useful things in there that I never knew. Hopefully it's useful to someone else.
    James

    phrakture wrote:
    voonte wrote:
    Quite interesting read, indeed.
    But, I have never understood the
    - 4 spaces per indentation level.
    - No hard tabs.
    argument.
    It's a bikeshed. There are arguments for and against both sides - a coder's holy war. The only way to solve it is to say "screw you all, do it this way". Guido did just that.
    Consistency is what really matters. I can show you a bunch of code, written in number of editors by a group of people who did not really care about consistency. Hopefully this is only C code, easy to fix with indent.

  • Run python code in big compute cloud of Azure

    So--
    I have a script in Python that I want to run. However, this script produce a VERY large amount of data that my computer CPU can't handle.
    How can I run a code in python in the big compute section of Azure?
    Step-by-step what do I do?
    Thanks

    Hi,
    Firstly, I recommend you refer to those tutorials to try to deploy your project on azure cloud service, such as Tutorial:
    Tutorial: Running a Python Web Application in Windows Azure
    Python on Windows Azure –  a Match Made in the Clouds!
    And this docs http://azure.microsoft.com/en-us/develop/python/ .
    Secondly, I suggest you could enable your could service autoscale feature (http://azure.microsoft.com/en-us/documentation/articles/cloud-services-how-to-scale/
    ). It could meet your project requirement.
    Hope this helps.
    Will
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Python Code?

    Recently my iMac's hard drive was copied as part of a computer forensic examination. The forensic expert filed a report with the court saying that he found emails on my computer that prove I have forged email headers, as well as used or tested remailing or anonymizing software. The emails he included with the report are listed as having been sent by [email protected] with the name "Barry Warsaw" on them.
    My first guess was that these emails were spam which was sent to me and immediately deleted. Further searching led me to the folks who operate the Python.org thing, whatever in the heck that is. They informed me that what was found was a very old piece of Python "sample data" which some computer makers and software writers include at the time of manufacture. They said there was "nothing sinister" about it and the "expert" doesn't know what he's doing.
    Does anyone here have any idea what's going on? I'm sensing that their forensic "expert" has either misidentified a piece of innocent email or code or is running a scam on somebody. I've put a copy of one of the emails below. Thanks.
    Return‐Path: <[email protected]> Delivered‐To: [email protected] Received: by mail.python.org (Postfix, from userid 889)
    id C2BF0D37C6; Tue, 11 Sep 2001 00:05:05 ‐0400 (EDT) MIME‐Version: 1.0
    Content‐Type: multipart/mixed; boundary="h90VIIIKmx" Content‐Transfer‐Encoding: 7bit Message‐ID: <[email protected]> From: [email protected] (Barry A. Warsaw)
    To: [email protected] Subject: a simple multipart Date: Tue, 11 Sep 2001 00:05:05 ‐0400 X‐Mailer: VM 6.95 under 21.4 (patch 4) "Artificial Intelligence" XEmacs Lucid X‐Attribution: BAW X‐Oblique‐Strategy: Make a door into a window
    ‐‐h90VIIIKmx Content‐Type: text/plain Content‐Disposition: inline; name="msg.txt" Content‐Transfer‐Encoding: 7bit
    a simple kind of mirror to reflect upon our own
    ‐‐h90VIIIKmx Content‐Type: text/plain Content‐Disposition: inline; name="msg.txt" Content‐Transfer‐Encoding: 7bit
    a simple kind of mirror to reflect upon our own
    ‐‐h90VIIIKmx‐‐
             Like         (0)    
        Reply   

    Barry Warsaw from Python.org contacted me with this information. I'll post it here in the event that anyone else might eventually run into the same thing. By the way, the computer forensic "expert" who stated that these emails were evidence of some sort of nefarious activity turns out to be far less than an expert after all. So much for his "credentials." It's official - he doesn't know what he's doing.
    From:     Barry Warsaw <[email protected]>
        Subject:     Re: Question
        Date:     May 4, 2011 4:37:02 PM EDT
        To:     [email protected]
        Cc:     [email protected], Tom Kirkman <[email protected]>
    Tom contacted me separately via my [email protected] email address, and I've already replied to him as best I can determine.  He sent a snippet of a few email headers from the messages in question, and I searched for a Message-Id I found in the snippet.  As best I can tell, the message was some sample data included in a commit message to python-checkins back in 2001.  I haven't even looked to see if the file is still in the tree, but just to tell you how old that was, it's not clear whether we're talking about the email package, mimelib or something older (I just don't remember ;).  And this was back when we were using CVS!
    It is sample data used to drive a unit test and was probably written around 2001.  This tests a library that parses email addresses.  The sample data is just made-up stuff to test the library, so it has to look like an email message. Sample data for unit tests don't change over time.  As a matter of fact, this particular message still lives in the Python source tree:
    http://hg.python.org/cpython/file/b4b0a1458638/Lib/email/test/data/msg_04.txt
    I hope my explanation to Tom included enough relevant background information on Python, our libraries, unit tests, sample data, commit process, etc. so that he can clearly tell there was absolutely nothing sinister about the file. In fact, it was never actually *sent* anywhere - it was just part of a message included in a commit notification. 
    Another thing I thought about: I think it's possible his computer manufacturer included a copy of the Python source code on his machine, or maybe he downloaded and installed Python at some time in the past, or possibly installed some software that *included* Python and its source tree.  Either way, I can't possibly imagine how this could be interpreted as anything other than totally innocent.  It's not even spam.
    Cheers,
    -Barry Warsaw

  • Python code in Java

    Hello,
    I have a python script that accesses to a serial device to read/write data. Now I would like to build a JAVA application that extend this script. I can call this script as a program java? I should create a Java application that interact with the user and writes on this device using python script already in my possess. I do not wish rewrite the script python in Java.
    I have used JEPP e Jython.........other ?

    XmaverickX wrote:
    duffymo wrote:
    Or Jython.
    http://www.jython.org/Project/index.html
    %When i recompile (is right recompile ?) communication.py with jython get this error:
    0 Note: Some input files use or override a deprecated API.
    Note: Recompile with -deprecation for details.Did you recompile with -deprecation turned on to see what the details were? (I'd recommend that you do.)
    After when i include Communication.class in my java project i get this error:
    Exception in thread "main" Traceback (innermost last):
    File "/home/maverick/prova/Communication.py", line 0, in main
    File "/usr/lib/serial/__init__.py", line 9, in ?
    AttributeError: class 'string' has no attribute 'split'Looks like the Jython string class does not have an attribute 'split' that you require. Maybe it was deprecated and removed.
    Is this why you asked for something other than Jython? Better to understand and fix this problem.
    %

  • Run python code in PX6-300D

    Hello,I would like to run Python scripts on my PX6-300D, does it supported? 

    Hello obarlev,
    It is not something that is officially supported and I wouldn't be able to help with it.

  • Looking for Web2Py or Python interfacing code to DI Server

    Dear All,
    I am looking for a Web2Py (python) code sample that can interface or talk with DI Server of SAP B1 say through win32 python API SOAP interface.
    Some sample to get me started in the right path to connect to DI server, login and access simple SAOP service.
    Thank you very much.

    I don't know if you'll find an exact sample here - you might be lucky of course, but I think it's a bit specific.
    Instead, I would focus on learning the two separately; look on google for some examples of writing SOAP interfaces using Python and then also do some DI server examples.
    The Python I can't help with, but for DI server you can check the SDK helpfile and go to Developers Guide -> DI Server and then under this you have lots of good sections:
    System Messages: Shows how to login and get the session ID
    Data Manipulation Messages: Shows how to add/update/remove objects in the DB
    DI Server application gives instructions on how to set it up.
    Hope it's useful, might be worth keeping thread open to see if anyone has done this before though

  • Compability problem with Java and Python  RSA algorithm implementation

    I have client server application. Server is writtein in python, client in java. Client receives messages from server encrypted with RSA (http://stuvel.eu/rsa), and I'm unable to decrypt it. It seems that this is RSA algorithm compatibility problem. I'm using algorithm from java.security package, instatinating Cipher object like this: c = Cipher.getInstance("RSA"); . I noticed that this algorithm produces for input blocks of lengtrh <=117 ouput block of length 128. Server I guess uses the most triviall impelentation of RSA ( (1 byte is encrypted to 1 byte) So i want to make my java algorithm compatibile with this one which server uses. How to do that ? Do i have to instatinate Cipher object in different way ? Or use another library ?

    azedor wrote:
    First you said it was no good because it could only handle <= 117 byte inputs, now you say it is no good because it produces a 128-byte output. You're not making sense.First i said that this two RSA implementations are not compatibile, and first reason i noticed firstly is that Python imlementation for input of length N produces cryptogram of the same length. Not true. In general, the RSA encryption of any number of bytes less than the length of the modulus will produce a result of length near that of the modulus. When N is less than the length of the modulus, it is rare that N bytes of cleartext produces N bytes of ciphertext.
    Java implementation for data block of length <=117 produces alwasy 128 bytes of output.Pretty much correct and very much desirable. This is primarily a function of the PKCS1 padding which is used to solve two basic problems. First, as I alluded to in my first response, it is the nature of the algorithm that leading zeros are not preserved and second when the cleartext is very small (a few bytes) the exponentiation does not roll over and it is easy to decrypt the result. Both these problems are addressed by PKCS1 padding.
    >
    >
    After what sabre150 said i think of giving up idea of translating Python code to Java and considering to use another assymetric cryptography algorithms on both sides. Can you recommend me sth what should be compatibile with Python ?This seems to be at odds with your statement in reply #3 "Also have acces only to client code so i have to change sth in java." ! This statement is why I said "I suspect ... you have dug a deep hole".
    In your position I would use the Python bindings for openssl. Once more, Google is your friend.

  • Python 2.5 / missing msvcp71.dll issue on Windows

    During a new DBXML installation I got stuck for a while installing the Python 2.5 bindings for DB XML 2.4.16 -- I kept getting a DLL import error when importing the dbxml module in the Python code. After a bit of troubleshooting I found that I was missing msvcp71.dll on the new Windows Server 2003 SP2 installation. Copying it over from the \windows\system32 folder of another of our servers (one that's currently running the same OS/Python/DB XML setup) to the system folder of the new server seems to have solved the problem.
    I haven't been able to find useful info on msvcp71.dll and this issue generally. I noticed that the new Windows server does have a msvcr71.dll in the system folder but I don't know if they're related. I'm just going with what worked for me. But I have two questions/suggestions:
    1. If there is a better approach than what I've done, please post it.
    2. The install.txt file in C:\Program Files\Oracle\Berkeley DB XML 2.4.16\python doesn't mention the msvcp71.dll dependency -- if others might encounter the problem I did, how about mentioning it there to save them some trouble?
    Tim

    Tim,
    msvcp71.dll is the runtime for the STL (standard template library) and is obviously required. Assuming you have installed the Windows Binaries, that file is supposed to be included in that distribution. What msvc* files can you see in the C:\Program Files\Oracle\Berkeley DB XML 2.4.16\bin directory (this is where it should be)?
    What you have done is safe but should not have been necessary if your PATH is correct and the library is installed.
    Regards,
    George

  • How to define interface builder outlets in Cocoa-Python?

    Hi,
    I am writing a Cocoa-Python application but I couldn't find a way to define outlets in Python code that I can use in the Interface Builder. Of course I know how to do that in Objective-C and this doc http://developer.apple.com/documentation/Cocoa/Conceptual/RubyPythonCocoa/Articl es/BuildingRubyCocoaAppl.html explains how to create outlets in Ruby, but what about Python?
    Thanks in advance,
    Ganesh

    I found it out myself. You have to write
    class MyClass(NSObject):
      outletName = objc.IBOutlet('outletName')
      def foo(self):
        # etc.
    Thanks anyway,
    Ganesh

  • Image file upload code

    Hi,
    I'm trying to track down where, i.e. by which code, image files are saved into the wiki.
    I've traced the route to the wiki.js file which creates the dialogue that posts the form to the server but I've run into a wall.
    I can't establish the name of the 'action' for the form.
    Nor can I infer which python code is receiving it.
    Can anyone help?
    p.s. The reason for all this is that I want uploaded files to be namable, either manually or driven by a field in the form.
    I guess this may involve rewriting some Python and I know that this is frowned upon but the look-out is mine!
    p.p.s. It would also be nice to know where dialogManager() is defined, that's got me beaten at the moment.

    John Anderson1 wrote:
    Remember that, when changing the code, you should override the code using your own theme; don't change it directly. Changing the uncompressed JavaScript won't work anyway; the server sends out code-compressed scripts whenever possible. Changing source code maintained by automatic software updates is the first of many steps down the path toward a bricked server.
    Yes, I'm starting to get a hang of this (I think) I do intend to override the js, it's just I need to know how it's doing it in order to overrride it!
    The form's "action" is "images"
    I'd sort of deduced this but I can't find the code on the server that implements it. I did a quick search and couldn't find "images' in Python and deduced I was being a bit simplistic.
    and dialogManager is defined in widgets.js:
    var ModalDialogManager = Class.createWithSharedInstance('dialogManager');
    Ah, thanks, I'll follow it up.
    You do know that you can just name the file in the Finder before uploading it, right?
    Not really. Under certain circumstances I want teamsserver to save the image file, in the page's image folder, with a particular name, i.e. NOT 123456.gif but pageImage.gif. I recognise that one has the potential problem of duplicate filenames but I'm happy to overwrite existing files AND I'm quite happy for teamsserver to give the file a unique name (presumably for internal database purposes) and make a duplicate of the numbered filename. i.e. save 123456.gif as per normal and then, if some condition is met (e.g. the alt name == pageimage) save a copy as pageImage.gif
    (If you're interested, I've managed to get search to take an additional parameter xslFile=1...5 which selects alternate search.xsl files that return different search layouts. One of which substitutes page specific images instead of the generic 'snowflake' image in search listings. Currently I have to give each page a tag that specifies what the pageImage uid is, but this is wasteful as every tag in every page is therefore different. What I'm trying to do now is make the pageImage filename consistent so that I have a single tag that indicates every page that has an associated image. (The custom search.xsl files recognise if a page HAS a custom image and uses the snowflake if it doesn't)
    Basically it allows me to generate slightly more attractive listings - nothing big but nice for my 'list of published books' page. Vanity, vanity)
    Thanks for hte help. I'll follow it up tomorrow.

  • Python vs Java - simple benchmark comparison

    Hi all,
    I recently posted a speed comparison of Python vs Java.
    Following Xentac's suggestion, I imported Psyco to see if I could get any JIT benefits in the Python scripts. I then tried the latested Java JDK6 dev binaries too. This follow-up can be found here.
    Please be aware that I'm totally aware of the vast limitations of micro-benchmarks like these. Still, although they are based on someone else's code, I like them because they represent the typical tasks I often carry out in both my Python and Java programming: IO, lists, hashes, for loops, etc.
    Any comments welcome, especially on how to optimise the Python code. I can already see a couple of ways that ought to improve the Java tests.

    I agree. I honestly am not trying to say that Java is better and Python is rubbish. I love em both. There's not a great deal of difference for the most part.
    I just felt that people assumed that Java was slow because they've heard it's slow, or had prior experience of the old versions.
    I have friend's saying "ugh, Java is sloowwww." And so avoid it. Yet, these same people rave about Perl and Python apps. My point was simply, hate Java for other reasons - not speed!
    You may notice that the Java executable is only 63K. The bulk of Java comes from its extensive class library that ships with the runtime. People think that Java must load up all the classes or something before running, when in fact it only ever loads with it needs. So, whilst the package itself is large, any sure, it does require more memory than other languages, I just don't believe it's as bulky as some assume.
    The motivation for those benchmarks was a comment on Frugalware's IRC channel where someone tried it out, said it was slow, removed it, and preferred the Python/gtk front-end they have instead. Followed with some insightful remark that Java only for web apps! I don't mind others prefering other front-ends. But is Jacman really slow? Please tell me, because it runs like a dream on my system. It would go even quicker if with pacman-optimize.

Maybe you are looking for