Module pubsub
[hide private]
[frames] | no frames]

Source Code for Module pubsub

 1  ### BITPIM 
 2  ### 
 3  ### Copyright (C) 2003-2004 Roger Binns <rogerb@rogerbinns.com> 
 4  ### 
 5  ### This program is free software; you can redistribute it and/or modify 
 6  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
 7  ### 
 8  ### $Id: pubsub.py 4768 2009-11-06 02:17:29Z hjelmn $ 
 9   
10   
11  """The publish subscribe mechanism used to maintain lists of stuff. 
12   
13  This helps different pieces of code maintain lists of things (eg 
14  wallpapers, categories) and other to express and interest and be 
15  notified when it changes (eg field editors).  The wxPython pubsub 
16  module is the base.  The enhancements are a list of standard topics in 
17  this file. 
18   
19  This code also used to be larger as the wxPython pubsub didn't use 
20  weak references.  It does now, so a whole bunch of code could be 
21  deleted. 
22  """ 
23   
24  from wx.lib.pubsub import Publisher 
25   
26   
27  ### 
28  ### A list of topics 
29  ### 
30   
31   
32  # Maintain the list of categories 
33  REQUEST_GROUP_WALLPAPERS=( 'request', 'groupwps') # no data 
34  GROUP_WALLPAPERS=( 'response', 'groupwps' ) # data is list of groups and their wallpapers 
35  SET_GROUP_WALLPAPERS=( 'request', 'setgroupwps') # data is list of groups and their wallpapers 
36  MERGE_GROUP_WALLPAPERS=( 'request', 'mergegroupwps') # data is list of groups and their wallpapers 
37  REQUEST_CATEGORIES=( 'request', 'categories' ) # no data 
38  ALL_CATEGORIES=( 'response', 'categories') # data is list of strings 
39  SET_CATEGORIES=( 'request', 'setcategories') # data is list of strings 
40  ADD_CATEGORY=( 'request', 'addcategory') # data is list of strings 
41  MERGE_CATEGORIES=( 'request', 'mergecategories') # data is list of strings 
42  ALL_WALLPAPERS=( 'response', 'wallpapers') # data is list of strings 
43  REQUEST_WALLPAPERS=( 'request', 'wallpapers') # no data 
44  ALL_RINGTONES=( 'response', 'ringtones' ) # data is list of strings 
45  REQUEST_RINGTONES=( 'request', 'ringtones') # no data 
46  PHONE_MODEL_CHANGED=( 'notification', 'phonemodelchanged') # data is phone module 
47  REQUEST_RINGTONE_INDEX=('request', 'ringtone-index') # no data 
48  ALL_RINGTONE_INDEX=('response', 'ringtone-index') # data is the ringtone-index dict 
49  REQUEST_PB_LOOKUP=('request', 'phonebook') # Request to lookup a number 
50  RESPONSE_PB_LOOKUP=('response', 'phonebook') # Response to the request 
51  MEDIA_NAME_CHANGED=('notificaion', 'medianamechanged') # notify if name changed 
52  REQUEST_TAB_CHANGED=('notification', 'tabchanges') # request to change the main tab 
53  TODAY_ITEM_SELECTED=('notification', 'todayitemselected') # a Today item was selected 
54  REQUEST_TODAY_DATA=('request', 'todaydata') # request data for Today page 
55  RESPONSE_TODAY_DATA=('response', 'todaydata') # reponse data for Today page 
56  NEW_DATA_AVAILABLE=('notification', 'dataavailable') # new data available 
57  MIDNIGHT=('notification', 'midnight')   # midnight had passed 
58  DR_RECORD=('notification', 'recorddata')    # DR On 
59  DR_PLAY=('notification', 'playdata')        # DR Playback 
60  DR_STOP=('notification', 'stop')            # DR stop 
61  REQUEST_MEDIA_INFO=('request', 'mediainfo')     # Request media item description 
62  RESPONSE_MEDIA_INFO=('response', 'mediainfo')   # Response: list of strings (lines) 
63  REQUEST_MEDIA_OPEN=('request', 'mediaopen')  # Request to open/launch a media item 
64   
65  # MEDIA_NAME_CHANGED keys & types 
66  media_change_type='type' 
67  wallpaper_type='wallpaper' 
68  ringtone_type='ringtone' 
69  media_old_name='old_name' 
70  media_new_name='new_name' 
71   
72 -def subscribe(listener, topic):
73 Publisher.subscribe(listener, topic)
74
75 -def unsubscribe(listener):
76 Publisher.unsubscribe(listener)
77
78 -def publish(topic, data=None):
79 Publisher.sendMessage(topic, data)
80