11/27/2010

Setting mp3 quality when using rhythmbox to sync iphone or ipod

When I sync music library with iphone in ubuntu, rhythmbox convert almost any type of music file into mp3 file automatically.

However, the default quality set is vbr, and I want the best quality, i.e., 320kbps, not vbr.

Rhythmbox - Edit - Preference - Music - Edit Preferred format
Select MP3.

Change the setting like this :

audio/x-raw-int,rate=44100,channels=2 ! lame name=enc mode=0 vbr=0 bitrate=320 ! id3v2mux



.

11/15/2010

django + apache server 1

1. Set apache to read my django project

cat /etc/apache2/httpd.conf

(location "/")
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath "['[path.to.django.project]', '[path.to.other.location.which.has.python.code]'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE [projectName].settings
PythonDebug On
(/location)

where, "(" and ")" should be replaced with "<" and ">"

In web browser, http://localhost/ gives the "It worked" page of django.
If "import error" occur, check the [path.to.directory] point out the right directory which contains the module.

2. utf-8 setting

$ cat /etc/apache2/envvars

...
export LANG=ko_KR.UTF-8
export LC_ALL=ko_KR.UTF-8
...

$ /etc/init.d/apache2 restart


3. Running a development server with apache mod_python

If a django python code was changed, apache server must be restarted.
To avoid this, just set

MaxRequestsPerChild 1

in /etc/apache2/apache2.conf

This force apache to reload everything for each request.


When debugging, use the code below to display a debugging information.

assert False, 'debug text'


4. Make database (mysql)


5. Make project, app

django-admin startproject (aaa)
cd aaa
./manage.py startapp (bbb)


in settings.py

add the code below

import os
ROOT_PATH = os.path.dirname(__file__)

add to TEMPLATE_DIRS

ROOT_PATH + '/templates',


and in INSTALLED_APPS, add

'aaa.bbb',


change the LANGUAGE_CODE option like

LANGUAGE_CODE = 'ko-KR'


and setting DB infomation.

DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'dbname' # Or path to database file if using sqlite3.
DATABASE_USER = 'userid' # Not used with sqlite3.
DATABASE_PASSWORD = 'password' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.


6. sync db

manage.py syncdb

Here, set user name and password.


7.

11/11/2010

Converting a date value read from a calc cell into readable format using python

When a date value, such as "2010-10-12" or etc., is in a cell,

oCell.getValue() and oCellRange.DataArray methods give just a number, not date format,
while oCell.getString() gives a date format string

The code below shows how to convert a date value into date format.


#!/usr/bin/python
import datetime, uno

# .... some lines to get oCell

# cell value shown in calc -> 2010-10-12
dateValue = oCell.getValue()
# get date value from a cell with getValue() method,
# note that I did NOT used the getString() method.

print dateValue # this gives 40463.0 <- This means the elapsed date from 1899-12-30

DateValue = datetime.timedelta(dateValue) + datetime.date(1899, 12, 30) # converting
# DateValue -> datetime.date(2010, 10, 12)

print DateValue # this gives 2010-10-12.



* The starting date 1899-12-30 can be changed in option > openoffice Calc > calculate > date

11/06/2010

Control Calc chart using python

ref: http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Structure_of_Charts

ref: http://www.oooforum.org/forum/viewtopic.phtml?p=56037


Legend show/hide

oChart = oSheet.Charts.getByIndex(0).EmbeddedObject
oChart.HasLegend = False


Set main title

oChart.HasMainTitle = True
oChart.Title.String = "main-title-string"


Set XAxis title

oDiagram = oChart.Diagram
oDiagram.HasXAxisTitle = True
oDiagram.XAxisTitle.String = "x-title"


Set XAxis label text rotation

oDiagram.XAxis.TextRotation = 90 * 100 # for 90 degree rotation

Set cell border

oBorderLine = createUnoStruct("com.sun.star.table.BorderLine2")
oBorderLine.InnerLineWidth = 2
oBorderLine.Color = 255 # blue

oCell.LeftBorder = oBorderLine
oCell.RightBorder = oBorderLine

Set cellRange border (apply to every cells)

oCellRange = oSheet.getCellRangeByPosition(1, 2, 3, 4)
oCellRange.BottomBorder = oBorderLine

Set cellRange TableBorder (apply to only edge lines not inner lines)

oCellRange.TableBorder -> com.sun.star.table.TableBorder

oTableBorder = createUnoStruct("com.sun.star.table.TableBorder")

# there are 2 types: BorderLine and BorderLine2. Confusing, be careful to choose.
oBorderLine = createUnoStruct("com.sun.star.table.BorderLine")
#oBorderLine2 = createUnoStruct("com.sun.star.table.BorderLine2")

# make oTableBorder object
oTableBorder.BottomLine = oBorderLine
oTableBorder.TopLine = oBorderLine
oTableBorder.LeftLine = oBorderLine
oTableBorder.RightLine = oBorderLine

# ... something like this ...
oTableBorder.IsTopLineValid = True
oTableBorder.IsBottomLineValid = True
oTableBorder.IsLeftLineValid = True
oTableBorder.IsRightLineValid = True

# set
oCellRange.TableBorder = oTableBorder
### Sometimes the code above does not work.
### Be sure that "oTableBorder.IsTopLineValid = True" line is correct.



.....

11/03/2010

ubuntu nautilus dirs config

$ cat ~/.config/user-dirs.dirs
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/바탕화면"
XDG_DOWNLOAD_DIR="$HOME/다운로드"
XDG_TEMPLATES_DIR="$HOME/서식"
XDG_PUBLICSHARE_DIR="$HOME/공개"
XDG_DOCUMENTS_DIR="$HOME/문서"
XDG_MUSIC_DIR="$HOME/음악"
XDG_PICTURES_DIR="$HOME/"
XDG_VIDEOS_DIR="$HOME/"