Thursday, December 27, 2007

Get Text from multi column ListBox in Python


y = self.listCtrl.GetItem(a,n)
txt = y.GetText()


where  a =  Row Number n = Column Number

Tuesday, December 25, 2007

Few TK form tricks in Python.

1. Disable max button:
root.overrideredirect(0)

2. Remove all the decorations :
root.overrideredirect(1)

3. Disable Resize:
root.resizable(0,0)

Sunday, December 23, 2007

Adding file type association using vbScript

fext = "fcz"
prgid = "FCZ File"
des = "FCZ File"
extanm = "c:\Program files\TestApps\AppStart.exe"
Set o = CreateObject("wscript.shell")
o.regwrite "HKCR\." + fext + "\" , prgid ', "REG_SZ"
o.regwrite "HKCR\" + prgid + "\", des ', "REG_SZ"
'o.regwrite "HKCR\" + prgid + "\DefaultIcon\", extico, "REG_SZ"
o.regwrite "HKCR\" + prgid + "\Shell\","Open"
o.regwrite "HKCR\" + prgid + "\Shell\Open\Command\", """" + extanm + """ ""%1""", "REG_SZ"

Playing with Registry using Python.,

def regReadValue( regKey, subKey, name ):
#print regKey
aReg = ConnectRegistry(None,regKey)
aKey = OpenKey(aReg, subKey)
index = 0
data = []
while 1:
try:
regName = EnumValue(aKey, index)
if name == regName[0]:
data = regName[1:]
print data
return data
except:
break
index = index + 1
return data

def regRead( regKey, subKey):
#print regKey
aReg = ConnectRegistry(None,regKey)
aKey = OpenKey(aReg, subKey) # r'SOFTWARE\Microsoft\Windows\CurrentVersion\Run')
index = 0
data = []
while 1:
try:
print("Enumkey =" + subKey + "\\" + EnumKey(aKey, index))
data.append( subKey + "\\" + EnumKey(aKey, index))
except:
break
index = index + 1
return data

def regWrite(regKey, subKey, regValue, regData, regType):
aReg = ConnectRegistry(None,regKey)
print subKey
aKey = CreateKey(aReg, subKey) #, 0, KE)
try:
SetValueEx(aKey,regValue,0, regType, regData)
except EnvironmentError:
print "Encountered problems writing into the Registry..."
CloseKey(aKey)
CloseKey(aReg)

def regDelete(regKey, subKey):
#aReg = ConnectRegistry(none,regKey)
reg = regRead(regKey, subKey)
for a in reg:
regDelete(regKey,a)
print a
DeleteKey(regKey, subKey)

Monday, December 17, 2007

Populating Two column in Pascal

Following code can populate them:

with listview1.Items.Add do
begin
caption := 'first Column' ;
SubItems.Add('Second Column');
end ;

Thursday, December 13, 2007

Read and Set CheckBoxes in PythonWin using win32...

# A demo of the win32rcparser module and using win32gui

import win32gui
import win32api
import win32con
import win32rcparser
import commctrl
import sys, os
import win32ui

# We use the .rc file in our 'test' directory.
try:
__file__
except NameError: # pre 2.3
__file__ = sys.argv[0]

this_dir = os.path.abspath(os.path.dirname(__file__))
g_rcname = os.path.abspath(
os.path.join( this_dir, "prefEditing.RC"))

if not os.path.isfile(g_rcname):
raise RuntimeError, "Can't locate resource file (should be at '%s')" % (g_rcname,)

class DemoWindow:
def __init__(self, dlg_template):
self.dlg_template = dlg_template

def CreateWindow(self):
self._DoCreate(win32gui.CreateDialogIndirect)

def DoModal(self):
return self._DoCreate(win32gui.DialogBoxIndirect)

def _DoCreate(self, fn):
message_map = {
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
}
return fn(0, self.dlg_template, 0, message_map)

def OnInitDialog(self, hwnd, msg, wparam, lparam):
self.hwnd = hwnd
# centre the dialog
desktop = win32gui.GetDesktopWindow()
l,t,r,b = win32gui.GetWindowRect(self.hwnd)
dt_l, dt_t, dt_r, dt_b = win32gui.GetWindowRect(desktop)
centre_x, centre_y = win32gui.ClientToScreen( desktop, ( (dt_r-dt_l)/2, (dt_b-dt_t)/2) )
win32gui.MoveWindow(hwnd, centre_x-(r/2), centre_y-(b/2), r-l, b-t, 0)

def getCheckBoxValue(self, hwnd, cbid):
## Gets the Value of the CheckBox #
b = win32gui.GetDlgItem(hwnd, cbid)
val = win32gui.SendMessage(hwnd, win32con.BM_GETCHECK, 0, 0) & win32con.BST_CHECKED
return val

def setCheckBoxValue(self, hwnd, cbid, val):
## Gets the Value of the CheckBox #
b = win32gui.GetDlgItem(hwnd, cbid)
win32gui.SendMessage(b,win32con.BM_SETCHECK,val,0)

def OnCommand(self, hwnd, msg, wparam, lparam):
# Needed to make OK/Cancel work - no other controls are handled.
id = win32api.LOWORD(wparam)
if id in [win32con.IDOK, win32con.IDCANCEL]:
win32gui.EndDialog(hwnd, id)
print id
a = win32gui.GetDesktopWindow()
# This returns the hwnd for the control
b = win32gui.GetDlgItem(hwnd, id)
# ("Hello")
# Changes the Text of control
# # win32gui.SetWindowText(b,"Test")
#yt = win32gui.DialogBoxParam(hwnd, id)
#print b, yt
#yt = win32gui.GetIconInfo( b)
print "Message :" + str(msg)
#win32gui.GetDlgItem(yt)
#print yt
#win32gui.SendMessage(b, commctrl.CDIS_SELECTED,0,0)
##win32gui.DialogBoxParam()
self.setCheckBoxValue(hwnd, id, 0)
#cb1=a.GetDlgItem(win32ui.IDC_PROMPT1)

def OnClose(self, hwnd, msg, wparam, lparam):
win32gui.EndDialog(hwnd, 0)

def OnDestroy(self, hwnd, msg, wparam, lparam):
pass

def DemoModal():
# Load the .rc file.
resources = win32rcparser.Parse(g_rcname)
for id, ddef in resources.dialogs.items():
print "Displaying dialog", id
w=DemoWindow(ddef)
w.DoModal()

if __name__=='__main__':
flags = 0
for flag in """ICC_DATE_CLASSES ICC_ANIMATE_CLASS ICC_ANIMATE_CLASS
ICC_BAR_CLASSES ICC_COOL_CLASSES ICC_DATE_CLASSES
ICC_HOTKEY_CLASS ICC_INTERNET_CLASSES ICC_LISTVIEW_CLASSES
ICC_PAGESCROLLER_CLASS ICC_PROGRESS_CLASS ICC_TAB_CLASSES
ICC_TREEVIEW_CLASSES ICC_UPDOWN_CLASS ICC_USEREX_CLASSES
ICC_WIN95_CLASSES """.split():
flags |= getattr(commctrl, flag)
win32gui.InitCommonControlsEx(flags)
# Need to do this go get rich-edit working.
##win32api.LoadLibrary("riched20.dll")
DemoModal()

Monday, November 26, 2007

Read Registry Files in Python

Reading Python files using open function will not work as Reg files are encoded using UTF-16, thus use the following code to read it

import codecs regFile = codecs.open ("c:/temp/Deve.reg", encoding="utf_16")
reg = regFile.read ()
regFile.close ()
print reg

Thursday, November 22, 2007

Softgrid Helper Ver: 0.02 Released.

Hello All,

Today I am releasing a newer & better version of the Softgrid Helper.

New Features:
1. New Installer: The msi package has been created using War Setup which internally uses Microsoft WIX.
2. Logging Enabled: Now most of the task has been logged so that any issue can be debugged.
3. New Name & Icons: New icons make this application look better.

Bug Fix(es) :
1. Refresh All and clean up issues have been resolved.

The installer can be downloaded from Here

Thanks and Regards,
Mayank Johri

Note:
1. This software is should not be used in production and has not been tested at all.
2. This software has been released under GNU 3.0 License.

Adding the Shortcuts to StartMenu

1. Create a new Directory in "Setup Files" and set the ID as "ProgramMenuFolder"  and set Name as "Programs".

2.  Create a new Directory under this directory and set ID as "ProgramMenuDir".

3. In the shortcut set the Directory as "ProgramMenuDir"

Sunday, November 18, 2007

Adding Scrollbars to TCL/TK listbox in python

The listbox itself doesn’t include a scrollbar. Attaching a scrollbar is pretty straightforward. Simply set the xscrollcommand and yscrollcommand options of the listbox to the set method of the corresponding scrollbar, and the command options of the scrollbars to the corresponding xview and yview methods in the listbox. Also remember to pack the scrollbars before the listbox. In the following example, only a vertical scrollbar is used. For more examples, see pattern section in the Scrollbar description.
frame = Frame(master)
scrollbar = Scrollbar(frame, orient=VERTICAL)
listbox = Listbox(frame, yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)listbox.pack(side=LEFT, fill=BOTH, expand=1)

Copied from http://effbot.org/tkinterbook/listbox.htm for personal use only.
Ok, now how to do this using GUI Builder:

Set the "yscrollcommand" of listbox to scrollbar.set in properties section and command of scrollbar to listbox.yview

Monday, October 29, 2007

This is my second tool which i use to clean up the OSD files, and prepare them to promote them to production server by updating the server name in the OSD files by right clicking them and selecting "update to Prod Server" in Windows Explorer.

The tool can be downloaded from OSD Helper
The source code of the package is also available with the package and is released under GNU 3 License.

NOTE: This program has not been tested fully and will contain many bugs, kindly report them and this program has not been intended to be used in production. Use it at your own risk.

Also comments and suggestions are always welcome.

Tuesday, October 16, 2007

Softgrid Helper.

I  have developed a new tool which can be used to cleanup the cache of softgrid client, refresh specific softgrid server or refresh all server.

Download it from here http://sourceforge.net/projects/softgridhelper/

Sunday, September 16, 2007

Another Downloader... batch downloader ....

The script can be used to batch download the files from the internet. say for example the website contain files from 1.zip to 100.zip at

http://www.something.com/zipfiles/ folder. then the download command will be

AnotherDownloader.py http://www.something.com/zipfiles/*.zip 1 100 /home/test/download

the above command will download the files to /home/test/download folder.

AnotherDownloader.pdf

Wednesday, August 29, 2007

rm2ogg convertor

Use the following command to convert rm files to ogg files.

$ mplayer "aks1.rm" -ao pcm:file=temp.wav | oggenc -q 10 -o "aks1.ogg" temp.wav

$ rm temp.wav

Display Video in VLC when using compiz is enabled.

For some reason, when compiz is running VLC does not show any video. I found the work around to the issue by following the below instructions

  1. Start VLC and click on Settings -> Preferences.

  2. Expand Video -> Output modules.

  3. Select Output modules, and check the  checkbox at the bottom right that says Advanced options.

  4. Select the option to select a different output device. Pick X11 video output, click on Save.

Sunday, August 26, 2007

mp32ogg convertor

I am adding a script which will convert the mp3 from a folder to ogg. mpg123 and oggenc are prerequisite for this scirpt. It can be download from http://mayankjohri.files.wordpress.com/2007/08/mp32ogg.pdf
The PreReq's are mpg123, vorbis-tools, python-id3

Saturday, August 25, 2007

Setting Evolution for Gmail Account

Steps to follow

  1. Enable the POP & SMTP service on gmail accont.

  2. Start Evolution

  3. Add New Account by clicking "Edit" -> "Preference"

  4. In "Accout Details", press "Add" Button

  5. Select "Forward"

  6. Enter your Account Name and Email ID and select "Forward"

  7. Select "POP" server for "Receiving Email"

  8. Under "Configuration" section enter "POP.gmail.com" and your email username

  9. Under "Security" select "SSL encryption"

  10. Under "Authentication Type" select Password

  11. Select "Forward"

  12. Select "Forward" for "Receiving Options

  13. In "Sending Email" select

    1. Server Type : SMTP

    2. Under "Server Configureation" add "SMTP.GMAIL.COM" for Server

    3. Under "Security" select "SSL Encryption" as "Use Secure Connection"

    4. Enter Username under Authentication section.



  14. Select "Forward"

Tuesday, August 21, 2007

Slackware: Enabling package update through online mirrors

Unfortunately Slackware 12.0 does not unable update of OS by default, slackpkg needs to be installed from the install CD/DVD which is located in "extra\slackpkg" folder.

installpkg slackpkg*.tgz

uncomment only one mirror on /etc/slackpkg/mirrors file which represent your version.

slackpkg update; slackpkg upgrade-all

the above command will upgrade your machine.

Friday, August 17, 2007

Adding HTTP Proxy Details in SVN

Edit the server file at ~/.subversion/servers

$ vi ~/.subversion/servers

Add or update the following values in the file

http-proxy-host = <Fill the proxy server name>
http-proxy-port = <Proxy Port>

Thursday, August 16, 2007

Remedy for Bug #89741: with Compiz, the title bar on maximized windows are drawn completely white.

When Compiz is running then the title bar on maximized windows are drawn completely white for my Laptop R32.

The solution of the issue is to create /etc/drirc file with the following contents:
<option name="allow_large_textures" value="2" />

Tuesday, August 14, 2007

Add Context Menu for a FileType

Eg:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\\.osd]
@="SoftGrid.osd.File"
"Content Type"="application/softricity-osd"

[HKEY_CLASSES_ROOT\\SoftGrid.osd.File\\shell\\UpdateOSD]

[HKEY_CLASSES_ROOT\\SoftGrid.osd.Fileshell\\UpdateOSD\\Command]
@="\"C:Program Files\\AddTabsToOSD\\addTabsToOSD.exe\" \"%1\""

The above reg key will add UpdateOSD menu for .osd file type

Wednesday, August 8, 2007

Slackware's pacman through HTTP Proxy

edit the /etc/pacman.conf on your slackware/frugalware machine and add or update the following.

ProxyServer = your.proxy.server	ie	proxy.domain.com

ProxyPort = your_proxy_port	ie	8080 

Tuesday, July 24, 2007

mp3 to ogg

1. apt-get install mpg321 vorbis-tools (If you don't have them on your machine)
Note: If you get error, check that you have contrib and non-free depositories in your sources list

2.Code: mpg321 input.mp3 -w raw && oggenc raw -o output.ogg
Note: raw is just a file name, it could be anything you want...

Tuesday, June 5, 2007

Tuesday, May 15, 2007

Setting Null as root password

sudo passwd -l root

This command will set Null as the root password. {To be used in ubuntu}

Adding Network shortcuts in MSI packages

Steps

  1. Create a property eg. INSTDIR in Property table

  2. Populate it with the network directory

  3. Create a property eg SHORTCUT1 in Property table /* IF not using Wise

  4. Polulate it with the full UNC path along with the executable name  /* IF not using Wise.

  5. Create a shortcut using the shortcut under the shortcut table

  6. Update the WkDir coloum in Shorcut table with INSTDIR (no NOT add brakets [] before and after INSTDIR).

Monday, April 9, 2007

Adding Public keys for apt-get

When one adds a new repositry in sources.list file then there is a high possibility that we face the following error when `apt-get update` command is executed

------------------------- Error -----------------

W: GPG error: http://edevelop.org unstable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7E5D69A103CA4243
W: GPG error: http://ftp.debian-unofficial.org sarge Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D5642BC86823D007
W: There are no public key available for the following key IDs:
B5D0C804ADB11277
W: You may want to run apt-get update to correct these problems
-------------------------------------------------

To resolve this issue i have created a script which when provided the KeyID will download the key and add it to your key ring.

---------------------------------- Script ------------------------

gpg --keyserver subkeys.pgp.net --recv-keys $1
gpg --armor --export $1 | apt-key add -
------------------------------------------------------------------