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

Source Code for Module field_color

  1  ### BITPIM 
  2  ### 
  3  ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 
  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: field_color.py 4775 2010-01-04 03:44:57Z djpham $ 
  9   
 10  """ 
 11  Code to handle setting colors for fields in various BitPim Editor Dialogs. 
 12  The idea is to show which fields are supported by the current phone model, 
 13  which fields are not, and which fields are unknown (default). 
 14   
 15  To use/enable this feature for your phone, define a dict value in your phone 
 16  profile that specifies the applicability of various fields.  It's probably best 
 17  if you copy the default_field_info dict to your phone profile and set 
 18  appropriate values.  The value of each key can be either: 
 19  None (don't know), 
 20  True (applicable), 
 21  False (not applicable), 
 22  0 (not applicable), 
 23  int>0 (number of entries this phone can have). 
 24   
 25  The name of this dict is 'field_color_data'.  An example is included in module 
 26  com_lgvx9800. 
 27   
 28  """ 
 29   
 30  import wx 
 31   
 32  applicable_color=wx.BLUE 
 33  notapplicable_color=wx.RED 
 34  dunno_color=wx.BLACK 
 35   
 36  default_field_info={ 
 37      'phonebook': { 
 38          'name': { 
 39              'first': None, 'middle': None, 'last': None, 'full': None, 
 40              'nickname': None }, 
 41          'number': { 
 42              'type': None, 'speeddial': None, 'number': None, 
 43              'ringtone': None, 'wallpaper': None }, 
 44          'email': None, 
 45          'email_details': { 
 46              'emailspeeddial': None, 'emailringtone': None, 
 47              'emailwallpaper': None }, 
 48          'address': { 
 49              'type': None, 'company': None, 'street': None, 'street2': None, 
 50              'city': None, 'state': None, 'postalcode': None, 'country': None }, 
 51          'url': None, 
 52          'memo': None, 
 53          'category': None, 
 54          'wallpaper': None, 
 55          'ringtone': None, 
 56          'storage': None, 
 57          'secret': None, 
 58          'ICE': None, 
 59          'im': None, 
 60          }, 
 61      'calendar': { 
 62          'description': None, 'location': None, 'allday': None, 
 63          'start': None, 'end': None, 'priority': None, 
 64          'alarm': None, 'vibrate': None, 
 65          'repeat': None, 
 66          'memo': None, 
 67          'category': None, 
 68          'wallpaper': None, 
 69          'ringtone': None, 
 70          }, 
 71      'memo': { 
 72          'subject': None, 
 73          'date': None, 
 74          'secret': None, 
 75          'category': None, 
 76          'memo': None, 
 77          }, 
 78      'todo': { 
 79          'summary': None, 
 80          'status': None, 
 81          'due_date': None, 
 82          'percent_complete': None, 
 83          'completion_date': None, 
 84          'private': None, 
 85          'priority': None, 
 86          'category': None, 
 87          'memo': None, 
 88          }, 
 89      } 
 90   
 91  current_field_info=default_field_info 
 92   
 93   
94 -def build_field_info(widget, name=None):
95 """Return the dict info for this widget 96 """ 97 global current_field_info 98 _parent=widget.GetParent() 99 if name: 100 _names=[name] 101 else: 102 _names=[] 103 while _parent: 104 if hasattr(_parent, 'color_field_name'): 105 if _parent.color_field_name not in _names: 106 _names.append(_parent.color_field_name) 107 _parent=_parent.GetParent() 108 _names.reverse() 109 _dict=current_field_info 110 for n in _names: 111 if not _dict.has_key(n): 112 _dict[n]={} 113 _dict=_dict[n] 114 return _dict
115
116 -def get_children_count(widget):
117 """Return the number of sibblings to this widget 118 """ 119 _parent=widget.GetParent() 120 _cnt=0 121 if _parent: 122 for _w in _parent.GetChildren(): 123 if isinstance(_w, widget.__class__): 124 _cnt+=1 125 return _cnt
126
127 -def get_color_info_from_profile(widget):
128 """Walk up the widget chain to find the one that has the phone profile 129 """ 130 global current_field_info 131 current_field_info=default_field_info 132 _w=widget.GetParent() 133 while _w: 134 if hasattr(_w, 'phoneprofile'): 135 # found it 136 current_field_info=_w.phoneprofile.field_color_data 137 return 138 _w=_w.GetParent()
139
140 -def color(widget, name, tree=None):
141 """Return the appropriate color for this field 142 """ 143 global current_field_info, default_field_info 144 if tree: 145 _dict=tree 146 else: 147 # need to build the field info dict 148 _dict=build_field_info(widget) 149 _val=_dict.get(name, None) 150 _cnt=get_children_count(widget) 151 if _val is None: 152 if current_field_info==default_field_info: 153 return dunno_color 154 else: 155 return notapplicable_color 156 elif _val is False or not isinstance(_val, bool) and _cnt>_val: 157 return notapplicable_color 158 else: 159 return applicable_color
160
161 -def build_color_field(widget, klass, args, name, tree=None):
162 """ 163 instantiate the widget, set the color, and return the widget 164 """ 165 _w=klass(*args) 166 if _w: 167 _w.SetForegroundColour(color(widget, name, tree)) 168 return _w
169
170 -def reload_color_info(widget, widgets):
171 get_color_info_from_profile(widget) 172 _fc_dict=build_field_info(widget, widget.color_field_name) 173 for (_w, name) in widgets: 174 _w.SetForegroundColour(color(_w, name, _fc_dict))
175