Attachment 'models.py'

Download

   1 default_official_url = 'http://www.wxpython.org/docs/api/'
   2 default_official_url += 'wx.CLASSNAME-class.html'
   3 default_sphinx_url = 'http://xoomer.virgilio.it/infinity77/wxPython/Widgets/'
   4 default_sphinx_url += 'wx.CLASSNAME.html'
   5 default_widgets_url = 'http://docs.wxwidgets.org/stable/'
   6 default_widgets_url += 'wx_wxCLASSNAME.html#wxCLASSNAME'
   7 
   8 
   9 USE_DEFAULT = 1
  10 
  11 
  12 class wxFeature:
  13 
  14     banner_shade = '#FFFFFF'
  15     indent = 0
  16 
  17     def __init__(self, name, official_url=USE_DEFAULT,
  18                              sphinx_url=USE_DEFAULT,
  19                              widgets_url=USE_DEFAULT):
  20 
  21         self.name = name
  22         self.description = ''
  23         self.notes = []
  24 
  25         self.official_url = official_url if official_url else None
  26         self.sphinx_url = sphinx_url if sphinx_url else None
  27         self.widgets_url = widgets_url if widgets_url else None
  28 
  29         self.indent = self.indent * ' '
  30 
  31     def get_official_url(self):
  32         pass
  33 
  34     def get_sphinx_url(self):
  35         pass
  36 
  37     def get_widgets_url(self):
  38         pass
  39 
  40     def wikify_url(self, url, label):
  41         return '[[' + url + '|' + label + ']]'
  42 
  43     def link_urls(self, urls):
  44         return ' - '.join(urls)
  45 
  46     def url_str(self):
  47         urls = [(self.get_official_url(), 'wxPython'),
  48                 (self.get_sphinx_url(), 'Sphinx'),
  49                 (self.get_widgets_url(), 'wxWidgets')]
  50         urls = [url for url in urls if url[0] is not None]
  51         urls = [self.wikify_url(*url) for url in urls]
  52         return self.link_urls(urls)
  53 
  54     def title_str(self):
  55 
  56         return "~+'''{{{" + self.name + "}}}'''+~"
  57 
  58     def banner_str(self):
  59         s = '||<tablewidth="100%" width="40%" bgcolor="'
  60         s += self.banner_shade + '">' + self.title_str()
  61         s += '||<) ' + self.banner_shade + '>'
  62         s += self.url_str() + '||\n'
  63         return s
  64 
  65 
  66 class wxClass(wxFeature):
  67 
  68     banner_shade = '#BBBBBB'
  69     indent = 1
  70 
  71     def __init__(self, name, official_docs=USE_DEFAULT,
  72                              sphinx_docs=USE_DEFAULT,
  73                              widget_docs=USE_DEFAULT):
  74         wxFeature.__init__(self, name, official_docs, sphinx_docs,
  75                                                             widget_docs)
  76         self.name = self.name
  77         self.events = []
  78         self.methods = []
  79         self.notes = []
  80 
  81     def get_url(self, source):
  82         if self.__dict__[source] != USE_DEFAULT:
  83             return self.__dict__[source]
  84 
  85         name = self.name
  86         if source == 'widgets_url':
  87             name = name.lower()
  88 
  89         template = eval('default_' + source)
  90         if source == 'sphinx_url' and 'event' in name.lower():
  91             template = template.replace('/Widgets/', '/Events/')
  92 
  93         return template.replace('CLASSNAME', name)
  94 
  95     def get_official_url(self):
  96         return self.get_url('official_url')
  97 
  98     def get_sphinx_url(self):
  99         return self.get_url('sphinx_url')
 100 
 101     def get_widgets_url(self):
 102         return self.get_url('widgets_url')
 103 
 104     def title_str(self):
 105         return "~+'''{{{wx." + self.name + "}}}'''+~"
 106 
 107     def toc_str(self):
 108         return '[[#' + self.name + '|' + self.name + ']]'
 109 
 110     def anchor_str(self):
 111         return '<<Anchor(' + self.name + ')>>'
 112 
 113     def __str__(self):
 114         s = self.anchor_str() + '\n'
 115         s += self.banner_str() + '\n'
 116         description = ''
 117         if self.description:
 118             description = self.indent + self.description
 119         events = ''
 120         if self.events:
 121             events = self.indent + "'''Events:''' "
 122             events += '~-' + ', '.join(self.events) + '-~'
 123         notes = ''
 124         if self.notes:
 125             notes = self.indent + "'''Notes:'''"
 126             for note in self.notes:
 127                 notes += '\n' + self.indent + ' *' + note 
 128         blurbits = [description, events, notes]
 129         blurbits = [b for b in blurbits if b]
 130         if blurbits:
 131             s += '<<BR>>\n'.join(blurbits) + '<<BR>>\n'
 132         for m in self.methods:
 133             s += str(m) + '\n'
 134         s += "||~-[[#Top|Back to Top]]-~||\n"
 135         return s
 136 
 137 
 138 class wxMethod(wxFeature):
 139 
 140     banner_shade = '#DDDDDD'
 141     indent = 2
 142 
 143     def __init__(self, name, wxclass, official_url=USE_DEFAULT,
 144                              sphinx_url=USE_DEFAULT,
 145                              widgets_url=USE_DEFAULT):
 146         wxFeature.__init__(self, name, official_url, sphinx_url,
 147                                                        widgets_url)
 148         self.wxclass = wxclass
 149         self.args = []
 150         self.args_of_interest = []
 151         self.styles = []
 152         self.default_styles = []
 153         wxclass.methods.append(self)
 154 
 155     def add_args(self, *args):
 156         self.args += args
 157 
 158     def get_official_url(self):
 159         if self.official_url is None:
 160             return None
 161         official = self.wxclass.get_official_url()
 162         if not official:
 163             return official
 164         else:
 165             return official + '#' + self.name
 166 
 167     def get_sphinx_url(self):
 168         if self.sphinx_url is None:
 169             return None
 170         sphinx = self.wxclass.get_sphinx_url()
 171         if not sphinx:
 172             return sphinx
 173         else:
 174             return sphinx + '#' + self.name
 175 
 176     def get_widgets_url(self):
 177         if self.widgets_url is None:
 178             return None
 179         widgets = self.wxclass.get_widgets_url()
 180         if not widgets:
 181             return widgets        
 182         if self.name == '__init__':
 183             name = 'ctor'
 184         else:
 185             name = self.name
 186         return widgets + name.lower()
 187 
 188     def args_str(self):
 189         argstrings = []
 190         for argstr in self.args:
 191             argstr = '{{{' + argstr + '}}}'
 192             for aoi in self.args_of_interest:
 193                 if aoi in argstr:
 194                     argstr = "'''" + argstr + "'''"
 195                     break
 196             argstrings.append(argstr)
 197         return '(' + ', '.join(argstrings) + ')'
 198 
 199     def link_urls(self, urls):
 200         return '~-' + '<<BR>>'.join(urls) + '-~'
 201 
 202     def banner_str(self):
 203         s = ' ||<tablewidth="100%"' + self.banner_shade + ' 1%>'
 204         s += self.title_str()
 205         s += "||<( " + self.banner_shade + ' width="80%">' + self.args_str()
 206         s += "||<) " + self.banner_shade + ' width="20%">' + self.url_str() + '||\n'
 207         return s
 208 
 209     def __str__(self):
 210         s = self.banner_str() + '\n'
 211         s += self.indent + self.description + '\n'
 212         if self.styles:
 213             s += self.indent + "'''Styles: '''"
 214             styles = []
 215             for style in self.styles:
 216                 if style in self.default_styles:
 217                     styles.append(style + '*')
 218                 else:
 219                     styles.append(style)
 220             s += '~-' + ', '.join(styles) + '-~<<BR>>\n'
 221         if self.notes:
 222             for i in range(len(self.notes)):
 223                 s += self.indent
 224                 s += '~-note' + str(i + 1) + ': ' + self.notes[i] + '-~<<BR>>\n'
 225 
 226         return s

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-07-14 17:57:12, 33.3 KB) [[attachment:cheat_sheet.xml]]
  • [get | view] (2013-07-09 15:32:33, 6.8 KB) [[attachment:models.py]]
  • [get | view] (2013-07-14 17:56:55, 5.4 KB) [[attachment:xml_parser.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.