存档

文章标签 ‘screenshot’

linux 下恢复 U 盘下被删除文件

2010年3月4日
Comments Off

我一老师的手机 sd 卡上的照片被不幸删除了,问有没有方法恢复。我找到一个叫 testdisk 的工具,成功将这些照片恢复过来,立此存照兼备忘。

安装:
sudo pacman -S testdisk
使用:
sudo testdiak
接下来按照图片直播搞定:

testdisk1

testdisk2

testdisk3

testdisk4

testdisk5

testdisk6

testdisk7

testdisk8

Other ,

chrome 的泡泡翻译插件

2009年12月31日

非常酷的一个 chrome 插件,使用的是 google translate 的数据,故而不用安装乱七八糟的辞典,其主页在这里:http://code.google.com/p/bubble-translate/

安装好了以后会直接显示配置界面,从里面可以选择翻译的语种,默认按住 ctrl 键然后用鼠标在页面选中文本就会弹出一个泡泡将翻译结果显示出来(最牛的是还可以全文翻译哦,强阿!),很好玩哦,以后上外文网站就不用随时开着一个辞典了。

露个脸:

单词翻译:
抓图38
全文翻译:
抓图39

Other ,

翻箱淘到的在线翻译脚本

2009年12月28日
Comments Off

偶尔清理我的个人可执行目录($HOME/.bin)发现了远古时代写的一个翻译脚本,牵出来遛了一遛,还可以用哈,嘿嘿,顺手给改了几下,添加了以下一些特性:

1) deamon 化(直接进后台了,不必老开着一个终端跑)
2) 三种显示方式:kdialog,notify-send 和 gnome-osd
3) 脚本名加 -k 参数剋掉后台进程

露脸一下:
dic_sh

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
 
# Name:     dic.sh
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Site:     http://joolix.com
# Licence:  GPLv3
# Version:  091228
 
timeout=10
 
