adam goucher | 1 Jul 04:16
Picon

Re: FW: Jython2.2b2 determining OS/platform and executing external programs


If you wrapped the creation of the browser variable in some platform decision stuff I don't see why it wouldn't.
 
-adam


> Date: Sun, 1 Jul 2007 06:35:34 +0800
> From: astigmatik <at> gmail.com
> To: jython-users <at> lists.sourceforge.net
> Subject: Re: [Jython-users] FW: Jython2.2b2 determining OS/platform and executing external programs
>
> I ended up with a Javanese solution:
>
> browser = r'c:\program files\mozilla firefox\firefox.exe'
> from java.lang import Runtime
> Runtime.getRuntime().exec((browser, url))
>
> Question is, would this work on non-Windows platforms?
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users


Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it!
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Frank Wierzbicki | 1 Jul 04:25
Picon
Gravatar

Re: FW: Jython2.2b2 determining OS/platform and executing external programs

On 6/30/07, astigmatik <at> gmail.com <astigmatik <at> gmail.com> wrote:
> I ended up with a Javanese solution:
>
> browser = r'c:\program files\mozilla firefox\firefox.exe'
> from java.lang import Runtime
> Runtime.getRuntime().exec((browser, url))
>
> Question is, would this work on non-Windows platforms?
It would work in principle, but you would need to use a platform
specific path and executable name (for example, on linux it would look
something like:

browser = r'/usr/lib/firefox'
from java.lang import Runtime
Runtime.getRuntime().exec((browser, url))

and on OS X you could probably achieve a similar effect like so:

browser = r'/usr/bin/open'
from java.lang import Runtime
Runtime.getRuntime().exec((browser, url))

although in the OS X case this would open whatever OS X would think of
as the appropriate app for the particular resource pointed to with
url.

-Frank

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
astigmatik | 1 Jul 04:36
Picon

Re: FW: Jython2.2b2 determining OS/platform and executing external programs

It was just an example. I'll get the value of 'browser' from users' preference.

On 7/1/07, Frank Wierzbicki <fwierzbicki <at> gmail.com> wrote:
> On 6/30/07, astigmatik <at> gmail.com <astigmatik <at> gmail.com> wrote:
> > I ended up with a Javanese solution:
> >
> > browser = r'c:\program files\mozilla firefox\firefox.exe'
> > from java.lang import Runtime
> > Runtime.getRuntime().exec((browser, url))
> >
> > Question is, would this work on non-Windows platforms?
> It would work in principle, but you would need to use a platform
> specific path and executable name (for example, on linux it would look
> something like:
>
> browser = r'/usr/lib/firefox'
> from java.lang import Runtime
> Runtime.getRuntime().exec((browser, url))
>
> and on OS X you could probably achieve a similar effect like so:
>
> browser = r'/usr/bin/open'
> from java.lang import Runtime
> Runtime.getRuntime().exec((browser, url))
>
> although in the OS X case this would open whatever OS X would think of
> as the appropriate app for the particular resource pointed to with
> url.
>
> -Frank
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
astigmatik | 1 Jul 04:48
Picon

Jython2.2b2 - expected 2 args; got 1

Another question. I have something like this:

class MyApp(swing.JFrame):
    def __init__(self):
        # more lines here..
        self.createMenus()
        # more lines here...
    def createMenus(self):
        menuBar = swing.JMenuBar()
        self.setJMenuBar(menuBar)
        # more lines here...
        def changeStyleSheet(event=None):
            cssfile = awt.FileDialog(self, "Select new style sheet")
            cssfile.show()
            if cssfile.getFile() is not None:
                cssfile = cssfile.getDirectory() + cssfile.getFile()
                from java.net import URL
                from javax.swing.text.html import StyleSheet
                ss = StyleSheet
                u = "file://" + cssfile
                ss.importStyleSheet(u)
                # more lines here...
        css = swing.JMenu('StyleSheet')
        css.setMnemonic('s')
        menuBar.add(css)
        css.add(JMenuItem('Change CSS file...',
actionPerformed=changeStyleSheet))
        # more lines here...

However, I get this error:
TypeError: importStyleSheet(): expected 2 args; got 1

According to the APIs
(http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/html/StyleSheet.html)
however, the importStyleSheet method only requires one arg, i.e.

public void importStyleSheet(URL url)

Why am I getting the TypeError? Am I doing something wrong?

Regards,
astigmatik

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Jeff Emanuel | 1 Jul 06:29
Favicon

Re: Jython2.2b2 - expected 2 args; got 1

I think you meant

   ss = StyleSheet()

to create an instance, instead of

   ss = StyleSheet

which assigns the class to a new variable.
In your posted code,  ss.importStyleSheet(u) is
equivalent to StyleSheet.importStyleSheet(u),
where u is expected to be an instance of
StyleSheet, hence another argument is required.
With ss assigned to a StyleSheet instance, u is
treated as an argument to the method.

astigmatik <at> gmail.com wrote:
> Another question. I have something like this:
> 
> class MyApp(swing.JFrame):
>     def __init__(self):
>         # more lines here..
>         self.createMenus()
>         # more lines here...
>     def createMenus(self):
>         menuBar = swing.JMenuBar()
>         self.setJMenuBar(menuBar)
>         # more lines here...
>         def changeStyleSheet(event=None):
>             cssfile = awt.FileDialog(self, "Select new style sheet")
>             cssfile.show()
>             if cssfile.getFile() is not None:
>                 cssfile = cssfile.getDirectory() + cssfile.getFile()
>                 from java.net import URL
>                 from javax.swing.text.html import StyleSheet
>                 ss = StyleSheet
>                 u = "file://" + cssfile
>                 ss.importStyleSheet(u)
>                 # more lines here...
>         css = swing.JMenu('StyleSheet')
>         css.setMnemonic('s')
>         menuBar.add(css)
>         css.add(JMenuItem('Change CSS file...',
> actionPerformed=changeStyleSheet))
>         # more lines here...
> 
> However, I get this error:
> TypeError: importStyleSheet(): expected 2 args; got 1
> 
> According to the APIs
> (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/html/StyleSheet.html)
> however, the importStyleSheet method only requires one arg, i.e.
> 
> public void importStyleSheet(URL url)
> 
> Why am I getting the TypeError? Am I doing something wrong?
> 
> Regards,
> astigmatik
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
astigmatik | 1 Jul 15:20
Picon

Re: Jython2.2b2 - expected 2 args; got 1

Thanks.. that was another one of my d'oh moments :-/

On 7/1/07, Jeff Emanuel wrote:
> I think you meant
>
>    ss = StyleSheet()
>
> to create an instance, instead of
>
>    ss = StyleSheet
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Oti | 1 Jul 23:02
Picon
Gravatar

Re: FW: Jython2.2b2 determining OS/platform and executing external programs

Hi,

the caller of Runtime.exec() needs to consume the output of the started process.
So in general I'd recommend to use os.system(), which IMHO handles this for you.
Of course you still have to deal with the syntax details of the platforms.

Best wishes,
Oti.

On 7/1/07, astigmatik <at> gmail.com <astigmatik <at> gmail.com > wrote:
It was just an example. I'll get the value of 'browser' from users' preference.

On 7/1/07, Frank Wierzbicki <fwierzbicki <at> gmail.com> wrote:
> On 6/30/07, astigmatik <at> gmail.com < astigmatik <at> gmail.com> wrote:
> > I ended up with a Javanese solution:
> >
> > browser = r'c:\program files\mozilla firefox\firefox.exe'
> > from java.lang import Runtime
> > Runtime.getRuntime().exec((browser, url))
> >
> > Question is, would this work on non-Windows platforms?
> It would work in principle, but you would need to use a platform
> specific path and executable name (for example, on linux it would look
> something like:
>
> browser = r'/usr/lib/firefox'
> from java.lang import Runtime
> Runtime.getRuntime().exec((browser, url))
>
> and on OS X you could probably achieve a similar effect like so:
>
> browser = r'/usr/bin/open'
> from java.lang import Runtime
> Runtime.getRuntime().exec((browser, url))
>
> although in the OS X case this would open whatever OS X would think of
> as the appropriate app for the particular resource pointed to with
> url.
>
> -Frank
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
astigmatik | 2 Jul 04:24
Picon

Re: FW: Jython2.2b2 determining OS/platform and executing external programs

If I use os.system(), it 'blocks' my app until I close that external
app. Also, I don't know how to pass a parameter with os.system().

I just want to be able to double-click a URL in a JEditorPane and make
it open an external browser which is the preference of the user, and
that browser opens the clicked URL (not necessarily the browser that
is associated with opening URLs). The output of that is not important.
I also don't want to read/write from that process. I just want it to
open and leave it at that. And I was hoping to find a solution that'll
work for all OSes.

If Runtime.getRuntime().exe() is not the answer, then how do I do
this? I've looked at popen, and I think it's too complicated for
something so simple.

On 7/2/07, Oti <ohumbel <at> gmail.com> wrote:
> Hi,
>
> the caller of Runtime.exec() needs to consume the output of the started
> process.
> So in general I'd recommend to use os.system(), which IMHO handles this for
> you.
> Of course you still have to deal with the syntax details of the platforms.
>
> Best wishes,
> Oti.
>
>
> On 7/1/07, astigmatik <at> gmail.com <astigmatik <at> gmail.com > wrote:
> >
> > It was just an example. I'll get the value of 'browser' from users'
> preference.
> >
> > On 7/1/07, Frank Wierzbicki <fwierzbicki <at> gmail.com> wrote:
> > > On 6/30/07, astigmatik <at> gmail.com < astigmatik <at> gmail.com> wrote:
> > > > I ended up with a Javanese solution:
> > > >
> > > > browser = r'c:\program files\mozilla firefox\firefox.exe'
> > > > from java.lang import Runtime
> > > > Runtime.getRuntime().exec((browser, url))
> > > >
> > > > Question is, would this work on non-Windows platforms?
> > > It would work in principle, but you would need to use a platform
> > > specific path and executable name (for example, on linux it would look
> > > something like:
> > >
> > > browser = r'/usr/lib/firefox'
> > > from java.lang import Runtime
> > > Runtime.getRuntime().exec((browser, url))
> > >
> > > and on OS X you could probably achieve a similar effect like so:
> > >
> > > browser = r'/usr/bin/open'
> > > from java.lang import Runtime
> > > Runtime.getRuntime().exec((browser, url))
> > >
> > > although in the OS X case this would open whatever OS X would think of
> > > as the appropriate app for the particular resource pointed to with
> > > url.
> > >
> > > -Frank
> > >
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Jython-users mailing list
> > Jython-users <at> lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/jython-users
> >
>
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
Oti | 2 Jul 06:45
Picon
Gravatar

Re: FW: Jython2.2b2 determining OS/platform and executing external programs

Sorry I was not aware you don't want to block.

Reading the javadoc of Process
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html
makes me believe it is not defined.

best wishes,
Oti.

In any case,

On 7/2/07, astigmatik <at> gmail.com <astigmatik <at> gmail.com> wrote:
If I use os.system(), it 'blocks' my app until I close that external
app. Also, I don't know how to pass a parameter with os.system().

I just want to be able to double-click a URL in a JEditorPane and make
it open an external browser which is the preference of the user, and
that browser opens the clicked URL (not necessarily the browser that
is associated with opening URLs). The output of that is not important.
I also don't want to read/write from that process. I just want it to
open and leave it at that. And I was hoping to find a solution that'll
work for all OSes.

If Runtime.getRuntime().exe() is not the answer, then how do I do
this? I've looked at popen, and I think it's too complicated for
something so simple.


On 7/2/07, Oti <ohumbel <at> gmail.com> wrote:
> Hi,
>
> the caller of Runtime.exec() needs to consume the output of the started
> process.
> So in general I'd recommend to use os.system(), which IMHO handles this for
> you.
> Of course you still have to deal with the syntax details of the platforms.
>
> Best wishes,
> Oti.
>
>
> On 7/1/07, astigmatik <at> gmail.com <astigmatik <at> gmail.com > wrote:
> >
> > It was just an example. I'll get the value of 'browser' from users'
> preference.
> >
> > On 7/1/07, Frank Wierzbicki < fwierzbicki <at> gmail.com> wrote:
> > > On 6/30/07, astigmatik <at> gmail.com < astigmatik <at> gmail.com> wrote:
> > > > I ended up with a Javanese solution:
> > > >
> > > > browser = r'c:\program files\mozilla firefox\firefox.exe'
> > > > from java.lang import Runtime
> > > > Runtime.getRuntime().exec((browser, url))
> > > >
> > > > Question is, would this work on non-Windows platforms?
> > > It would work in principle, but you would need to use a platform
> > > specific path and executable name (for example, on linux it would look
> > > something like:
> > >
> > > browser = r'/usr/lib/firefox'
> > > from java.lang import Runtime
> > > Runtime.getRuntime().exec((browser, url))
> > >
> > > and on OS X you could probably achieve a similar effect like so:
> > >
> > > browser = r'/usr/bin/open'
> > > from java.lang import Runtime
> > > Runtime.getRuntime().exec((browser, url))
> > >
> > > although in the OS X case this would open whatever OS X would think of
> > > as the appropriate app for the particular resource pointed to with
> > > url.
> > >
> > > -Frank
> > >
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Jython-users mailing list
> > Jython-users <at> lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/jython-users
> >
>
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users
Arye | 2 Jul 12:08
Picon

Re: character encoding issues

Dear Alan Kennedy,

Thanks for your help. Indeed, reading a file with codecs.open in jython
works fine.

However I am still wondering why codecs.open works and
the regular file open does not as demonstrated in the little
program below:

I saved this string "®™°" (Three characters : (R), TM and degrees")
in file "myfunnychars.txt" using the utf-8 encoding by using CPython
#!/usr/bin/env python
# -*- mode: pymode; coding: latin1; -*-

myfunnychars = u"®™°"
my_utf8 = myfunnychars.encode("utf-8")
output_utf8 = open("myfunnycharst.txt", "wb")
output_utf8.write(my_utf8)
output_utf8.close()


***************************************
import codecs

input1 = open("myfunnychars.txt", "r")
str1 = input1.read()
print "type(str1)=",type(str1)

input1.close()
for c in str1:
    print ord(c),



input2 = codecs.open("myfunnychars.txt", "r", 'utf-8')
str2 = input2.read()
print "\ntype(str2)=",type(str2)
input2.close()

for c in str2:
    print ord(c),
***************************************

output:
C:\AH\WORK\UTIL>python compare_read_codecs.py
type(str1)= <type 'str'>
194 174 194 153 194 176
type(str2)= <type 'unicode'>
174 153 176

C:\AH\WORK\UTIL>jython compare_read_codecs.py
type(str1)= <type 'str'>
194 174 194 8482 194 176
type(str2)= <type 'unicode'>
174 153 176

this "8482" seems mysterious to me.

All the best,
Arye.



[Arye]
> The little program below behaves differently when run by jython and Python:
> I am trying to encode in utf-8 a unicode string with 3 characters in it:
> u"(r)™°" The "Registered", "Trade Mark", and "Degrees" characters.

The fundamental problem here is that jython does not support PEP 263,
which permits you to declare the encoding of your source module.

Because you have embedded your funny characters directly in your source,
jython does not interpret them correctly.

Cpython will only interpret them correctly if you have an encoding
declaration at the top of your source file, like so

# -*- coding: utf-8 -*-

(Change the encoding to whatever your text editor produces)

Defining Python Source Code Encodings
http://www.python.org/dev/peps/pep-0263/

There are two solutions to your problem

1. Do not embed the raw characters directly in your source file.
Instead, declare them with unicode escapes, like so

myfunnychars = u"\u00b0\u00ae\u2122"

2. Keep all unicode strings in separate files to your source, and read
them with codecs.open.

Try running this code in both cpython and jython; you should get
identical results from both

# -=-=-=-=-=-=-=-=-=
import sys
print "sys.getdefaultencoding()=", sys.getdefaultencoding()

myfunnychars = u"\u00b0\u00ae\u2122"

my_utf8 = myfunnychars.encode ("utf-8")
print "len(my_utf8)=",len(my_utf8)
print "my_utf8=",my_utf8

for c in my_utf8:
print ord(c)
# -=-=-=-=-=-=-=-=-=

Regards,

Alan.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jython-users mailing list
Jython-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

Gmane