分类: 技术宅

  • UOItemAssist – UO物品管理工具 v0.8

    UOItemAssist是为了方便的管理和查看Ultima Online(以下简称UO, 网络创世纪)的物品所开发的程序。

    steamworkshop_collection_1397670961_collection_branding
    (更多…)

  • 隐藏QListWidgetItem的checkbox

    本文主要介绍Python下通过设置Qt::CheckStateRole来隐藏勾选框(checkbox)的方式。

    QListWidgetItem设置物品多选的的方法很简单,通过setCheckState()或者setFlags()都可以实现,但是在设置“多选”之后,勾选框就不能通过设置setFlags()来去除Qt::ItemIsUserCheckable的标识。

    根据以下链接的博文说明:
    http://badlyhonedbytes.wordpress.com/2013/03/31/hiding-the-checkbox-of-a-qlistwidgetitem/

    The trick is to use QListWidgetItem::setData() to set the data in the Qt::CheckStateRole to an empty QVariant(). The same method can be used to set the item’s check state.

    只要通过QListWidgetItem::setData()来设置data中的Qt::CheckStateRole为一个空的变量QVariant()即可,在Python中实现方式如下:

    [python]
    from PyQt4 import QtCore, QtGui

    #列出QlistWidget的总行数
    rows = self.listWidget_item.count()

    #读取QlistWidget中的每一行
    for row in xrange(rows):
    #返回所给“行”的物件
    item = self.listWidget_item.item(row)
    #设置Qt::CheckStateRole的值为空
    #的QVariant()变量,10代表Qt::CheckStateRole
    item.setData(10, QtCore.QVariant())
    [/python]

    参考资料
    QListWidgetItem
    http://qt-project.org/doc/qt-4.8/qlistwidgetitem.html
    QVariant
    http://qt-project.org/doc/qt-4.8/qvariant.html#QVariant
    ItemDataRole
    http://qt-project.org/doc/qt-4.8/qt.html#ItemDataRole-enum

  • Python描述符(descriptor)解密,文章地址

    这篇文章解决了困扰我许久的疑问,实在太好了,网上所有的乱七八糟的说明,还不如这个来的完善,直接将文章链接放在最上面。

    原文链接: Chris Beaumont 翻译: 极客范 慕容老匹夫
    译文链接: http://www.geekfan.net/7862/

  • add another MS-Office spelling checker language

    when we install a language MS-Office, we have a language spelling checker by default, but if we  want use another language spelling checker, we must install an language package.

    So here, a simple method in MS-Office 2010 which need a french spelling checker:

    1. check your office  2010 version, 32bits or 64bits?
    2. download the corresponding language package by below link:
      1. 32bits: http://www.microsoft.com/fr-fr/download/details.aspx?id=26616
      2. 64bits: http://www.microsoft.com/fr-fr/download/details.aspx?id=26619
    3. install language package.
    4. select in MS-Office language spelling checker (important)

    for other language or MS-Office version: use your Google search by taping: “MS-Office 2013 french language package”, i’m sure you could find easily the best result.

  • [Fr|法文]维基百科讨论页面的处理手册

    《维基百科讨论页面的处理手册》是从《CoMeRe》的项目《Wikiconflits》整理出来的一份操作手册,它介绍了为何分析,如何从维基百科的DUMP中提取相关页面,并如何分析页面中的Wikitext(维基文本),最后转换成项目要求的最终TEI格式。目前版本V2.0, 在1.0版本上添加了转换TEI的内容。本手册语言为法文。

    手册法文介绍:
    “Wikiconflits, un corpus extrait de Wikipédia : principe et méthode d’élaboration”, Le groupe CoMeRe-nouvelles-acquisitions-Wikipédia vise à constituer un corpus de pages Wikipédia qui sera adjoint au corpus CoMeRe afin d’améliorer sa représentativité. Son choix s’est porté autour de l’observation de pages ayant suscité des discussions conflictuelles autour de controverses dans les champs des sciences et des techniques. Dans une première partie, le groupe explique sa méthode de sélection des discussions conflictuelles. Dans les parties suivantes, le groupe CoMeRe-LRL expose la méthode de constitution du corpus en fonction des critères précédemment retenus et la façon de les transformer en TEI. Ce rapport se termine par la présentation de l’outil WikiTool développé lors des traitements. Mis à disposition sous licence libre il permet d’extraire des pages dans les fichiers de type Dump de Wikipedia.

    CoMeRe网站(法文) http://comere.org/
    下载: cmr-wikiconflits-tei-v2-manuel

  • python 位操作符 左移和右移 运算

    左移和右移N位等同于无溢出检查的2的N次幂运算:2**N
    <<左移 运算规则: 按二进制形式把所有的数字向左移动对应的位数,高位移出(舍弃),低位的空位补零。 语法格式: 需要移位的数字<<移位的位数 例如:3<<2则是将数字3左移动2位 计算过程: 3<<2首先把3转换为二进制数字00000000000000000000000000000011 然后把该数字高位(左侧)的两个零移出,其他的数字都朝左平移2位,最后在低位(右侧) 的连个空位补零。则得到的结果是00000000000000000000000000001100, 则转换为十进制是12 数学意义: 在数学没有溢出的前提下,对于正数和负数,左移以为都相当于乘以2的1次方,左移n位 就相当于乘以2的n次方 >>右移
    运算规则:
    按二进制形式把所有的数字向右移动对应的位数,低位移出(舍弃),高位的空位补符号位
    即正数补0,负数补1
    语法规则:
    需要移位的数字>>移位的次数
    例如:11>>2则是将数字11右移2位
    计算过程:
    11的二进制形式为:00000000000000000000000000001011然后把低位的最
    后两个数字移出,因为该数字是正数,所以在高位补0,则得到的最终的二进制结果为:
    00000000000000000000000000000010转换为十进制数为3
    数学意义:
    右移一位相当于除以2,右移n位相当于除以2的n次方,这里取的是商,不要余数

    转自:http://wangyan112.blog.51cto.com/3383033/1320143

  • Python 继承使用super出错

    Python 2.2以后使用super继承的父类属性的时候会报错,这篇文章通过讲解新式类和旧类的区别来解决super报错的问题。

    在Python的类中去继承父类的属性, 一般的写法为:

    [python]
    class Father:
    def __init__(self):
    print "I’m Father"

    class Child(Father):
    def __init__(self):
    Father.__init__(self)
    print "I’m Child"
    >>>f = Child()
    I’m Father
    I’m Child
    [/python]

    如果在多重继承的问题中,例如菱形继承(钻石问题),则需要用到super来解决。但是super只能用在继承基类”object”的新式类中,不能用于以前的经典类,否则报错:

    [python]
    class Father:
    def __init__(self):
    print "I’m Father"

    class Child(Father):
    def __init__(self):
    super(Child, self).__init__()
    print "I’m Child"
    >>>f = Child()
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<stdin>", line 3, in __init__
    TypeError: must be type, not classobj
    [/python]

    原因如下:

    解决的方法是设置Father继承Object

    [python]
    class Father(object):
    def __init__(self):
    print "I’m Father"

    class Child(Father):
    def __init__(self):
    super(Child, self).__init__()
    print "I’m Child"
    >>>f = Child()
    I’m Father
    I’m Child
    [/python]

    以下关于《旧类和新式类》的内容摘自:http://blog.csdn.net/jb19900111/article/details/20228341

    • python的新式类是2.2版本引进来的,我们可以将之前的类叫做经典类或者旧类。
    • 为什么要在2.2中引进new style class呢?官方给的解释是:为了统一类(class)和类型(type)。
    • 在2.2之前,比如2.1版本中,类和类型是不同的,如a是ClassA的一个实例,那么a.__class__返回 ‘ class __main__.ClassA‘ ,type(a)返回总是<type ‘instance’>。而引入新类后,比如ClassB是个新类,b是ClassB的实例,b.__class__和type(b)都是返回‘class ‘__main__.ClassB’ ,这样就统一了。
    • 引入新类后,还有其他的好处,比如更多的内置属性将会引入,描述符的引入,属性可以来计算等等。
    • 为了向前兼容,默认情况下用户定义的类为经典类,新类需要继承自所有类的基类 object 或者继承自object的新类。
    • 值得注意的地方是,虽然使用的是最新的python(2.7),但是一些特性不会在旧式类起作用。
    • 所以,为了确保自己使用的是新式类,有以下方法:
      • 把这个赋值语句放在类模块代码的最前面 __metaclass__ = type(前面有提过)。
      • 自己的类都从内建类object直接或者间接地继承。
      • 如果不需要兼容旧式类,旧版本的类,那么就保持都是新式类。
      • 当然,在Python3里面,不存在这些问题了,因为所有的类都是object类的子类(隐式)。
  • 维基编码-Wikicode

    这片文章简单介绍了“维基编码(Wikicode)”以及维基百科对这些代码的处理方式。
    维基百科的数据以其专用的编码(Wikicode)存储在DUMP中,由这种代码构成的文本称为维基文本(Wikitext)。如果是有写过维基百科的朋友,对这个编码方式肯定不陌生,通过不同的编码方式,可以添加文本样式、超链接、注释等等,甚至可以改变文章结构。如果不清楚也没有关系,这种编码基本的使用还是挺简单的,参见Help:Wiki Markup
    维基编码是维基百科的数据的格式,但是一般我们在浏览维基百科的时候,因为维基编码已经通过维基百科的系统转换成了HTML代码了,因此一般我们看不到维基编码的痕迹, 下面给处一个简单的例子来说明区别:

    WikicodeView
    WikicodeView

    HTMLView
    HTMLView
    NormalView
    NormalView
  • 维基百科的“ 历史页面 “

    维基百科的“ 历史页面 “

    如要要分析处理维基百科某一个页面的历史记录,最好的方式就是通过“ 历史页面 ”来寻找不同版本直接的区别。这里介绍了HTML格式下面,这些信息的存储格式,以便自动筛选信息。
    维基百科为每一个页面提供了一个动态的历史界面,以记录每次的修改。这个页面由一个列表构成,表中的每一条都是一次修改记录,如下: 
    GetImage

    每条记录由修改日期、修改人、修改内容大小、是否是微小修改、修改备注构成,当然每条修改记录有相对应的文章正文,只是这个正文需要点击链接进入另外一个页面找到(这个和DUMP中的数据不一样,查看《文章页面及历史版本》)。

    这个页面由于是一个动态页面,因此无法从DUMP文件中找出,只能通过HTML格式的方式将页面保存下来。因为是HTML的格式,所以页面的源代码包括了大量的格式化的代码,而要取得所需信息,就需要定位所信息的位置,之后,通过分析代码的结构即可取得所需信息。

    在HTML页面中,历史记录的位置在”id”为”pagehistory”的<ul>标签之间,每条记录以<li>的代码形式被保存着,如下

    [html]
    <ul id=”pagehistory”>
    <li>…</li>
    <li>…</li>
    <li>…</li>
    </ul>
    [/html]

    每条<li>的记录格式的内容结构如下:

    [html]
    <ul>
    <li>
    <span>(<a
    href=”https://fr.wikipedia.org/w/index.php?title=Histoire_de_la_logique&amp;diff=100272207&amp;oldid=97547514″
    title=”Histoire de la logique”>actu</a> | <a
    href=”https://fr.wikipedia.org/w/index.php?title=Histoire_de_la_logique&amp;diff=97547514&amp;oldid=97547510″
    title=”Histoire de la logique”>diff</a>)</span>
    <input type=”radio” value=”97547514″ name=”oldid” id=”mw-oldid-97547514″ style=”visibility: visible;” />
    <input type=”radio” value=”97547514″ name=”diff” id=”mw-diff-97547514″ style=”visibility: hidden;” />
    <a href=”https://fr.wikipedia.org/w/index.php?title=Histoire_de_la_logique&amp;oldid=97547514″
    title=”Histoire de la logique”>17 octobre 2013 à 15:25</a>‎
    <span>
    <a href=”https://fr.wikipedia.org/wiki/Utilisateur:Salebot”
    title=”Utilisateur:Salebot”>Salebot</a>
    <span>(<a
    href=”https://fr.wikipedia.org/wiki/Discussion_utilisateur:Salebot”
    title=”Discussion utilisateur:Salebot”>discuter</a> | <a
    href=”https://fr.wikipedia.org/wiki/Sp%C3%A9cial:Contributions/Salebot”
    title=”Spécial:Contributions/Salebot”>contributions</a>)</span>
    </span>‎
    <span>. .</span>
    <span>(23&nbsp;130 octets)</span>
    <span dir=”ltr” title=”23&nbsp;130 octets après changement”
    >(-76)</span>
    <span>. .</span>
    <span>(bot : révocation de <a
    href=”https://fr.wikipedia.org/wiki/Sp%C3%A9cial:Contributions/193.253.229.112″
    title=”Spécial:Contributions/193.253.229.112″>193.253.229.112</a>
    (modification suspecte : -399), retour à la version 97088153 de Proz)</span>
    (<span><a
    href=”https://fr.wikipedia.org/w/index.php?title=Histoire_de_la_logique&amp;action=edit&amp;undoafter=97547510&amp;undo=97547514″
    title=”Histoire de la logique”>annuler</a></span>)
    </li>
    </ul>
    [/html]

    通过这个结构,我们可以找出一下内容:

    1. 版本(revision) 的ID(这个ID在整个维基百科中是唯一的):https://fr.wikipedia.org/w/index.php?title=Histoire_de_la_logique&amp;oldid=97547514
    2. 版本时间:17 octobre 2013 à 15:25
    3. 这个版本的用户链接:https://fr.wikipedia.org/wiki/Utilisateur:Salebot
    4. 用户名:Salebot
    5. 文章内容大小:23 130 octets
    6. 修改内容大小:-76
    7. 文章编辑的记录:(bot : révocation de 193.253.229.112 (modification suspecte : -399), retour à la version 97088153 de Proz)
    8. 另外,微小编辑属于附加属性,在源代码中按以下方式保存:
      <abbr title=”Cette modification est mineure.”>m</abbr>
  • 处理维基百科的“ 历史页面 ”

    在CoMeRe处理维基百科的页面的时候,由于每一个页面上有一个“历史页面”, 这里包括了这个页面的所有编辑的历史记录,因此整理并分析编辑记录,这里是一个很好的开始。

    对这个页面整体的处理思路是先通过HTML分析全文本,找出历史编辑的列表,并对每条编辑记录进行分析和处理,最后每条记录得出:

    • 条目的ID
    • 日期
    • 作者名
    • 版本的文本长度
    • 相对前面一个版本,文本长度变化的数量
    • 评论
    • 是否属于“小量编辑”

    代码pagehistory.py负责进行这个的处理,需要注意的是,在匹配Wikipedia日期的时候,Python程序需要设置本地格式, 在Ubuntu下使用下面命令查看本地支持的语言:

    [bash]
    locale -a
    [/bash]

    链接:https://github.com/KunFly/wiki

    定了两个类:

    PageHistory和Revision

    PageHistory

    • get_revisions(), 返回所有的revision

    Revision

    每一个revision包括一下属性:

    • id, 版本ID
    • date(), 版本日期
    • author(), 版本作者
    • size(), 版本大小
    • change_size(), 相对前一个版本,修改的数量大小
    • comment(), 修改的注释
    • minoredit(),是否是“小量修改“

    每一个属性都可以找到相对应的方法:

    • get_id()
    • get_date()
    • get_author()
    • get_size()
    • get_change_size()
    • get_comment()
    • get_minoredit()