You Are Here:

Community: Developer Discussion Boards

#1 Old Post Canvas callbacks - 2006-07-02, 21:51

Join Date: Sep 2003
Posts: 11
directx
Offline
Registered User
Hi!
Could someone please take a look at the following code and explain to me why this script crashes after the socket.bt_discover() call?

I suspect canvas callbacks but cannot pinpoint the problem. It's probably something very obvious but since I am new to Python on Symbian I cannot see the problem.
Thank you in advance for any helpful information.


[code]
import sys
import e32
import socket
import appuifw

e32.ao_yield()

class KeyboardHandler(object):
def __init__(self, onevent_callback = lambda event:None):
self._keyboard_state = {}
self._downs = {}
self._onevent_callback = onevent_callback

def set__onevent_callback(self, callback):
self._onevent_callback = callback

def handle_event(self, event):
if event['type'] == appuifw.EEventKeyDown:
code = event['scancode']
if not self.is_down(code):
self._downs[code] = self._downs.get(code,0)+1
self._keyboard_state
Code:
 = 1
        elif event['type'] == appuifw.EEventKeyUp:
            self._keyboard_state[event['scancode']] = 0
        self._onevent_callback(event)
        
    def is_down(self, scancode):
        return self._keyboard_state.get(scancode, 0)
        
    def pressed(self,scancode):
        if self._downs.get(scancode, 0):
            self._downs[scancode] -= 1
            return True
        return False


class CanvasHandler(object):
    def __init__(self, refresh_callback = lambda rect:None):
        self._refresh_callback = refresh_callback

    def set__refresh_callback(self, callback):
        self._refresh_callback = callback

    def refresh(self, rect):
        self._refresh_callback(rect)


class Application:
    def __init__(self, keyboard_handler, canvas_handler):
        self.lock = e32.Ao_lock()
        
        self.old_title = appuifw.app.title
        appuifw.app.title = u"Application"
        
        self.exit_flag = False
        appuifw.app.exit_key_handler = self.abort
        
        self._canvas = appuifw.Canvas(event_callback = keyboard_handler.handle_event,
                                      redraw_callback = canvas_handler.refresh)  

        appuifw.app.screen = 'normal'
        appuifw.app.body = self._canvas
        
        address,services = socket.bt_discover()

    def event_callback(self, event):
        self.refresh_callback(None)
 
    def refresh_callback(self, rect):
        self._canvas.clear()
        
    def loop(self):
        try:
            while not self.exit_flag:
                self.refresh_callback(None)
                self.lock.wait()
        finally:
            pass
        
    def update(self):
        self.lock.signal()    
        
    def close(self):
        appuifw.app.menu = []
        appuifw.app.body = None
        appuifw.app.exit_key_handler = None
        appuifw.app.title = self.old_title

    def abort(self):
        # Exit-key handler.
        self.exit_flag = True
        self.lock.signal()

       
def main():   
    keyboard_handler = KeyboardHandler()
    canvas_handler = CanvasHandler();
             
    app = Application(keyboard_handler, canvas_handler)
    
    keyboard_handler.set__onevent_callback(app.event_callback)
    canvas_handler.set__refresh_callback(app.refresh_callback)
    
    try:
        app.loop()
    finally:
        app.close()

if __name__ == "__main__":
    main()
Reply With Quote

#2 Old Re: Canvas callbacks - 2006-07-04, 16:35

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
This snippet can be found on ORG PyBluez v0.7 (http://org.csail.mit.edu/pybluez/) documentation:

Quote:
A note on working with Symbian smartphones:
bt_discover in Python for Series 60 will only detect service records
with service class SERIAL_PORT_CLASS and profile SERIAL_PORT_PROFILE
When selecting a device which does not possess these records, socket.bt_discover() raises a confusing and nondescript exception:

Code:
... line 64, in __init__
    address,services = socket.bt_discover()
error: (2, 'No such file or directory')
The script works fine when the target device correctly advertises having a serial port profile (tested with Nokia 6600 and a Linux PC).
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a partly transparent Canvas to lay on top of another Canvas? mkleijer Mobile Java Media (Graphics & Sounds) 4 2007-05-22 08:00
Canvas doesn't show when getWidth/getHeight is used claudio4j Mobile Java Media (Graphics & Sounds) 2 2003-11-05 09:41
Major problem with delegation to Canvas bartekn Mobile Java Media (Graphics & Sounds) 8 2003-10-08 18:46
7650 and 3650 Canvas and FullCanvas memory marcilgen Mobile Java General 5 2003-07-08 13:24
Larger canvas? bjajo780 Mobile Java General 1 2002-06-18 15:17

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