3+

2014-09-12から1日間の記事一覧

QTreeWidget example

ツリー構造のリストを、割りと簡単に作るサンプル。 タプルのリストからツリーアイテムを作る。タプル(k,v,n)の構造は、 k:ノードの名前 v:ノードの値 n:子ノード(のリスト) 以下ソース。 #!/usr/bin/env python # -*- coding: utf-8 -*- import sys, os, pp…

;(function(document){ var pres = document.getElementsByTagName("pre") for(var i=pres.length; i--; ){  var el = makeOl(pres[i]) pres[i].appendChild(el) } function makeOl(pre){ var ol = document.createElement("ol") , li = document.createElement("li") , df = document.createDocumentFragment() , br = pre.innerHTML.match(/\n/g) || 0 ol.className = "preLine" ol.setAttribute("role", "presentation") // no lang, no line-number if( pre.className && ! /lang-./.test(pre.className) ){ br.length += 1 } for(var i=br.length; i--; ){ var li2 = li.cloneNode(true) df.appendChild(li2) } ol.appendChild(df) return ol } })(document)