Drawing in PDF

2009-06-29 Thread Jun
HEllo,

I've a pdf file, and i want to draw some additional stuff on it, by
example : some markup  notation. Anyone has idea how to do that ?
thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing in PDF

2009-06-29 Thread Jun
On Jun 30, 12:09 am, Emile van Sebille  wrote:
> On 6/29/2009 2:51 PM Jun said...
>
> > HEllo,
>
> > I've a pdf file, and i want to draw some additional stuff on it, by
> > example : some markup  notation. Anyone has idea how to do that ?
> > thank you in advance.
>
> ISTM that reportlab's commercial offering does that.
>
> http://www.reportlab.com/sectors/developers/
>
> Emile

Thanks a lot, is there open source solution ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing in PDF

2009-06-29 Thread Jun
On Jun 30, 12:22 am, Emile van Sebille  wrote:
> On 6/29/2009 3:14 PM Jun said...
>
> > On Jun 30, 12:09 am, Emile van Sebille  wrote:
> >> On 6/29/2009 2:51 PM Jun said...
>
> >>> HEllo,
> >>> I've a pdf file, and i want to draw some additional stuff on it, by
> >>> example : some markup  notation. Anyone has idea how to do that ?
> >>> thank you in advance.
> >> ISTM that reportlab's commercial offering does that.
>
> >>http://www.reportlab.com/sectors/developers/
>
> >> Emile
>
> > Thanks a lot, is there open source solution ?
>
> Not that I'm aware of.  If you have the appropriate source data you
> could create the complete document using the open source ReportLab.
> There are also tools available for combining PDFs.  But if you want to
> insert into the middle of an existing PDF let us know if you find an
> open source answer.
>
> Emile

I checked out whyteboard project (http://code.google.com/p/
whyteboard/)
which intends to use cairo (Drawing) and Python Poppler (load PDF).

-- 
http://mail.python.org/mailman/listinfo/python-list


Copy/paste through LAN

2009-07-22 Thread Jun
Hello,

I've a client/server application which uses Pyro to communicate each
other.
Now i try to implement copy/paste through LAN between server
controlled
filesystem to my local windows machine (I could list files in client's
window).
How can i pass the url information through Pyro ?

Thank you in advance.

Jun
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 110, Issue 106

2012-11-14 Thread Jun Tanaka
Hi,

I have a question about Django. I easy_installed Django1.4 and psycopg2,
and python manage.py syncdb. And gave me a error; No module named
psycopg2.extensions. posgre9.1 is installed.
It works fine on my MAC but not my Windows. Does anyone know about
this issue

Hope to resolve this issue soon.
Jun
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get the IP address of the wifi interface?

2011-05-13 Thread Jun Hu
Hi python experts:
There are two network interfaces on my laptop, one is 100M Ethernet, the
other is wifi, both are connected and have IP addresses.
The question is: how to get the ip address of WIFI interface without parsing
the output of a shell command like "ipconfig" or "ifconfig"?

OS: Windows or Linux

H.J
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get IP address of WIFI interface

2011-05-14 Thread Jun Hu
Thanks, is there any other way without using external command?

On Fri, May 13, 2011 at 10:41 PM, Ishwor Gurung wrote:

> Hi.
>
> On 14 May 2011 14:46, Far.Runner  wrote:
> > Hi Python Experts:
> > There are two network interfaces on my laptop, one is
> > 100M Ethernet interface, the other is wifi interface, both are connected
> and
> > has an IP address. then the question is: how to get the ip address of the
> > wifi interface in a python script?
> > OS: Windows or Linux
>
> Detect the OS with os.name and branch out to specific use case.
>
> The specific functionality can be implemented 2 ways:
> 1/ Regular expression pattern match
> 2/ Substring match and splits
>
> The subprocess module will then let you run those commands.
> 1/ posix - (Linux in your case) will use ifconfig
> 2/ nt - (windows in your ase) will use ipconfig.
>
> HTH.
>
>
>
> --
>
> Regards
> Ishwor Gurung
> Key id:0xa98db35e
> Key fingerprint:FBEF 0D69 6DE1 C72B A5A8  35FE 5A9B F3BB 4E5E 17B5
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get the IP address of WIFI interface

2011-05-15 Thread Jun Hu
Thanks for the tip, it is really helpful!
however the class of Win32_NetworkAdapterConfiguration doesn't include the
interface type (you can NOT tell if it is a wifi interface), so I change the
code a bit like following:

import wmi

wlan_int_id=None
for nic in wmi.WMI().Win32_NetworkAdapter():
if nic.NetConnectionID == "Wireless Network Connection":
wlan_int_id=nic.Index
break

if wlan_int_id<>None:
for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1):
if nic.Index==wlan_int_id:
print nic.IPAddress[0]
else:
print "WLAN interface NOT Found"



On Sun, May 15, 2011 at 4:12 AM, Tim Golden  wrote:

