~jbernard/acire/depend-python-mechanize

« back to all changes in this revision

Viewing changes to bin/acire

  • Committer: Jono Bacon
  • Date: 2010-03-20 22:57:40 UTC
  • Revision ID: jono@forge-20100320225740-z6mjl59cddcza583
Added a documentation feature to provide documentation links.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import pango
27
27
import webbrowser
28
28
import gconf
 
29
from mechanize import Browser
29
30
import tempfile     #Used in run_snippet to run user-modded snippet
30
31
###Needed to check for GTK version, gtk.FileChooserDialog available, see save_snippet()
31
32
import pygtk
86
87
 
87
88
        #code for other initialization actions should be added here
88
89
 
 
90
        # browser for grabbing docs titles
 
91
        self.browser = Browser()
 
92
 
89
93
        # references to glade widgets
90
94
 
91
95
        self.editor_viewport = self.builder.get_object("editor_viewport")
99
103
        self.terminal_scroll = self.builder.get_object("terminal_scroll")
100
104
        self.terminal_expander = self.builder.get_object("terminal_expander")
101
105
        self.status_label = self.builder.get_object("status_label")
 
106
        self.docs_box = self.builder.get_object("docs_box")
102
107
        
103
108
        # set up source view
104
109
        
239
244
        self.editor_buffer.set_data('filename', self.current_filename)
240
245
        self.editor_view.show()
241
246
        self.editor_buffer.set_modified(False)  #Reqd for check in run_snippet()
 
247
 
 
248
        self.editor_viewport.show_all()
 
249
 
 
250
        # update snippet information
242
251
                    
243
252
        self.location_label.set_text(self.current_filename)
244
253
        self.description_label.set_text(self.snippetsdata[self.current_filename]["description"])
245
254
 
246
 
        self.editor_viewport.show_all()
 
255
        # update docs
 
256
 
 
257
        ## first delete any existing docs buttons:
 
258
 
 
259
        kids = self.docs_box.get_children()
 
260
 
 
261
        for k in kids:
 
262
            k.destroy()
 
263
 
 
264
        if "docs" in self.snippetsdata[self.current_filename]:
 
265
            docslist = self.snippetsdata[self.current_filename]["docs"].split(',')
 
266
 
 
267
            for d in docslist:
 
268
                url = d.lstrip().rstrip()
 
269
                self.browser.open(url)
 
270
                title = self.browser.title()
 
271
 
 
272
                docsbutton = gtk.LinkButton(url, title)
 
273
                docsbutton.set_alignment(0, 0)
 
274
                docsbutton.show()
 
275
 
 
276
                self.docs_box.add(docsbutton)
 
277
                self.docs_box.set_child_packing(docsbutton, False, False, 0, gtk.PACK_START)
 
278
        else:
 
279
            docsbutton = gtk.LinkButton("http://wiki.ubuntu.com/PythonSnippets", _("Click to here to add documentaton for this snippet."))
 
280
            docsbutton.set_alignment(0, 0)
 
281
            docsbutton.show()
 
282
 
 
283
            self.docs_box.add(docsbutton)
 
284
            self.docs_box.set_child_packing(docsbutton, False, False, 0, gtk.PACK_START)
 
285
 
 
286
        self.docs_box.show()
247
287
 
248
288
    def run_snippet(self, widget, data=None):
249
289
        """Run the currently selected snippet"""
342
382
        """Scan snippets files for meta data."""
343
383
        
344
384
        for f in self.snippetsfiles:
345
 
            print f
346
385
            file_object = open(f)
347
386
 
348
387
            try:
360
399
                name = re.search(r'\[SNIPPET_NAME: (.*?)]', l)
361
400
                cats = re.search(r'\[SNIPPET_CATEGORIES: (.*?)]', l)    
362
401
                description = re.search(r'\[SNIPPET_DESCRIPTION: (.*?)]', l)
 
402
                docs = re.search(r'\[SNIPPET_DOCS: (.*?)]', l)
363
403
 
364
404
                if name is not None:
365
405
                    itemdict['name'] = name.groups()[0]
370
410
                if description is not None:
371
411
                    itemdict['description'] = description.groups()[0]
372
412
 
373
 
#            if itemdict:
374
 
#                tempdict['filename'] = f            
 
413
                if docs is not None:
 
414
                    itemdict['docs'] = docs.groups()[0]
 
415
 
375
416
                self.snippetsdata[f] = itemdict
376
417
 
377
418
        self.status_label.set_text(str(len(self.snippetsdata)) + _(" snippets available"))