trans() {
	str="`xsel`"
	while true ; do
	  a="`xsel`"
	  if [ "$a" != "$str" ] ; then
		str="$a"
		[ ${#a} -lt 15 ] && word="`w3m -dump -no-cookie http://dict.cn/mini.php?q="$a" \
		| sed -e '$d' -e 's/</ /g' -e 's/>/ /g'`"
		if [ "`which gnome-osd-client 2>/dev/null`" ]; then
			gnome-osd-client -f "<message id='word' osd_fake_translucent_bg='off' \
			osd_vposition='top' osd_halignment='right' animations='on' hide_timeout='10000'>\
			<span size='15000' foreground='pink'>`echo "$word"`</span></message>"
		elif [ "`which kdialog 2>/dev/null`" ]; then
			kdialog --passivepopup "$word" "${timeout:-5}" &>/dev/null
		elif [ "`which notify-send 2>/dev/null`" ]; then
			timeout=${timeout:-5}
			timeout=$((timeout*1000))
			notify-send -t "$timeout" "$word"
		fi
	  fi
	  sleep 1
	done
}
 
# daemonize
if [ "x$1" != "x--" -a "x$1" != "x-k"  -a "x$1" != "x-h" ]; then
	if [ ! "`cat /tmp/dic.pid 2>/dev/null`" ]; then
		"$0" -- 1> /dev/null 2> /dev/null &
		exit 0
	else
		echo "dic is running."
		exit 0
	fi
elif [ "x$1" = "x-k" ]; then
	pic_pid="`cat /tmp/dic.pid 2>/dev/null`"
	if [ "$pic_pid" ]; then
		kill -9 "$pic_pid" 2>/dev/null
		rm /tmp/dic.pid 2>/dev/null
		echo "dic process is terminated."
	else
		echo "no dic process is running."
	fi
	exit 0
elif [ "x$1" = "x-h" ]; then
	nm="`basename $0`"
	echo -e "$nm: run\n$nm -k: kill daemon\n$nm -h: show help"
	exit 0
fi
 
echo $$ > /tmp/dic.pid
trans

Script , , ,

Bash matrix 脚本

2009年12月18日

RT
根据骨头兄滴大作改编。
matrix

代码(单行):

p(){printf "\033[%d;%dH\033[32m%c\033[m" $1 $2 "$3"};clear;N=20;for i in `seq 1 $N 2`; do x[$i]=$((RANDOM%LINES+1));y[$i]=$((RANDOM%COLUMNS+1));done;chars=({0..9} {a..z} {A..Z} '*' '&' '^' '%' '$' '#' '@' '~' '<' '>' '?' '+');while :; do for i in `seq $N`;do ran_char=${chars[$RANDOM % ${#chars[@]}]};p ${x[$i]} ${y[$i]} $ran_char;((x[$i]++));if [ ${x[$i]} -ge $LINES ]; then for j in `seq $LINES`;do p $j ${y[$i]} " ";done;x[$i]=$((RANDOM%LINES+1));y[$i]=$((RANDOM%COLUMNS+1));fi;done;sleep .02;done

代码(多行, 多行代码须用 . script.sh 的方式运行,不然会出错)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
p(){
	printf "\033[%d;%dH\033[32m%c\033[m" $1 $2 "$3"
}
clear
N=20
for i in `seq 1 $N 2`; do
	x[$i]=$((RANDOM%LINES+1))
	y[$i]=$((RANDOM%COLUMNS+1))
done
 
chars=({0..9} {a..z} {A..Z} '*' '&' '^' '%' '$' '#' '@' '~' '<' '>' '?' '+')
while :; do
	for i in `seq $N`; do
		ran_char=${chars[$RANDOM % ${#chars[@]}]}
		p ${x[$i]} ${y[$i]} $ran_char
		((x[$i]++))
		if [ ${x[$i]} -ge $LINES ]; then
			for j in `seq $LINES`; do
				p $j ${y[$i]} " "
			done
			x[$i]=$((RANDOM%LINES+1))
			y[$i]=$((RANDOM%COLUMNS+1))
		fi
	done
	sleep .02
done

Script , ,

产生网站验证码图片的脚本

2009年12月18日
Comments Off

近日想用 web.py 搭建一个网站,在登录部分想到用验证码,参考了网上的一些代码以后自己改写出想要的版本,其特点如下:

1) 图片内容为代数算式
2) 有线条干扰
3) 除去生成验证码图片外还返回一个元组: (filename, result)

使用倒是挺方便的,先放出源码,希望能启发大家。
这里有一张生成的图片:

验证码例图

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Name:     genpic.py
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Site:     http://joolix.com
# Licence:  GPLv3
# Version:  091218
 
'''用于产生网站验证码图片(代数算式)'''
 
import Image,ImageDraw,ImageFont
import random
import math
import hashlib
import datetime
 
def genpic():
    '''生成验证码图片,返回一个元组(filename,result)'''
    #图片宽度
    width = 130
    #图片高度
    height = 35
    #背景颜色
    bgcolor = (151, random.randint(0,225), random.randint(0,225))
    #生成背景图片
    image = Image.new('RGB',(width,height),bgcolor)
    #加载字体
    font = ImageFont.truetype('/usr/share/fonts/TTF/DejaVuSans-Bold.ttf',27)
    #字体颜色
    fontcolor = (0, 0, 0)
 
    #产生draw对象
    draw = ImageDraw.Draw(image)
 
    # 生成算式
    ops = ['+', '-']
    op = random.choice(ops)
    num1 = random.randint(0, 99)
    num2 = random.randint(0, 99)
    rand_str = str(num1) + " " + op + " " + str(num2)
    result = str(eval(rand_str))
 
    # 生成文件名
    m = hashlib.md5()
    m.update(str(datetime.datetime.now()))
    fnm = m.hexdigest()
 
    #画字体,(0,0)是起始位置
    draw.text((0,0),rand_str + ' =',font=font,fill=fontcolor)
 
    #画线
    #线的颜色
    linecolor= (random.randint(0,225), random.randint(0,225), random.randint(0,225))
    for i in range(0,15):
        #随机产生线条
        x1 = random.randint(0,width)
        x2 = random.randint(0,width)
        y1 = random.randint(0,height)
        y2 = random.randint(0,height)
        draw.line([(x1, y1), (x2, y2)], linecolor)
 
    #释放draw
    del draw
 
    #保存文件到本地
    image.save(fnm + '.jpg')
    return (fnm, result)
 
if __name__ == "__main__":
    pic = genpic()
    print pic

Script , ,

snail 溶剂比例计算器升级版

2009年12月12日
Comments Off

添加了利用现有两种溶液来计算欲配溶液的功能
修复了一些易引发错误的代码。
片片:
snail2 抓图

代码:
snail.py :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
# Author:   xiooli <xioooli[at]yahoo.com.cn>
# Site:     http://joolix.com
# Licence:  GPLv3
 
import sys, os
from PyQt4 import QtCore, QtGui
from ui_zh import Ui_mainWindow
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
 
class Win(QMainWindow, Ui_mainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        self.label_6_txt = ""
        now_B_A = now_B_B = ""
        continue_com = ""
        vol = ""
        rst = ""
 
        try:
            now_B_A = float(self.lineEdit_4.text())
            now_B_B = float(self.lineEdit_5.text())
        except:
            pass
        try:
            now_A_A = float(self.lineEdit_1.text())
            now_A_B = float(self.lineEdit_2.text())
            now_vol = float(self.lineEdit_3.text())
            want_A = float(self.lineEdit_6.text())
            want_B = float(self.lineEdit_7.text())
        except ValueError:
           self.label_6_txt = "错误:有输入框未输入数字,或输入了非数字字符!"
 
        if ( not self.label_6_txt ) and ( now_B_A and now_B_B ):
            try:
                vol,rst = self.lineEdit_3.text(),\
                        round(now_vol*( now_A_A/(now_A_A+now_A_B)-want_A/(want_A+want_B) ) / \
                        ( want_A/(want_A+want_B)-now_B_A/(now_B_A+now_B_B) ), 4)
            except ZeroDivisionError:
                self.label_6_txt = "错误:试图除零!"
            if rst != "" and rst > 0:
                rst = str(rst)
                self.label_6_txt = "须向 " + vol + " ML 现有溶液 A 中加入现有溶液 B " + rst + " ML"
            else:
                self.label_6_txt = "注意:现有溶液 A 和 B 不能配制出欲配溶液<p>"
                continue_com = 1
 
        if ( not self.label_6_txt ) or continue_com:
            if want_A*(now_A_A+now_A_B) == 0:
                self.label_6_txt = "错误:试图除零!"
            elif want_B != 0 and (now_A_B == 0 or now_A_A / now_A_B > want_A / want_B):
                vol,rst = self.lineEdit_3.text(),\
                        str(round(now_vol*now_A_A*(want_A+want_B)/(want_A*(now_A_A+now_A_B))-now_vol,4))
                self.label_6_txt += "须向 " + vol + " ML 现有溶液 A 中加入溶剂 B " + rst + " ML"
            elif want_B != 0 and now_A_B != 0 and now_A_A / now_A_B == want_A / want_B:
                self.label_6_txt = "现有溶液 A 和欲配溶液是同一种溶液,无须额外动作。"
            else:
                try:
                    vol,rst=self.lineEdit_3.text(),\
                            str(round(now_vol*now_A_B*(want_A+want_B)/(want_B*(now_A_A+now_A_B))-now_vol,4))
                    self.label_6_txt += "须向 " + vol + " ML 现有溶液 A 中加入溶剂 A " + rst + " ML"
                except ZeroDivisionError:
                    self.label_6_txt = "错误:试图除零!"
 
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", self.label_6_txt, None, QtGui.QApplication.UnicodeUTF8))
 
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    win=Win()
    win.show()
    sys.exit(app.exec_())

ui_zh.py :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'snail.ui'
#
# Created: Wed Nov 11 21:15:36 2009
#      by: PyQt4 UI code generator 4.6.1
#
# WARNING! All changes made in this file will be lost!
 
from PyQt4 import QtCore, QtGui
 
class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(872, 452)
        self.centralwidget = QtGui.QWidget(mainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.lineEdit_1 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_1.setGeometry(QtCore.QRect(250, 90, 171, 51))
        self.lineEdit_1.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_1.setObjectName("lineEdit_1")
        self.lineEdit_2 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(460, 90, 171, 51))
        self.lineEdit_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.lineEdit_3 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_3.setGeometry(QtCore.QRect(670, 90, 161, 51))
        self.lineEdit_3.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.lineEdit_4 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_4.setGeometry(QtCore.QRect(250, 170, 171, 51))
        self.lineEdit_4.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.lineEdit_5 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_5.setGeometry(QtCore.QRect(460, 170, 171, 51))
        self.lineEdit_5.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_5.setObjectName("lineEdit_5")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(280, 20, 131, 41))
        self.label.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label.setObjectName("label")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(490, 20, 131, 41))
        self.label_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_2.setObjectName("label_2")
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(710, 20, 131, 41))
        self.label_3.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_3.setObjectName("label_3")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(40, 100, 171, 41))
        self.label_4.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_4.setObjectName("label_4")
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(40, 250, 171, 41))
        self.label_5.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_5.setObjectName("label_5")
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(670, 170, 161, 51))
        self.pushButton.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.pushButton.setObjectName("pushButton")
        self.frame = QtGui.QFrame(self.centralwidget)
        self.frame.setEnabled(True)
        self.frame.setGeometry(QtCore.QRect(40, 330, 791, 91))
        self.frame.setMouseTracking(False)
        self.frame.setAutoFillBackground(False)
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.label_6 = QtGui.QLabel(self.frame)
        self.label_6.setGeometry(QtCore.QRect(10, 10, 781, 71))
        self.label_6.setStyleSheet("""font: 22pt \"Bitstream Vera Sans Mono\"; color: rgb(0, 0, 255);""")
        self.label_6.setObjectName("label_6")
        self.label_7 = QtGui.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(40, 180, 171, 41))
        self.label_7.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\"; A")
        self.label_7.setObjectName("label_7")
        self.lineEdit_6 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_6.setGeometry(QtCore.QRect(250, 250, 171, 51))
        self.lineEdit_6.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_6.setObjectName("lineEdit_6")
        self.lineEdit_7 = QtGui.QLineEdit(self.centralwidget)
        self.lineEdit_7.setGeometry(QtCore.QRect(460, 250, 171, 51))
        self.lineEdit_7.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(670, 250, 161, 51))
        self.pushButton_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.pushButton_2.setObjectName("pushButton_2")
        mainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(mainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 872, 25))
        self.menubar.setObjectName("menubar")
        mainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(mainWindow)
        self.statusbar.setObjectName("statusbar")
        mainWindow.setStatusBar(self.statusbar)
 
        self.retranslateUi(mainWindow)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.label_6.clear)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL("clicked()"), mainWindow.close)
        QtCore.QMetaObject.connectSlotsByName(mainWindow)
 
    def retranslateUi(self, mainWindow):
        mainWindow.setWindowTitle(QtGui.QApplication.translate("mainWindow", " 溶剂比例计算器 - Snail", None, QtGui.QApplication.UnicodeUTF8))
        self.lineEdit_3.setText(QtGui.QApplication.translate("mainWindow", "1000", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("mainWindow", " 溶剂 A", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("mainWindow", " 溶剂 B", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("mainWindow", "体积", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("mainWindow", "现有溶液 A", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("mainWindow", "欲配溶液", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("mainWindow", "计算", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", "欢迎使用溶剂比例计算器 Snail\nxiooli <xioooli@yahoo.com.cn>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_7.setText(QtGui.QApplication.translate("mainWindow", "现有溶液 B", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("mainWindow", "关闭", None, QtGui.QApplication.UnicodeUTF8))

Chemistry, Script , ,

pyqt 的溶剂比例计算器 snail

2009年11月10日

RT
开始做植化了,要用,鑫哥的那个是 for win 的,以前写了个 ruby-gtk 的不知道扔哪里去了,于是重新写了个 pyqt 的。

ps: 图形界面的程序真是浪费表情阿,真正干活的就两三行,一旦要图形界面了就几百行,这个看来是死要面子(图形界面)活受罪的真实写照阿,呵呵。

片片:
snail 抓图

源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/python
# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'snail.ui'
#
# Created: Tue Nov 10 17:44:47 2009
#      by: PyQt4 UI code generator 4.6.1
#
# WARNING! All changes made in this file will be lost!
 
import sys, os
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QMainWindow
from PyQt4.QtCore import pyqtSignature
 
class Ui_mainWindow(object):
    def setupUi(self, mainWindow):
        mainWindow.setObjectName("mainWindow")
        mainWindow.resize(767, 375)
        self.centralwidget = QtGui.QWidget(mainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.textEdit = QtGui.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(170, 90, 171, 51))
        self.textEdit.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit.setObjectName("textEdit")
        self.textEdit_2 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_2.setGeometry(QtCore.QRect(380, 90, 171, 51))
        self.textEdit_2.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_2.setObjectName("textEdit_2")
        self.textEdit_3 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_3.setGeometry(QtCore.QRect(590, 90, 161, 51))
        self.textEdit_3.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_3.setObjectName("textEdit_3")
        self.textEdit_4 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_4.setGeometry(QtCore.QRect(170, 180, 171, 51))
        self.textEdit_4.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_4.setObjectName("textEdit_4")
        self.textEdit_5 = QtGui.QTextEdit(self.centralwidget)
        self.textEdit_5.setGeometry(QtCore.QRect(380, 180, 171, 51))
        self.textEdit_5.setStyleSheet("font: 22pt \"Bitstream Vera Sans Mono\";")
        self.textEdit_5.setObjectName("textEdit_5")
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(200, 20, 131, 41))
        self.label.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label.setObjectName("label")
        self.label_2 = QtGui.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(410, 20, 131, 41))
        self.label_2.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_2.setObjectName("label_2")
        self.label_3 = QtGui.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(630, 20, 131, 41))
        self.label_3.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_3.setObjectName("label_3")
        self.label_4 = QtGui.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(20, 90, 151, 41))
        self.label_4.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_4.setObjectName("label_4")
        self.label_5 = QtGui.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(20, 190, 151, 41))
        self.label_5.setStyleSheet("font: 26pt \"Bitstream Vera Sans Mono\"; 溶剂 A")
        self.label_5.setObjectName("label_5")
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(590, 180, 161, 51))
        self.pushButton.setStyleSheet("font: 20pt \"Bitstream Vera Sans Mono\";")
        self.pushButton.setObjectName("pushButton")
        self.label_6 = QtGui.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(30, 270, 721, 71))
        self.label_6.setStyleSheet("""font: 22pt \"Bitstream Vera Sans Mono\"; color: rgb(0, 0, 255);""")
        self.label_6.setObjectName("label_6")
        self.frame = QtGui.QFrame(self.centralwidget)
        self.frame.setEnabled(True)
        self.frame.setGeometry(QtCore.QRect(20, 260, 731, 91))
        self.frame.setMouseTracking(False)
        self.frame.setAutoFillBackground(False)
        self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setObjectName("frame")
        mainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(mainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 767, 25))
        self.menubar.setObjectName("menubar")
        mainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(mainWindow)
        self.statusbar.setObjectName("statusbar")
        mainWindow.setStatusBar(self.statusbar)
 
        self.retranslateUi(mainWindow)
        #QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.label_6.)
        QtCore.QMetaObject.connectSlotsByName(mainWindow)
 
    def retranslateUi(self, mainWindow):
        mainWindow.setWindowTitle(QtGui.QApplication.translate("mainWindow", "溶剂比例计算器 -Snail", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit_3.setHtml(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:22pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">1000</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">溶剂 A</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">溶剂 B</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">体积</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">现有溶液</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:26pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">欲配溶液</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("mainWindow", "也来算一个!", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:22pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">欢迎使用溶剂比例计算器 Snail</p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Xiooli &lt;xioooli@yahoo.com.cn&gt;</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
 
 
 
class Win(QMainWindow, Ui_mainWindow):
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)
        self.setupUi(self)
    @pyqtSignature("")
    def on_pushButton_clicked(self):
        self.label_6_txt = ""
        try:
            now_A = float(self.textEdit.toPlainText())
            now_B = float(self.textEdit_2.toPlainText())
            now_vol = float(self.textEdit_3.toPlainText())
            want_A = float(self.textEdit_4.toPlainText())
            want_B = float(self.textEdit_5.toPlainText())
        except ValueError:
           self.label_6_txt = "错误:有输入框未输入数字,或输入了非数字字符!"
 
        if not self.label_6_txt:
            if want_A*(now_A+now_B) == 0 or want_B*(now_A+now_B) == 0:
                self.label_6_txt = "错误:试图除零!"
            elif now_A / now_B > want_A / want_B:
                vol,rst=self.textEdit_3.toPlainText(),\
                        str(round(now_vol*now_A*(want_A+want_B)/(want_A*(now_A+now_B))-now_vol,4))
                self.label_6_txt = "须向 " + vol + " ML 现有溶液中加入溶液 B " + rst + " ML"
            elif now_A / now_B == want_A / want_B:
                self.label_6_txt = "现有溶液和欲配溶液是同一种溶液,无须额外动作。"
            else:
                vol,rst=self.textEdit_3.toPlainText(),\
                        str(round(now_vol*now_B*(want_A+want_B)/(want_B*(now_A+now_B))-now_vol,4))
                self.label_6_txt = "须向 " + vol + " ML 现有溶液中加入溶液 A " + rst + " ML"
        self.label_6.setText(QtGui.QApplication.translate("mainWindow", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Bitstream Vera Sans Mono\'; font-size:22pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"+self.label_6_txt+"</p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
 
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    win=Win()
    win.show()
    sys.exit(app.exec_())

Chemistry, Script , , ,

Firefox下直接观看PPS看看

2009年10月16日
Comments Off

ubuntu论坛牛人写了pps的totem插件,可以用于观看pps的节目,具体安装方法debian系的参考http://forum.ubuntu.org.cn/viewtopic.php?f=74&t=223582
archlinux用以下命令即可安装:

yaourt -S libppswrapper-git gst-plugins-pps-git totem-pps-git libpps gst-plugins-sopcast-git totem-sopcast-git

但是这样只可以在totem的窗口里面看,当然也可以点击pps看看节目右边的客户端播放,然后将其关联到totem,但是总离不了一个独立的totem窗口,于是我们的 Hello World 童鞋在自我需求的推动下写了一个greasemonkey脚本,让其可直接在frefox的窗口下播放pps看看(当然是调用totem-pps的)。

要正常使用这个油猴脚本,你需要满足几个基本条件:
1) 能正常使用的totem-pps
2) totem-plugin(arch下的包名字,其他distro.里面自己找找吧)
3) firefox 安装并启用 greasemonkey

一切就绪以后你就可以去pps上面踢馆咯,哈哈!

greasemonkey 脚本从这里下载:http://forum.ubuntu.org.cn/download/file.php?id=80735,解压后拖到firefox的窗口里面进行安装。

秀图一张:
pps-in-ff

Script , , , ,

植化流程图生成脚本

2009年9月9日

RT
做植化的同学写报告的时候常常要画分离的流程图,以往大家都是拖啊拖啊的,看起来就恼火,于是就写了这样一个脚本(以后我也要画这种东西嘛),可以将简单的描述语言直接生成流程图,比如,如下的语言就可以生成如下的图:

a#草药样品
b#粗分浸膏
a#$甲醇提取=>b#
c1#正丁醇相
c2#石油醚相
c3#…
c4#水相
b#^$有机溶剂萃取
b#=>c1#
b#=>c2#
b#=>c3#
b#=>c4#
c2#^$继续柱层析分离
c2#=>d1#成分五
c2#=>d2#成分六

生成的流程图

该描述语言语法非常简单:
#前面是 node 的名字,$后面是描述,=> 将两个 node 连接起来,在其中画箭头,可以连续连接 比如 a# => b# => c# 也是可以的,node 后面 => 前面的 $xxx 是线上的注释,如果某一个点要往下分支的话只需用 node#^ 即可,node#^ 后面可以直接加注释,很简单的,看上面那个例子结合图片就可以搞明白了。

运行该脚本需要 python-yapgvb,此脚本受弯弯同学脚本的启发并参考了部分代码(http://python.ubuntu.org.cn/viewtopic.php?f=162&t=180285&sid=e2ae53902848adb1d59c375bf2325043

使用方法:

python liuchengtu.py -o xxx.png deffile

还有很多个性化选项,请参考源码。

源码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# Author: xioooli<at>yahoo.com.cn,joolix.com
# Licence GPLv2
# Version 2009.09.09
 
import sys
import yapgvb
import optparse
 
FORMATS = {"png" : yapgvb.formats.png,
        "jpg" : yapgvb.formats.jpg,
        "gif" : yapgvb.formats.gif}
ENGINES = {"dot" : yapgvb.engines.dot,
        "neato" : yapgvb.engines.neato,
        "circo" : yapgvb.engines.circo,
        "twopi" : yapgvb.engines.twopi}
 
if __name__ == '__main__':
#    args = sys.argv
#    if len(args) < 2:
#        print "Usage: python state_machine.py <def file>"
#        sys.exit(0)
 
    parser = optparse.OptionParser()
    parser.add_option("-f", "--format", dest="format",
            help="store the flow chart in FORMAT (png, svg, jpg, gif)",
            metavar="FORMAT", default="png")
    parser.add_option("-o", "--output", dest="output",
            help="save the flow chart to FILE",
            metavar="FILE")
    parser.add_option("-e", "--engine", dest="engine",
            help="the layout ENGINE to use for the flow chart (dot, neato, circo, twopi)",
            metavar="ENGINE", default="dot")
    parser.add_option("-c", "--color", dest="fillcolor",
            help="the fillcolor of the node",
            default="white")
    parser.add_option("--fs", "--font-size", dest="fontsize",
            help="the font size of the text",
            default="12")
    parser.add_option("--nfc", "--node-font-color", dest="nodefontcolor",
            help="the fillcolor of the font in node",
            default="black")
    parser.add_option("--nc", "--node-color", dest="nodecolor",
            help="the color of the node frame",
            default="black")
    parser.add_option("--ec", "--edge-color", dest="edgecolor",
            help="the color of the edge",
            default="black")
    parser.add_option("--efc", "--edge-font-color", dest="edgefontcolor",
            help="the font color of the edge text",
            default="black")
    parser.add_option("-s", "--style", dest="style",
            help="the style of the node",
            default="filled")
    parser.add_option("--ah", "--arrowhead", dest="arrowhead",
            help="the style of the arrowhead",
            default="normal")
    parser.add_option("--as", "--arrowsize", dest="arrowsize",
            help="the size of the arrow",
            default=1)
    parser.add_option("--ns", "--nodesep", dest="nodesep",
            help="the sepration between two nodes",
            default=.5)
    parser.add_option("--sp", "--shape", dest="shape",
            help="the shape of the node",
            default="box")
 
    options, args = parser.parse_args()
    if len(args) < 1:
        parser.print_usage()
        sys.exit(0)
 
    graph = yapgvb.Graph("States")
    graph.rankdir="TB"
    graph.nodesep=options.nodesep
    node_dict = {}
 
    with open(args[0]) as def_file:
        lines = [l.strip() for l in def_file.readlines()]
        for line in lines:
            nodes = line.split("=>")
            prev_node = None
            for node in nodes[::-1]:
                label = node.strip().split("#")
                if not node_dict.has_key(label[0]) and label[0] != "":
                    try:
                        lb=label[1].split("$")[0]
                    except:
                        lb=""
                    node_in_graph = graph.add_node(label=lb,
                            shape=options.shape, fillcolor=options.fillcolor,
                            fontcolor=options.nodefontcolor, fontsize=options.fontsize,
                            style=options.style, color=options.nodecolor, width=0.5)
                    node_dict[label[0]] = node_in_graph
                elif label[0] != "":
                    node_in_graph = node_dict[label[0]]
 
                try:
                       blanknode = node.strip().split("#^")
                       if len(blanknode) >= 2:
                           blanknode = blanknode[0]
                       else:
                           blanknode = ""
                except:
                       blanknode = ""
                if node_dict.has_key(blanknode) and blanknode != "":
                    node_dict[blanknode + "_0"] = node_dict[blanknode]
                    node_in_graph = graph.add_node(label="",     
                            shape="circle", fillcolor=options.edgecolor,
                            color=options.edgecolor, style="filled", height=.05, width=.05)
                    node_dict[blanknode] = node_in_graph
                    edge = node_dict[blanknode + "_0"] - node_dict[blanknode]
                    edge.color=options.edgecolor
                    try:
                        edge.label=" "+node.strip().split("$")[1]
                        edge.fontcolor=options.edgefontcolor
                        edge.fontsize=options.fontsize
                    except:
                        pass
 
                if prev_node:
                    edge = node_in_graph - prev_node
                    edge.color=options.edgecolor
                    edge.arrowhead = options.arrowhead
                    edge.arrowsize = options.arrowsize
                    try:
                        edge.label=" "+node.strip().split("$")[1]
                        edge.fontcolor=options.edgefontcolor
                        edge.fontsize=options.fontsize
                    except:
                        pass
 
                prev_node = node_in_graph
 
    graph.layout(ENGINES[options.engine])
    format = FORMATS[options.format]
    if options.output:
        out_file = options.output
    else:
        out_file = args[0] + "." + format
 
    graph.render(out_file, format)

Chemistry, Script , , ,

joolix 2009 提前预览

2009年8月13日
Comments Off

RT,看个热闹哈,还有几样东西没有完成,可能还要等一段时间才放出测试。

大家请移步 http://forum.ubuntu.org.cn/viewtopic.php?f=33&t=220549 观看哈。

Joolix ,