> On 15/05/2011 12:04 PM, Neal Becker wrote:
>
>> Far.Runner wrote:
>>
>>  Hi python experts:
>>> There are two network interfaces on my laptop: one is 100M Ethernet
>>> interface, the other is wifi interface, both are connected and has an ip
>>> address.
>>> The question is: How to get the ip address of the wifi interface in a
>>> python
>>> script without parsing the output of a shell command like "ipconfig" or
>>> "ifconfig"?
>>>
>>> OS: Windows or Linux
>>>
>>> F.R
>>>
>>
>> Here's some useful snippits for linux:
>>
>
> ... and for Windows:
>
> 
> import wmi
>
> for nic in wmi.WMI ().Win32_NetworkAdapterConfiguration (IPEnabled=1):
>  print nic.Caption, nic.IPAddress
>
> 
>
> TJG
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get the IP address of WIFI interface

2011-05-15 Thread Jun Hu
On Sun, May 15, 2011 at 2:14 PM, Andrew Berg wrote:

>
> One thing I found out about Win32_NetworkAdapterConfiguration is that it
> only contains /current/ information and not the stored info that it uses
> when making an initial connection (you can see and edit this info in the
> Network and Sharing Center applet). The difference is that if you're
> offline, that WMI object will have no useful info at all. You can find
> the info in the registry if you know what the UUID (or whatever it is)
> of (or assigned to) the interface (it's in
>
> HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces).
> The OP said the card would be connected, so it might not be an issue,
> but I think it's important to know that. Wouldn't want you to suddenly
> get blank strings or exceptions and not know why. ;-)
>
> Thanks for the reminder, however, it seems the IPAddress
of Win32_NetworkAdapterConfiguration will be 0.0.0.0 if the interface is NOT
connected (at least that is the result on my winxp), so I think we are safe
here.   ^_^
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Get the IP address of WIFI interface

2011-05-16 Thread Jun Hu
Thanks, this code works perfectly in ubuntu 10.04.
one question though, is dbus usually implemented in other distribution of
linux?

On Mon, May 16, 2011 at 12:57 PM, Anssi Saari  wrote:

> Neal Becker  writes:
>
> One possible solution in Linux is asking NetworkManager, if it's in
> use. It knows which interfaces are active and what kind they are (LAN,
> WLAN, WWAN etc.) NetworkManager communicates via dbus and even
> includes python example scripts. So here's my scriptlet based on
> NetworkManager example nm-state.py. This one prints out all active
> devices and their type and IP address. Easily modified to print only
> WLAN types.
>
> import dbus, socket, struct
>
> bus = dbus.SystemBus()
>
> proxy = bus.get_object("org.freedesktop.NetworkManager",
> "/org/freedesktop/NetworkManager")
> manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager")
>
> # Get device-specific state
> devices = manager.GetDevices()
> for d in devices:
>dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d)
>prop_iface = dbus.Interface(dev_proxy,
> "org.freedesktop.DBus.Properties")
>
># Get the device's current state and interface name
>state = prop_iface.Get("org.freedesktop.NetworkManager.Device", "State")
>name = prop_iface.Get("org.freedesktop.NetworkManager.Device",
> "Interface")
>ifa = "org.freedesktop.NetworkManager.Device"
>type = prop_iface.Get(ifa, "DeviceType")
>addr = prop_iface.Get(ifa, "Ip4Address")
>
># and print them out
>if state == 8:   # activated
>addr_dotted = socket.inet_ntoa(struct.pack('
>s = "Device %s is activated and has type %s and address %s"
>print s % (name, type, addr_dotted)
>else:
>print "Device %s is not activated" % name
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


process.popen with Japanese args => UTF8 JAVA

2014-03-08 Thread Jun Tanaka
Hello,

I have tried to process.popen to run java program with Japanese language.
test.java is compiled with utf8
'日本語' below means Japanese in Japanese.
but it does not work. Anyone who knows this matter well. Please help.

Jun

>>>>>>>>python code>>>>>>>>>>>>>
sentence = '日本語'
filename = 'japanese'
java_file = 'test'
cmd = "java {0} {1} {2}".format(java_file, sentence, filename)
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
>>>>>>>>python code end>>>>>>>>>>>>>>>>>>>>>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threaded Design Question

2007-08-09 Thread Jun-geun Park
[EMAIL PROTECTED] wrote:
> Hi all!  I'm implementing one of my first multithreaded apps, and have
> gotten to a point where I think I'm going off track from a standard
> idiom.  Wondering if anyone can point me in the right direction.
> 
> The script will run as a daemon and watch a given directory for new
> files.  Once it determines that a file has finished moving into the
> watch folder, it will kick off a process on one of the files.  Several
> of these could be running at any given time up to a max number of
> threads.
> 
> Here's how I have it designed so far.  The main thread starts a
> Watch(threading.Thread) class that loops and searches a directory for
> files.  It has been passed a Queue.Queue() object (watch_queue), and
> as it finds new files in the watch folder, it adds the file name to
> the queue.
> 
> The main thread then grabs an item off the watch_queue, and kicks off
> processing on that file using another class Worker(threading.thread).
> 
> My problem is with communicating between the threads as to which files
> are currently processing, or are already present in the watch_queue so
> that the Watch thread does not continuously add unneeded files to the
> watch_queue to be processed.  For example...Watch() finds a file to be
> processed and adds it to the queue.  The main thread sees the file on
> the queue and pops it off and begins processing.  Now the file has
> been removed from the watch_queue, and Watch() thread has no way of
> knowing that the other Worker() thread is processing it, and shouldn't
> pick it up again.  So it will see the file as new and add it to the
> queue again.  PS.. The file is deleted from the watch folder after it
> has finished processing, so that's how i'll know which files to
> process in the long term.
> 
> I made definite progress by creating two queues...watch_queue and
> processing_queue, and then used lists within the classes to store the
> state of which files are processing/watched.
> 
> I think I could pull it off, but it has got very confusing quickly,
> trying to keep each thread's list and the queue always in sync with
> one another.  The easiset solution I can see is if my threads could
> read an item from the queue without removing it from the queue and
> only remove it when I tell it to.  Then the Watch() thread could then
> just follow what items are on the watch_queue to know what files to
> add, and then the Worker() thread could intentionally remove the item
> from the watch_queue once it has finished processing it.
> 
> Now that I'm writing this out, I see a solution by over-riding or
> wrapping Queue.Queue().get() to give me the behavior I mention above.
> 
> I've noticed .join() and .task_done(), but I'm not sure of how to use
> them properly.  Any suggestions would be greatly appreciated.
> 
> ~Sean
> 

1) Use a (global) hash table and a mutex on it. Before a worker thread
starts processing a file, have the worker acquire the mutex, add the
filename into a global dictionary as a key, and release the mutex.  Then,
when the watcher thread attempts to read a file, it only has to check
whether the filename is on the table.

If different files may have a same name, you can also use size or some
other signatures. Also, I think basic operations on primitive types on
Python are atomic so you don't actually need mutex, but in threaded
programs, it's always a good habit to use mutexes explicitly.

2) If the watcher thread doesn't spend much time in "recognizing" files 
to process,
simply make the watcher thread reads many(or all) files in the directory,
put them all in the queue, and wait until all items in the queue are 
processed
using .join(). Workers can indicate that the processing of the last 
dequeued item
is done by calling .task_done() (As soon as all items are flaged 
"task_done()", join() will
unblock.) After processing of files on the queue are all done,
watcher can move or remove processed files and read the directory again. 
Of course,
you need to keep track of "recognized" files of that turn.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Biased random?

