Monday, October 18, 2010

PyGTK - How to get text size in pixels

When you search internet for simplest way how to get size of text in pixels in PyGTK you will end up with many tutorials, but still you will not know how to do it. Probably best knowledge base I have found is faq.pygtk.org.

You need only two commands, if you have already any gtk.Widget:

pango = widget.create_pango_layout('your text')

(text_width, text_height) = pango.get_pixel_size()


You should take into account that text_width and text_height are not constant for your pygtk application during runtime, because user can change system theme, and your application should react accordingly. This type of change is propagated to your application through pango.Layout.context_changed() event.

Thursday, April 16, 2009

VirtualBox OSE in Fedora 10 (compilation from SVN sources)

all steps should be executed as root (maybe except step 2. and 3., but this will involve more work)

1. dependencies for Fedora 10

yum install subversion dev86 glibc-devel glibc-headers iasl kernel-devel kernel-headers libcap-devel libIDL-devel libpng-devel libX11-devel libXcursor-devel libXext-devel libxml2-devel libXmu-devel libxslt-devel libXt-devel pulseaudio-libs-devel python-devel qt-devel SDL-devel

2. download current version from subversion

mkdir /usr/src/virtualbox
cd /usr/src/virtualbox/
svn co http://www.virtualbox.org/svn/vbox/trunk vbox

3. configure and compile

cd vbox
./configure
source ./env.sh
kmk all

4. permissions

