页面

2009/05/11

DIY 一个用于生成桌面墙纸的“网络相机”

en 写了一个 python 脚本——WebCam,区区百十行代码,实现了从网络或本地目录抓取多幅图片并随机拼合到一起,所生成的图片可以作为漂亮的桌面墙纸。这个脚本程序虽然不是非常智能,但是它可以作为一个 python 编程示例供初学者借鉴。您也可以尝试做一个 Lua 或 Ruby 版本

这个脚本的全部代码如下:

#! /usr/bin/env python

# Copyright 2009 by Benjamin Fogle
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .

import sys
import os
import os.path
import urllib2
import tempfile
import math

# Constants. Change these to customize the script
# In ksh: CONFIG_FILE=$HOME/lectures/examples/LEC-05/webcam_config
CONFIG_FILE=os.getenv('HOME') + '/.webcam_config'
TARGET=os.getenv('HOME') + '/Pictures/Wallpapers/webcam.jpg'
SCREEN_X = 1024
SCREEN_Y = 768

def GetTiles(num_images):
"""Returns a tuple (N,M) representing the tile grid"""
# This algorithm could be much improved
tile = math.ceil(math.sqrt(N))
return (tile, tile)

def GetImageSize(N, M):
"""Returns a the max size of each image based on the screen size
and the tile grid"
""
global SCREEN_X
global SCREEN_Y
ImgX = SCREEN_X / N
ImgY = SCREEN_Y / M
return (ImgX, ImgY)

def CopyFile(src_fp, dest_fp):
"""Copy a file intelligently"""
data = src_fp.read(49152) # Copy 48k at a time
while data:
dest_fp.write(data)
data = src_fp.read(49152)
# Note: shutils.copyfileobj does this too.

if len(sys.argv) != 1:
print "Usage: %s" % (sys.argv[0])
print
print "Config file is located in %s" % CONFIG_FILE
sys.exit(1)

# Make sure the config file is readable and that it is a regular file
# There is a better way to do this that we will learn later.
if not os.access(CONFIG_FILE, os.R_OK) or not os.path.isfile(CONFIG_FILE):
print "Error: %s could not be opened!" % CONFIG_FILE
sys.exit(2)

urls = [] # Url to download from. Read from config file
captions = [] # Captions for each image. Read from config file
filenames = [] # Temporary file names

config_fp = open(CONFIG_FILE, 'r')
line = config_fp.readline()
N=0
while line:
params = line.split(":::")
urls.append(params[0].strip())
captions.append(params[1].strip())
line = config_fp.readline()
N+=1
config_fp.close()


# Download each url. This is how to iterate over mutliple lists at once
for url, caption in zip(urls, captions):
url_fp = urllib2.urlopen(url)
# The following two lines are the preffered way to open a temporary
# file.
fd, name = tempfile.mkstemp()
img_fp = os.fdopen(fd, 'w')
filenames.append(name)
CopyFile(url_fp, img_fp)
url_fp.close()
img_fp.close() # The data won't appear in img_fp until it's closed
# Use the ImageMagick suite from the shell to add a caption
os.system("convert '%s' -set comment '%s' '%s'" % \
(name, caption, name))

# Figure out the parameters
tilex, tiley = GetTiles(N)
imgx, imgy = GetImageSize(tilex, tiley)

# Use ImageMagick again to assemble the wallpaper
cmd = "montage -geometry %dx%d \
-tile %dx%d \
-set caption '%%c' \
-pointsize 32 \
-size %dx%d \
-texture plasma: \
+polaroid \
-background black "
% (imgx, imgy, tilex, tiley,
SCREEN_X, SCREEN_Y)

# Add each image file to the command string
for filename in filenames:
cmd += '"%s" ' % filename

# Add the output file to the command string and execute
cmd += TARGET
os.system(cmd)

# Cleanup
for filename in filenames:
os.unlink(filename) # In ksh: rm $filename

要运行该脚本,需要您的系统中已经安装 imagemagick(一般 GNU/Linux 会默认为您安装该软件包)。

首先将上述代码复制到 webcam 文件并保存;然后,为该文件的添加可执行权限:

$ chmod +x webcam

在使用该脚本之前,需要将所要获取图片的地址信息写入 .webcam_config 文件,例如:

$ nbsp;nbsp;nbsp;nbsp;echo "file:///home/garfileo/Winter.jpg ::: 冬天" >> $HOME/.webcam_config
$ echo "http://www.51766.com/bbs/photo/1127887493353.jpg ::: 昌平∙白虎涧" >>$HOME/.webcam_config
$ echo "http://tw.mjjq.com/pic/20070530/20070530043314558.jpg ::: 赤水" >>$HOME/.webcam_config
$ echo "file:///home/garfileo/MY-Moutain.jpg ::: 明月山" >> $HOME/.webcam_config

然后,只需要执行 webcam 脚本,便可以在 $HOME/Pictures/Wallpapers 目录(若无该目录,请自行创建)中生成合成图片。上面向 .webcam_config 文件写入的四幅图地址,第一幅与第四幅图位于我的本地目录,而其它两幅均来自网络。每幅图片的地址后面均尾随 ":::" 符号,它是用来间隔图片地址与图片标签名的。这些图片的合成效果如下:

按照上述步骤正确操作,最终可以得到合成图片。不过,如果图片标签名是中文的话,那么最终的合成图中每幅小图的标签应该是一串问号或乱码。这是因为 webcam 脚本是通过调用 imagemagick 图片处理工具箱中的 montage 程序实现图片合成的,如果在图片中使用了中文标签名,那么需要设定中文字体方能在合成图中正确显示中文。要解决这个问题,需要在 webcam 脚本中找到以下代码段:

...... ......

# Use ImageMagick again to assemble the wallpaper

cmd = "montage -geometry %dx%d \
-tile %dx%d \
-set caption '%%c' \
-pointsize 32 \
...... ......

然后在其中添加字体设置代码:

...... ......

# Use ImageMagick again to assemble the wallpaper
cmd = "montage -geometry %dx%d \
-font /usr/share/fonts/winfonts/msyh.ttf \
-tile %dx%d \
-set caption '%%c' \
-pointsize 32 \
...... ......

这样,这个问题便解决了。

来自:http://www.linuxgem.org/posts/8167

一键式备份你的 Gnome

用得最习惯的 Gnome 桌面配置往往不是一蹴而就,而是一段时间慢慢调整得来的,如果要更换电脑,或是转移到另外的 Linux 系统上工作,就要把原来的配置转移过来。

当然你可以直接打包 Gnome 配置的相关目录,甚至整个家目录,不过 Yourgnome 这个小脚本可以更加方便的完成备份和恢复的任务。

Yourgnome 就是一个 bash 脚本文件,他可以备份和恢复你的 Gnome 的:

  1. 所有主题
  2. panel 设置
  3. 蓝牙管理器设置
  4. Evolution 设置
  5. 归档管理器设置
  6. 屏保
  7. 会话设置
  8. Gnome-terminal 设置
  9. 音量控制设置
  10. Metacity 和 Compiz 设置
  11. Update-manager 和 Notifier 设置
  12. Totem 设置
  13. 网络管理器设置
  14. Screenlets 设置

询问保存位置后,yourgnome 会把所有的配置文件打包成一个 tar.gz。

脚本非常简单,以至于可以贴在这里:

#!/bin/sh
#-------------------------------------------#
#                     yourgnome version 1          #
#       http://code.google.com/p/yourgnome          #
#                            Licence: GPL            #
#       http://www.gnu.org/licenses/gpl.html   #
#-------------------------------------------#
clear;
echo "yourgnome Version 1 , http://code.google.com/p/yourgnome\n";
echo "this tool used to backup your Gnome in one tar.gz file !";
echo "Also, it restores that backup for you when you want !";
echo "\n";
echo "\033[1m 1] Backup.\033[0m";
echo "\033[1m 2] Restore.\033[0m";
read -p "->> 1 or 2 ?: " choice
if [ $choice -eq 1 ];
then
clear
echo "yourgnome Version 1 , http://code.google.com/p/yourgnome\n";
echo "this tool used to backup your Gnome in one tar.gz file !";
echo "Also, it restores that backup for you when you want !";
echo "\n";
echo "->> Gnome will be backed up for the user: \033[1m$USERNAME\033[0m";
echo "->> type the path in which you want to save the backup, then press Enter ..";
echo "->> e.g. /home/$USERNAME/Desktop"
read -p "->> Path: " path
clear
nowd=`date | awk '{ print $3_$2_$6 }'`
ran=`echo $$`
echo "yourgnome Version 1 , http://code.google.com/p/yourgnome\n";
echo "this tool used to backup your Gnome in one tar.gz file !";
echo "Also, it restores that backup for you when you want !";
echo "\n";
echo "\033[1m**-->> 0] Creating temporary folder ..\033[0m";
mkdir /tmp/yourgnome_$ran-$nowd
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 1] Creating backup of: Gnome Themes ..\033[0m";
cd $HOME/
tar -z -P --create --file /tmp/yourgnome_$ran-$nowd/yourgnome_themes_$ran-$nowd.tar.gz .themes
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 2] Creating backup of: Gnome Background Image ..\033[0m";
bgpath=`gconftool-2 -g /desktop/gnome/background/picture_filename`
bgdir=`dirname $bgpath`
fname=`basename $bgpath`
cd $bgdir/
tar -z -P --create --file /tmp/yourgnome_$ran-$nowd/yourgnome_bg_$ran-$nowd.tar.gz$fname
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 3] Creating backup of: Gnome Configuration Records ..\033[0m";
cd $HOME/
tar -z -P --create --file /tmp/yourgnome_$ran-$nowd/yourgnome_conf_$ran-$nowd.tar.gz .gconf
gconftool-2 --dump / > /tmp/yourgnome_$ran-$nowd/dump
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 4] Creating Info Files ..\033[0m";
echo "$ran-$nowd" > /tmp/yourgnome_$ran-$nowd/infofile
echo "$fname" > /tmp/yourgnome_$ran-$nowd/bgfile
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 5] Creating Final File ..\033[0m";
echo "\033[1mQ:\033[0m What name you want for the final backup file ?"
echo "e.g. MyBackUp"
read -p "filename: " n
cd /tmp/yourgnome_$ran-$nowd/
tar -z -P --create --file $path/$n.tar.gz *
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 6] Removing temporary folder ..\033[0m";
rm -rf /tmp/yourgnome_$ran-$nowd
echo "\033[1m**-->> Done !\033[0m";
fi
if [ $choice -eq 2 ];
then
clear
echo "yourgnome Version 1 , http://code.google.com/p/yourgnome\n";
echo "this tool used to backup your Gnome in one tar.gz file !";
echo "Also, it restores that backup for you when you want !";
echo "\n";
echo "type the path with filename of yourgnome backup .."
echo "->> e.g. /home/$USERNAME/Desktop/MyBackUp.tar.gz"
read -p "->> Backup File: " epath
echo "\033[1m**-->> 0] Creating temporary folder ..\033[0m";
if [ ! -d /tmp/yourgnome ]then
mkdir /tmp/yourgnome
fi

echo "\033[1m**-->> 1] Reading backup ..\033[0m";
tar --extract --directory=/tmp/yourgnome --file=$epath
getinfofile=`cat /tmp/yourgnome/infofile`
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 2] Extracting: Gnome Themes ..\033[0m";
cd /tmp/yourgnome/
tar --extract --directory=$HOME --file=yourgnome_themes_$getinfofile.tar.gz
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 3] Extracting: Gnome Configuration Records ..\033[0m";
tar --extract --directory=$HOME --file=yourgnome_conf_$getinfofile.tar.gz
gconftool-2 --load /tmp/yourgnome/dump /
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 4] Extracting: Gnome Background Image ..\033[0m";
echo "type a path to save the background image in .."
echo "->> e.g. /home/$USERNAME/Desktop"
read -p "->> Path: " np
tar --extract -P --directory=$np --file=yourgnome_bg_$getinfofile.tar.gz
bgf=`cat /tmp/yourgnome/bgfile`
gconftool-2 -s /desktop/gnome/background/picture_filename -t string $np/$bgf
echo "\033[1m**-->> Done !\033[0m";
echo "\033[1m**-->> 5] Removing temporary folder ..\033[0m";
rm -rf /tmp/yourgnome
echo "\033[1m**-->> Done !\033[0m";
fi

你也可以在 http://code.google.com/p/yourgnome 来下载最新的脚本。

来自:http://www.linuxgem.org/posts/7116

Audacious



Audacious 是一款轻量级的音乐播放器,基于GTK2,这使得其对多语言环境支持更好, Audaicous致力于提升音乐品质,并且支持广泛的音频编码格式.Audacious是大名鼎鼎的BMP(Beep Media Player)的衍生版,后者又是XMMS的衍生版, Audacious的回放引擎要比ubuntu默认的GStreamer强大的多,而且可以通过插件获得更强大的解码/功能.废话不多说,let’s begin~

1:安装Audacious:

1)Ubuntu 的软件源中一般都有Audacious, 你所需要做的就是打开终端:

[sudo apt-get install audacious] //这里是安装audacious主程序

[sudo apt-get install audacious-plugins audacious-plugins-extra]

//这里是安装audacious的插件/解码器

2)如果你的源里面没有,也可以选择编译安装:

在官网下载源码包:

http://audacious-media-player.org/downloads

和上面apt-get安装的一样的道理,需要下载两个包包:) ~~

audacious-1.5.1.tgz和audacious-plugins-1.5.1.tgz

下载完成之后解压出来,可以双击解压或者终端 tar -xvvf 压缩包名

3)如果你很熟悉编译安装的流程,可以跳过这里:

~终端cd 到你解压出来的目录

~特殊情况下需要做这一句: [chmod 755 configure]来给configure文件加可以执行的权限

~执行[./configure CFLAGS=-O2]:注意:如果是很少编译软件,可能在这里遇到很多问题,

先确保安装了最基本的编译环境: [sudo apt-get install build-essential]

这里举例说明一个问题:cofigure时遇到:

checking for GLIB… no

configure: error:

Cannot find Glib2! If you are using binary packages based system, check that you

have the corresponding -dev/devel packages installed.

于是可以按照给出的提示,在新利得里面搜索glib2,或者[aptitude search] 等等方法,总而言之

会找到这样一个东东:libglib2.0-dev,定睛一看介绍,这不就是你要找的么?安装之~~ 然后继续 configure, 遇到警告的话可以忽略的,遇到下一个error?如法炮制即可

~好了,能看到这里,我假设你前面已经通过了,现在在终端执行[make], 这一步执行的时间取决于你的 机器速度了,好在audacious是个很小的软件,最长不过几分钟就可以编译完成

notice:在做下一步前,确保configure和make你已经通过,不然hn安装失败,后果自负哦

~OK,历经千辛万苦,终于编译完成了,继续在终端输入[sudo make install] 就安装完成了

~不要忘了安装audacious-plugins,步骤同上:configure->make->make install

2:配置Audacious:

不会吧?又要配置?为什么每个软件装完都要折腾折腾才能用的顺手?汗…本地化一直是linux的伤..

继续努力吧~~

你可能遇到的问题:

1)播放列表乱码(这大概是你使用这个系统以来最头疼的问题了)

没问题,这样设置一下:

首选项->播放列表->元数据: (Preferences->Playlist->Petadata)

使用自動编码检测器:chinese (Auto character encoding detected for)

备用字符编码cp936 (Fallback character encoding)

2)音量很小:

首选项->重放增益->默认增益改为0.00(Preferences->Replay Gain->Default Gain)

也可以设置为大于0,但可能会产生失真

3)想要最小化到托盘,就像千千静听那样么?

首选项->插件->常规,选上Status Icon. (Preferences->Plugins->General)

点击托盘图标即可

3:恭喜恭喜,终于大功告成了, 享受Audacious给你带来的快乐吧!~~

本文原作者:OWNLINUX团队->坠落de咾鼠

Audacious

舒阁 (Shuge): 自由开放的数字图书馆系统

舒阁(shuge)是一个自由的数字图书馆,毓琦(yuki)是舒阁的命令行版本桌面客户端,可以用于下载和管理本地电子书籍。

shuge 有一个专门的仓库(Lee Tree,“李树”),用于收录电子书籍的种子文件(Lee Seed,“李树种子”);每个种子文件记录电子书籍的名称,类别,版本和下载地址等等元数据。

一般地,用户需要下载(第一次运行 yuki.py 时)或更新包含所有电子书籍元数据的种子文件,它们只是包含电子书籍名称和下载地址等等必要数据的文本文件,所以比较小。

下载一本电子书籍的流程

下载并安装 yuki 到 $HOME/shuge_desktop

wget http://shuge.googlecode.com/files/desktop-20090508.7z && 7z x desktop-20090508.7z -o$HOME/shuge_desktop

echo export PATH=$PATH:$HOME/shuge_desktop/desktop/bin/ >> ~/.bashrc && source ~/.bashrc

更新 Lee Tree

yuki.py -u

更新 Pear Tree(可选)

yuki.py -U

搜索名字包含 lolita 的电子书籍

yuki.py -s lolita

搜索描述包含 lolita 的电子书籍

yuki.py -S lolita

下载 lolita

yuki.py --ask lolita

--ask 参数表示下载前要确认

阅读 lolita

yuki.py -r lolita

删除 lolita

yuki.py -d lolita

如何向 shuge 提交、共享电子书籍

由于上前书籍分类不太合理,书籍元数据条目定义也不稳定,所以我建议您暂时提交书籍清单到 shuge dot lee at gmail dot com 接受格式为: txt html pdf chm tex

如果您使用的是 Linux,您可以使用 tree 程序生成书籍列表。

如果您使用的是 Windows,使用下面的命令生成。 dir /S $dir > ebook.txt

无论如何,我不建议、不提供、不怂恿您提交、共享有版权问题的书籍。

shuge 的 tree 主要分两种,一种是收录有专人长期、稳定、固定维护和更新的、以自由许可(CC 系列或 GFDL)发布的书籍的种子的李树──Lee Tree,另一种是,非 shuge 开发者或编辑维护的各种各样的 Pear Tree。

有 Gentoo 使用经验的人,会很容易明白 Lee Tree 和 Portage Tree,Pear Tree 和 Overlay 之间的关系。

2009/05/10

Weather wallpaper




Weather wallpaper 是一款蛮有趣的软件,它可以根据你所在位置的天气情况实时创建墙纸并自动设置到你的 Linux 桌面。
在启动 Weather wallpaper 后,它将显示预设位置的天气信息。你需要点击状态栏的图标,并到首选项中将位置更改为你实际所在的地方
Weather wallpaper 提供有 Debian/Ubuntu 源、Archlinux 用的 PKGBUILD、Gentoo 用的 ebuild,另外也包含源码包可以下载。
Weather wallpaper

2009/05/09

Freeciv: 文明游戏


Freeciv 是一个类”席德梅尔文明”系列的文明游戏。开源软件,可以联网。在 Debian 上面分为服务器端和客户端。


Freeciv 的风格类似文明 2,是一个回合制的策略游戏;模拟地球上的文明发展里程。从最初的一个移民和农民发展现代大规模的城市。发射航天飞机。很有一种历史感。

当前流行的游戏“孢子”就是模仿文明游戏。

Freeciv

2009/05/07

Wavemon: 无线网络监视器



Wavemon 允许你对无线网络设备进行监视,并为你提供诸如设备配置、加密、电源管理参数、网络信息、连接质量、访问点范围等重要信息。

Wavemon 是基于 Ncurses 界面的程序,源代码可从其主页获取。

Wavemon