2007-08-27 Thread Jun-geun Park
Ivan Voras wrote:
> Hi,
> 
> I have a list of items, and need to choose several elements from it,
> "almost random". The catch is that the elements from the beginning
> should have more chance of being selected than those at the end (how
> much more? I don't care how the "envelope" of probability looks like at
> this point - can be linear). I see that there are several functions in
> Python standard libraries for various distribution, but is there an easy
> pythonic way to make them do what I need?
> 
> 

That's weird. random.randint(a,b) will be enough for most cases. Test
your system to see the distribution is uniform with something like:


import random

dist = {}
for z in xrange(10):
 u = random.randint(1,10)
 try:
 dist[u] = dist[u] + 1
 except KeyError:
 dist[u] = 1

print dist

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Biased random?

2007-08-27 Thread Jun-geun Park
Jun-geun Park wrote:
> Ivan Voras wrote:
>> Hi,
>>
>> I have a list of items, and need to choose several elements from it,
>> "almost random". The catch is that the elements from the beginning
>> should have more chance of being selected than those at the end (how
>> much more? I don't care how the "envelope" of probability looks like at
>> this point - can be linear). I see that there are several functions in
>> Python standard libraries for various distribution, but is there an easy
>> pythonic way to make them do what I need?
>>
>>
> 
> That's weird. random.randint(a,b) will be enough for most cases. Test
> your system to see the distribution is uniform with something like:
> 
> 
> import random
> 
> dist = {}
> for z in xrange(10):
> u = random.randint(1,10)
> try:
> dist[u] = dist[u] + 1
> except KeyError:
> dist[u] = 1
> 
> print dist
> 

I understood the question wrong.(Thanks, Grant and Robert.) To get the 
linear
distribution, you can start from the following:

 a = (random.random() + random.random())/2.0 # Triangle distribution 
in [0,1)
 b = random.random()# 
Uniform in [0,1)
 c = b + (1-b)*a 
 # Convolution
 u = int(100*(1-c)+1) 
# ceil(100*(1-c))

, then, because convolution of a rectangle function and a triangle 
function is a
linear function under the valid domain, u is a random integer in [1,100]
that follows (decreasing) linear distribution.

Alternatively if I were in your case, I would go with an exponential 
random with
a suitable lambda(by cutting its tail.)
-- 
http://mail.python.org/mailman/listinfo/python-list