0001 ### BITPIM 0002 ### 0003 ### Copyright (C) 2006 Joe Pham <djpham@bitpim.org> 0004 ### 0005 ### This program is free software; you can redistribute it and/or modify 0006 ### it under the terms of the BitPim license as detailed in the LICENSE file. 0007 ### 0008 ### $Id: field_color.py 4693 2008-08-15 22:30:51Z djpham $ 0009 0010 """ 0011 Code to handle setting colors for fields in various BitPim Editor Dialogs. 0012 The idea is to show which fields are supported by the current phone model, 0013 which fields are not, and which fields are unknown (default). 0014 0015 To use/enable this feature for your phone, define a dict value in your phone 0016 profile that specifies the applicability of various fields. It's probably best 0017 if you copy the default_field_info dict to your phone profile and set 0018 appropriate values. The value of each key can be either: 0019 None (don't know), 0020 True (applicable), 0021 False (not applicable), 0022 0 (not applicable), 0023 int>0 (number of entries this phone can have). 0024 0025 The name of this dict is 'field_color_data'. An example is included in module 0026 com_lgvx9800. 0027 0028 """ 0029 0030 import wx 0031 0032 applicable_color=wx.BLUE 0033 notapplicable_color=wx.RED 0034 dunno_color=wx.BLACK 0035 0036 default_field_info={ 0037 'phonebook': { 0038 'name': { 0039 'first': None, 'middle': None, 'last': None, 'full': None, 0040 'nickname': None }, 0041 'number': { 0042 'type': None, 'speeddial': None, 'number': None, 0043 'ringtone': None, 'wallpaper': None }, 0044 'email': None, 0045 'email_details': { 0046 'emailspeeddial': None, 'emailringtone': None, 0047 'emailwallpaper': None }, 0048 'address': { 0049 'type': None, 'company': None, 'street': None, 'street2': None, 0050 'city': None, 'state': None, 'postalcode': None, 'country': None }, 0051 'url': None, 0052 'memo': None, 0053 'category': None, 0054 'wallpaper': None, 0055 'ringtone': None, 0056 'storage': None, 0057 'secret': None, 0058 'ICE': None, 0059 }, 0060 'calendar': { 0061 'description': None, 'location': None, 'allday': None, 0062 'start': None, 'end': None, 'priority': None, 0063 'alarm': None, 'vibrate': None, 0064 'repeat': None, 0065 'memo': None, 0066 'category': None, 0067 'wallpaper': None, 0068 'ringtone': None, 0069 }, 0070 'memo': { 0071 'subject': None, 0072 'date': None, 0073 'secret': None, 0074 'category': None, 0075 'memo': None, 0076 }, 0077 'todo': { 0078 'summary': None, 0079 'status': None, 0080 'due_date': None, 0081 'percent_complete': None, 0082 'completion_date': None, 0083 'private': None, 0084 'priority': None, 0085 'category': None, 0086 'memo': None, 0087 }, 0088 } 0089 0090 current_field_info=default_field_info 0091 0092 0093 def build_field_info(widget, name=None): 0094 """Return the dict info for this widget 0095 """ 0096 global current_field_info 0097 _parent=widget.GetParent() 0098 if name: 0099 _names=[name] 0100 else: 0101 _names=[] 0102 while _parent: 0103 if hasattr(_parent, 'color_field_name'): 0104 _names.append(_parent.color_field_name) 0105 _parent=_parent.GetParent() 0106 _names.reverse() 0107 _dict=current_field_info 0108 for n in _names: 0109 if not _dict.has_key(n): 0110 _dict[n]={} 0111 _dict=_dict[n] 0112 return _dict 0113 0114 def get_children_count(widget): 0115 """Return the number of sibblings to this widget 0116 """ 0117 _parent=widget.GetParent() 0118 _cnt=0 0119 if _parent: 0120 for _w in _parent.GetChildren(): 0121 if isinstance(_w, widget.__class__): 0122 _cnt+=1 0123 return _cnt 0124 0125 def get_color_info_from_profile(widget): 0126 """Walk up the widget chain to find the one that has the phone profile 0127 """ 0128 global current_field_info 0129 current_field_info=default_field_info 0130 _w=widget.GetParent() 0131 while _w: 0132 if hasattr(_w, 'phoneprofile'): 0133 # found it 0134 current_field_info=_w.phoneprofile.field_color_data 0135 return 0136 _w=_w.GetParent() 0137 0138 def color(widget, name, tree=None): 0139 """Return the appropriate color for this field 0140 """ 0141 global current_field_info, default_field_info 0142 if tree: 0143 _dict=tree 0144 else: 0145 # need to build the field info dict 0146 _dict=build_field_info(widget) 0147 _val=_dict.get(name, None) 0148 _cnt=get_children_count(widget) 0149 if _val is None: 0150 if current_field_info==default_field_info: 0151 return dunno_color 0152 else: 0153 return notapplicable_color 0154 elif _val is False or not isinstance(_val, bool) and _cnt>_val: 0155 return notapplicable_color 0156 else: 0157 return applicable_color 0158 0159 def build_color_field(widget, klass, args, name, tree=None): 0160 """ 0161 instantiate the widget, set the color, and return the widget 0162 """ 0163 _w=klass(*args) 0164 if _w: 0165 _w.SetForegroundColour(color(widget, name, tree)) 0166 return _w 0167 0168 def reload_color_info(widget, widgets): 0169 get_color_info_from_profile(widget) 0170 _fc_dict=build_field_info(widget, widget.color_field_name) 0171 for (_w, name) in widgets: 0172 _w.SetForegroundColour(color(_w, name, _fc_dict)) 0173 0174
Generated by PyXR 0.9.4