cd out/linux.x86/release/bin
chcon -t texrel_shlib_t *.so components/*.so
chown root.root VirtualBox VBoxHeadless VBoxSDL VBoxBFE VBoxNetDHCP VBoxNetAdpCtl
chmod 4511 VirtualBox VBoxHeadless VBoxSDL VBoxBFE VBoxNetDHCP VBoxNetAdpCtl

5. symbolic links (solving problem with NS_ERROR_FACTORY_NOT_REGISTERED)

cd components
ln -s ../VBoxDDU.so .
ln -s ../VBoxREM.so .
ln -s ../VBoxRT.so .
ln -s ../VBoxVMM.so .
ln -s ../VBoxXPCOM.so .

6. kernel modules

cd ../src
make
make install

7. check permissions and ownership for tmp (again solving problem with NS_ERROR_FACTORY_NOT_REGISTERED)

ls -ld /tmp

permissions should be drwxrwxrwt, user root, group root
if not use following commands to fix:

chmod 1777 /tmp
chown root:root /tmp

8. final steps

mv /usr/src/virtualbox/vbox/out/linux.x86/release/bin /usr/lib/virtualbox
ln -s /usr/lib/virtualbox/VirtualBox /usr/bin/VirtualBox
ln -s /usr/lib/virtualbox/VBoxManage /usr/bin/VBoxManage
ln -s /usr/lib/virtualbox/VBoxTunctl /usr/bin/VBoxTunctl
ln -s /usr/lib/virtualbox/VBoxHeadless /usr/bin/VBoxHeadless
ln -s /usr/lib/virtualbox/VBoxSDL /usr/bin/VBoxSDL
ln -s /usr/lib/virtualbox/VBoxVRDP /usr/bin/VBoxVRDP

Friday, July 13, 2007

Initialize Oracle APEX (HTMLDB) session state for debugging

If you ever wanted to debug your code written for Oracle Application Express (HTMLDB), you probably run into problem when using function V(...) to access user session variables. To make code runnable outside of APEX environment you should not reference APEX session state, but this is not always easy and sometimes really impossible.

In my application I use many views referencing function V() and also some of my procedures use this function, but it is very hard to debug such procedure or view, because session state is not accessible and so function V() always returns NULL.

After some time of research I found very easy way how to create your debug environment with any session state as you wish.

Key to success is package wwv_flow. Inside this package are all variables containing your session state. They have names like g_user, g_instance etc. As you see they do not correspond to names in application where are names like APP_USER, APP_SESSION etc.

These are so called built-in variables, but what to do to initialize your own variable. There are two arrays g_substitution_item_name and g_substitution_item_value for this purpose. g_substitution_item_name contains names of your variables and g_substitution_item_value contains values on their corresponding index.

Below is small example how to initialize your session before debugging outside APEX.

wwv_flow.g_user := 'APP_USER'; -- V('APP_USER')
wwv_flow.g_instance := 12345678901234; -- V('APP_SESSION')
wwv_flow.g_flow_id := 101; -- V('APP_ID')
wwv_flow.g_flow_step_id := 1; -- V('APP_PAGE_ID')

wwv_flow.g_substitution_item_name(1) := 'ITEM_NAME';
wwv_flow.g_substitution_item_value(1) := 'ITEM_VALUE';
wwv_flow.g_substitution_item_name(2) := 'P1_ITEM';
wwv_flow.g_substitution_item_value(2) := 'P1_ITEM_VALUE';


Complete set of variables in wwv_flow:

FLOW_SESSIONwwv_flow.g_instance
FLOW_IDwwv_flow.g_flow_id
FLOW_ALIASwwv_flow.g_flow_alias
FLOW_USERwwv_flow.g_user
FLOW_USER_IDwwv_flow.g_user_id
FLOW_STEP_IDwwv_flow.g_flow_step_id
FLOW_PAGE_IDwwv_flow.g_flow_step_id
FLOW_CURRENT_MIN_ROWwwv_flow.g_flow_current_min_row
FLOW_CURRENT_MAX_ROWSwwv_flow.g_flow_current_max_rows
FLOW_CURRENT_ROWS_FETCHEDwwv_flow.g_flow_current_rows_fetched
FLOW_LAST_TAB_PRESSEDwwv_flow.g_last_tab_pressed
APP_SESSIONwwv_flow.g_instance
APP_IDwwv_flow.g_flow_id
APP_ALIASwwv_flow.g_flow_alias
APP_USERwwv_flow.g_user
APP_USER_IDwwv_flow.g_user_id
APP_PAGE_IDwwv_flow.g_flow_step_id
APP_CURRENT_MIN_ROWwwv_flow.g_flow_current_min_row
APP_CURRENT_MAX_ROWSwwv_flow.g_flow_current_max_rows
APP_CURRENT_ROWS_FETCHEDwwv_flow.g_flow_current_rows_fetched
APP_LAST_TAB_PRESSEDwwv_flow.g_last_tab_pressed
APP_UNIQUE_PAGE_IDwwv_flow.g_unique_page_id
APP_TRANSLATION_IDwwv_flow.g_translated_flow_id
APP_TRANSLATION_PAGE_IDwwv_flow.g_translated_page_id
REQUESTwwv_flow.g_request
USERwwv_flow.g_user
USER_KNOWN_ASwwv_flow.g_user_known_as
SESSIONwwv_flow.g_instance
INSTANCEwwv_flow.g_instance
PUBLIC_URL_PREFIXwwv_flow.g_public_url_prefix
AUTHENTICATED_URL_PREFIXwwv_flow.g_dbauth_url_prefix
PUBLIC_USERwwv_flow.g_public_user
AUTHENTICATIONwwv_flow.g_authentication
POPUP_FILTERwwv_flow.g_popup_filter
CURRENT_PARENT_TAB_TEXTwwv_flow.g_current_parent_tab_text
OWNERwwv_flow.g_flow_owner
MAP1_Xwwv_flow.g_map1(1)
MAP1_Ywwv_flow.g_map1(2)
MAP2_Xwwv_flow.g_map2(1)
MAP2_Ywwv_flow.g_map2(2)
MAP3_Xwwv_flow.g_map3(1)
MAP3_Ywwv_flow.g_map3(2)


Some (maybe) useful variables outside wwv_flow:

FLOW_JOBwwv_flow_plsql_job.g_job
APP_JOBwwv_flow_plsql_job.g_job
FLOW_SECURITY_GROUP_IDwwv_flow_security.g_security_group_id
APP_SECURITY_GROUP_IDwwv_flow_security.g_security_group_id
COMPANY_IDwwv_flow_security.g_security_group_id
WORKSPACE_IDwwv_flow_security.g_security_group_id

Thursday, July 12, 2007

Solving Windows Vista Shadow Copy Problem

I get used to new Vista feature known as "Previous Versions". It allows you to access previous version of any file. Previous versions of all modified files are created every day. Suddenly this great function stopped working. Here is short log how I managed to make it working again.

It all started with complete backup of my computer then I removed all previous versions from the system with Disk Cleanup / More Options / System Restore and Shadow Copies. After this moment no more shadow copies of changed documents was created, but as mentioned above they should be created on daily basis. Maybe I should also mention that I installed one cpu intensive peace of software these days, but I didn't suspect it as a reason.

I used following command to check how much space shadow copies really occupy on my disk:

vssadmin list shadowstorage

two weeks after cleanup followed by regular using of my computer the result was:

vssadmin 1.1 - Volume Shadow Copy Service administrative command-line tool
(C) Copyright 2001-2005 Microsoft Corp.

Shadow Copy Storage association
For volume: (C:)\\?\Volume{3face778-0410-11dc-bb91-806e6f6e6963}\
Shadow Copy Storage volume: (C:)\\?\Volume{3face778-0410-11dc-bb91-806e6f6e6963}\
Used Shadow Copy Storage space: 0 B
Allocated Shadow Copy Storage space: 0 B
Maximum Shadow Copy Storage space: 16.768 GB


really no previous version of any file on entire disk after two weeks! I checked services "Volume Shadow Copy" and "Microsoft Software Shadow Copy Provider", both was set to "Manual" startup type as should be.

I tried to create restore point manually. Used Shadow Copy Storage was 18 MB right away. After maybe 20 minutes even 427 MB. Instantly previous versions of modified files appeared. Looks good, but why restore point is not created automatically?

I checked "Task Scheduler" service, which should be set to "Automatic" and started. Then I went to "Scheduled tasks", which should contain SystemRestore. Yes, they do, but Last Run Time was about two weeks ago. Task Triggers seemed OK, but there is something suspicious under Conditions "Start the task only if the computer is idle for 10 minutes", and that was the reason. I have Folding At Home running in the background eating one cpu all the time and probably this blocks automatic SystemRestore, so I removed that condition and everything is working now.

I hope this can help somebody with the same problem.

Notepad replacement

What to use when Windows Notepad is not enough (Dec 1, 2006)

Some time before I decided to stop using standard windows notepad even for simple text tasks, because it lacks some really needed functionality like unix text support, multiple undo/redo, stay on top ...
I decided to search for some interesting program that can replace notepad once forever on my computer. This program must fulfill some requirements such as to be fast, small and free.
Programs meeting this criteria can be divided to two categories: lightweight multi-window editors and heavyweight single-window editors

Multi-window notepads (real notepad replacements)

All of them looks very similar to notepad, but add missing functionality as:
  • Recent file history
  • Unix text support (LF vs CR/LF line-ends)
  • Stay on top of all windows
Programs in this category are all quite simple. They do not need installation and all of them need just one executable to work.

versionfile sizemultiple undo/redobig filesvery big filesbinary filesutf8rectangular selectionregexp searchsyntax highlight

my rating

notepadXP69120NYNYYNNN4
metapad3.5195744YNNNNNNN5
notepad21.0.12552960YYYYYYYY1
ted notepad5.2.1beta122880NYYN*YNNN2
win32pad1.5.10.153248YNNYY*NNN3
edxor1.6530720NNNYY*NNN3

* Ted notepad can open file with binary content, but changes some binary characters.
* Utf-8 support was correct, but Unicode (Utf-16) was not.
* rating: lower is better

Single-window editors

Most of them are near to complete development environment and so cannot be directly compared to previous category.
They have some common functions:
  • Tabbed interface

  • Unix text support

version
size
multiple undo/redo
big files
very big files
binary files
utf8
rectangular selection
regexp search
syntax highlight
my rating
notepad++
3.9
2,2 MB
Y
Y
Y
Y
Y
Y
Y
Y
1
gridinsoft notepad lite
3.2.1.4
3,7 MB
Y
Y
Y
Y
Y*
Y
N
Y
3
PSPad
4.5.2002
3,8 MB
Y
Y
Y
Y
Y
Y
Y
Y
1
programmer's notepad 2
2.0.6.1
3,6 MB
Y
Y
Y
Y
Y
Y
Y
Y
2
NoteTab Light
4.95
3,4 MB
N
Y
N
N
Y
N
Y
N
4

* Only Gridinsoft notepad lite and PSPad can be used as standalone executable.
* In PSPad I cannot find any history of recent files.
* In PSPad and Programmers's notepad is no possibility to to make window always on top.
* Gridinsoft notepad light cannot open Utf-16 files correctly.

Conclusion

For me the winner is clear: notepad2.

Update (July 12, 2007)

After some time of real use of notepad2, there was two big issues for me:
  • notepad2 does not have detection if same file is already opened in another window

  • notepad2 has problems to work with larger files on slower computers (at least version 1.0.12)
Then I changed my default editor to ted notepad, which has only one bigger issue for me and that is single step undo.

Update (September 10, 2007)

Single step undo was so big issue, I had to start my search for good notepad replacement again. What I found is AkelPad, which is perfect: small with all functions I ever need.