<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jayway Team Blog &#187; python</title>
	<atom:link href="http://blog.jayway.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 11 Feb 2012 10:33:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PySide and QML</title>
		<link>http://blog.jayway.com/2011/04/04/pyside-and-qml/</link>
		<comments>http://blog.jayway.com/2011/04/04/pyside-and-qml/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 09:15:21 +0000</pubDate>
		<dc:creator>Mario Boikov</dc:creator>
				<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[QML]]></category>
		<category><![CDATA[Qt]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=7879</guid>
		<description><![CDATA[It has been out there for a while but I haven't had time to try it out, PySide 1.0 with QML support! This really gives you a über rapid app development environment. The power of Python combined with the awesomeness of the declarative language QML (QtQuick) from the Qt framework. Take a look and feel [...]]]></description>
			<content:encoded><![CDATA[<p>It has been out there for a while but I haven't had time to try it out, <a href="http://www.pyside.org">PySide</a> 1.0 with <a href="http://doc.qt.nokia.com/4.7/qtquick.html">QML</a> support!</p>
<p>This really gives you a über rapid app development environment. The  power of Python combined with the awesomeness of the declarative  language QML (<a href="http://qt.nokia.com/qtquick/">QtQuick</a>) from the <a href="http://qt.nokia.com">Qt framework.</a></p>
<p>Take a look and feel free to play with the example below:</p>
<p>The Python file<br />
<!-- Generator: GNU source-highlight 3.1.3 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --></p>
<pre><tt><strong><span style="color: #000080;">from</span></strong> PySide <strong><span style="color: #000080;">import</span></strong> QtCore
<strong><span style="color: #000080;">from</span></strong> PySide <strong><span style="color: #000080;">import</span></strong> QtGui
<strong><span style="color: #000080;">from</span></strong> PySide <strong><span style="color: #000080;">import</span></strong> QtDeclarative

<strong><span style="color: #0000ff;">class</span></strong> <strong><span style="color: #000000;">Message</span></strong><span style="color: #990000;">(</span>QtDeclarative<span style="color: #990000;">.</span>QDeclarativeItem<span style="color: #990000;">):</span>

    messageChanged <span style="color: #990000;">=</span> QtCore<span style="color: #990000;">.</span><strong><span style="color: #000000;">Signal</span></strong><span style="color: #990000;">()</span>

    <strong><span style="color: #0000ff;">def</span></strong> <strong><span style="color: #000000;">__init__</span></strong><span style="color: #990000;">(</span>self<span style="color: #990000;">,</span> parent <span style="color: #990000;">=</span> None<span style="color: #990000;">):</span>
        QtDeclarative<span style="color: #990000;">.</span>QDeclarativeItem<span style="color: #990000;">.</span><strong><span style="color: #000000;">__init__</span></strong><span style="color: #990000;">(</span>self<span style="color: #990000;">,</span> parent<span style="color: #990000;">)</span>
        self<span style="color: #990000;">.</span>_msg <span style="color: #990000;">=</span> u<span style="color: #ff0000;">''</span>

    <strong><span style="color: #0000ff;">def</span></strong> <strong><span style="color: #000000;">getMessage</span></strong><span style="color: #990000;">(</span>self<span style="color: #990000;">):</span>
        <strong><span style="color: #0000ff;">return</span></strong> self<span style="color: #990000;">.</span>_msg

    <strong><span style="color: #0000ff;">def</span></strong> <strong><span style="color: #000000;">setMessage</span></strong><span style="color: #990000;">(</span>self<span style="color: #990000;">,</span> value<span style="color: #990000;">):</span>
        <strong><span style="color: #0000ff;">if</span></strong> self<span style="color: #990000;">.</span>_msg <span style="color: #990000;">!=</span> value<span style="color: #990000;">:</span>
            <strong><span style="color: #0000ff;">print</span></strong> <span style="color: #ff0000;">"Setting message property to"</span><span style="color: #990000;">,</span> value
            self<span style="color: #990000;">.</span>_msg <span style="color: #990000;">=</span> value
            self<span style="color: #990000;">.</span>messageChanged<span style="color: #990000;">.</span><strong><span style="color: #000000;">emit</span></strong><span style="color: #990000;">()</span>
        <strong><span style="color: #0000ff;">else</span></strong><span style="color: #990000;">:</span>
            <strong><span style="color: #0000ff;">print</span></strong> <span style="color: #ff0000;">"Message property already set to"</span><span style="color: #990000;">,</span> value

    message <span style="color: #990000;">=</span> QtCore<span style="color: #990000;">.</span><strong><span style="color: #000000;">Property</span></strong><span style="color: #990000;">(</span>unicode<span style="color: #990000;">,</span> getMessage<span style="color: #990000;">,</span> setMessage<span style="color: #990000;">,</span> notify<span style="color: #990000;">=</span>messageChanged<span style="color: #990000;">)</span>

<strong><span style="color: #0000ff;">def</span></strong> <strong><span style="color: #000000;">main</span></strong><span style="color: #990000;">():</span>
    app <span style="color: #990000;">=</span> QtGui<span style="color: #990000;">.</span><strong><span style="color: #000000;">QApplication</span></strong><span style="color: #990000;">([])</span>

    QtDeclarative<span style="color: #990000;">.</span><strong><span style="color: #000000;">qmlRegisterType</span></strong><span style="color: #990000;">(</span>Message<span style="color: #990000;">,</span> <span style="color: #ff0000;">"utils"</span><span style="color: #990000;">,</span> <span style="color: #993399;">1</span><span style="color: #990000;">,</span> <span style="color: #993399;">0</span><span style="color: #990000;">,</span> <span style="color: #ff0000;">"Message"</span><span style="color: #990000;">)</span>

    win <span style="color: #990000;">=</span> QtDeclarative<span style="color: #990000;">.</span><strong><span style="color: #000000;">QDeclarativeView</span></strong><span style="color: #990000;">()</span>
    win<span style="color: #990000;">.</span><strong><span style="color: #000000;">setSource</span></strong><span style="color: #990000;">(</span><span style="color: #ff0000;">"main.qml"</span><span style="color: #990000;">)</span>
    win<span style="color: #990000;">.</span><strong><span style="color: #000000;">setWindowTitle</span></strong><span style="color: #990000;">(</span><span style="color: #ff0000;">"Hello World"</span><span style="color: #990000;">)</span>
    win<span style="color: #990000;">.</span><strong><span style="color: #000000;">setResizeMode</span></strong><span style="color: #990000;">(</span>QtDeclarative<span style="color: #990000;">.</span>QDeclarativeView<span style="color: #990000;">.</span>SizeRootObjectToView<span style="color: #990000;">)</span>

    win<span style="color: #990000;">.</span><strong><span style="color: #000000;">show</span></strong><span style="color: #990000;">()</span>
    app<span style="color: #990000;">.</span><strong><span style="color: #000000;">exec_</span></strong><span style="color: #990000;">()</span>

<strong><span style="color: #0000ff;">if</span></strong> __name__ <span style="color: #990000;">==</span> <span style="color: #ff0000;">"__main__"</span><span style="color: #990000;">:</span>
    <strong><span style="color: #000000;">main</span></strong><span style="color: #990000;">()</span>
</tt></pre>
<p>and main.qml<br />
<!-- Generator: GNU source-highlight 3.1.3 by Lorenzo Bettini http://www.lorenzobettini.it http://www.gnu.org/software/src-highlite --></p>
<pre><tt>import Qt <span style="color: #993399;">4.7</span> <em><span style="color: #9a1900;">// or QtQuick 1.0 if applicable</span></em>

import utils <span style="color: #993399;">1.0</span>

Rectangle <span style="color: #ff0000;">{</span>
    id<span style="color: #990000;">:</span> main

    signal clicked

    color<span style="color: #990000;">:</span> <span style="color: #ff0000;">"black"</span>
    width<span style="color: #990000;">:</span> <span style="color: #993399;">360</span><span style="color: #990000;">;</span> height<span style="color: #990000;">:</span> <span style="color: #993399;">360</span>

    Message <span style="color: #ff0000;">{</span>
        id<span style="color: #990000;">:</span> msg

        message<span style="color: #990000;">:</span> <span style="color: #ff0000;">"Click Me!"</span>
        onMessageChanged<span style="color: #990000;">:</span> label<span style="color: #990000;">.</span>font<span style="color: #990000;">.</span>pixelSize <span style="color: #990000;">=</span> <span style="color: #993399;">40</span>
    <span style="color: #ff0000;">}</span>

    Text <span style="color: #ff0000;">{</span>
        id<span style="color: #990000;">:</span> label

        anchors<span style="color: #990000;">.</span>centerIn<span style="color: #990000;">:</span> parent

        text<span style="color: #990000;">:</span> msg<span style="color: #990000;">.</span>message
        color<span style="color: #990000;">:</span> <span style="color: #ff0000;">"white"</span>
        font<span style="color: #990000;">.</span>pixelSize<span style="color: #990000;">:</span> <span style="color: #993399;">25</span>

        Behavior on font<span style="color: #990000;">.</span>pixelSize <span style="color: #ff0000;">{</span>
            NumberAnimation <span style="color: #ff0000;">{</span> duration<span style="color: #990000;">:</span> <span style="color: #993399;">800</span><span style="color: #990000;">;</span> easing<span style="color: #990000;">.</span>type<span style="color: #990000;">:</span> Easing<span style="color: #990000;">.</span>OutBounce <span style="color: #ff0000;">}</span>
        <span style="color: #ff0000;">}</span>

        MouseArea <span style="color: #ff0000;">{</span>
            anchors<span style="color: #990000;">.</span>fill<span style="color: #990000;">:</span> parent
            onClicked<span style="color: #990000;">:</span> msg<span style="color: #990000;">.</span>message <span style="color: #990000;">=</span> <span style="color: #ff0000;">"Hello World"</span>
        <span style="color: #ff0000;">}</span>
    <span style="color: #ff0000;">}</span>

<span style="color: #ff0000;">}</span>
</tt></pre>
<p>For more information point your browser to <a href="http://www.pyside.org/">http://www.pyside.org</a> and download the package for your OS.</p>
<p>You'll also find useful information at <a href="http://developer.qt.nokia.com/wiki/Category:LanguageBindings::PySide">http://developer.qt.nokia.com/wiki/Category:LanguageBindings::PySide</a></p>
<p>Happy hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/04/04/pyside-and-qml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scripting in Ruby</title>
		<link>http://blog.jayway.com/2010/01/16/scripting-in-ruby/</link>
		<comments>http://blog.jayway.com/2010/01/16/scripting-in-ruby/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 12:54:25 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=4349</guid>
		<description><![CDATA[I just read, or rather skimmed, the book, called Everyday Scripting with Ruby and it is awful. I had high expectations. I was expecting something like Perl for System Administration, where you right away get into hard core Perl scripting. This book is nothing like that! It is a really basic introduction to Ruby, and [...]]]></description>
			<content:encoded><![CDATA[<p>I just read, or rather skimmed, the book, called <em>Everyday Scripting with Ruby</em> and it is awful. I had high expectations. I was expecting something like<br />
<a href="http://www.amazon.com/Perl-System-Administrators-David-Blank-Edelman/dp/1565926099?tag=thtasta-20">Perl for System Administration</a>, where you right away get into hard core Perl scripting. This book is nothing like that! It is a really basic introduction to Ruby, and if you have any experience programming at all, DON'T BUY THIS BOOK.</p>
<p>OK, enough complaining! I am going to do what this book does not do. I am going to show a good way to write scripts in Ruby. If you want to learn more about Ruby, buy<br />
<a href="http://www.amazon.com/Programming-Ruby-1-9-Pragmatic-Programmers/dp/1934356085?tag=thtasta-20">Programming Ruby</a>, <a href="http://www.amazon.com/Well-Grounded-Rubyist-David-Black/dp/1933988657?tag=thtasta-20">The Well-Grounded Rubyist</a> and <a href="http://www.amazon.com/Ruby-Way-Second-Techniques-Programming/dp/0672328844?tag=thtasta-20">The Ruby Way</a>.</p>
<p>Ruby is an excellent language. It is, in my opinion, the best scripting language and it beats both Perl and Python face down. If you are not scripting in Ruby, you are missing out.<br />
Ok, so here is the script.</p>
<h3>sendgmail</h3>
<p>The script is called <strong>sendgmail</strong> and it sends mail via gmail (surprise!).</p>
<p>This is how the command is used.</p>
<pre lang='bash'>
$ sendgmail --help
/usr/local/bin/sendgmail [options] attachments...
Options are ...
    -t, --to TO                      Send email to recipient
    -m, --message MESSAGE            Include the message.
    -s, --subject SUBJECT            Include the subject.
    -v, --verbose                    Log to standard output.
    -V, --version                    Display the program version.
    -h, -H, --help                   Display this help message.
</pre>
<p>And here is the code, liberally sprinkled with comments.</p>
<pre>
<I>#!/usr/bin/env ruby
</I><I># Use the currently configured ruby version
</I>
<I># optparse contains OptionParser, ostruct: OpenStruct and growl Growl
</I><B>require</B> <B>'optparse'</B>
<B>require</B> <B>'ostruct'</B>
<B>require</B> <B>'growl'</B>

<I># This is the name of the script that is called
</I><I># Whatever you name your script will be reflected here.
</I><I># This can be useful if you want to have the same script do many things
</I><I># Create differently named links to the script
</I><I># and use the program name to select behavior.
</I>PROGRAM_NAME = <B>$0</B>
PROGRAM_VERSION = 1.0

<I># Create an OpenStruct to save the options.
</I><I># OpenStruct allows you to use options.my_option instead of
</I><I># option['my_option'] with a normal hash
</I><I># http://ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html
</I><B>def</B> <B>options
</B>  <B>@options</B> ||= OpenStruct.new
<B>end</B>

<I># This is the options of the program, see OptionParser
</I><I># http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html
</I><B>def</B> <B>program_options
</B>  [
          <I># The values of the array are,
</I>          <I># [long_option, short_option and parameter, description, code to execute]
</I>          [<B>'--to'</B>, <B>'-t TO'</B>, <B>&quot;Send email to recipient&quot;</B>,
           lambda { |value| options.to = value }
          ],
          [<B>'--message'</B>, <B>'-m MESSAGE'</B>, <B>&quot;Include the message.&quot;</B>,
           lambda { |value| options.message = value }
          ],
          [<B>'--subject'</B>, <B>'-s SUBJECT'</B>, <B>&quot;Include the subject.&quot;</B>,
           lambda { |value| options.subject = value }
          ],
          [<B>'--verbose'</B>, <B>'-v'</B>, <B>&quot;Log to standard output.&quot;</B>,
           lambda { |value| options.verbose = <B>true</B> }
          ],
          [<B>'--version'</B>, <B>'-V'</B>, <B>&quot;Display the program version.&quot;</B>,
           lambda { |value|
             puts <B>&quot;#{program_name}, version #{PROGRAM_VERSION}&quot;</B>
             exit
           }
          ]
  ]
<B>end</B>

option_parser = OptionParser.new <B>do</B> |opts|
  opts.banner = <B>&quot;#{PROGRAM_NAME} [options] attachments...&quot;</B>
  opts.separator <B>&quot;&quot;</B>
  opts.separator <B>&quot;Options are ...&quot;</B>

  <I># Add the command on_tail, to make it appear as the last option in the list.
</I>  opts.on_tail(<B>&quot;-h&quot;</B>, <B>&quot;--help&quot;</B>, <B>&quot;-H&quot;</B>, <B>&quot;Display this help message.&quot;</B>) <B>do</B>
    puts opts
    exit
  <B>end</B>

  program_options.each { |args| opts.on(*args) }
<B>end</B>

<B>begin</B>
  <I># Parse the options and remove them from the ARGV array
</I>  option_parser.parse!
<B>rescue</B> OptionParser::ParseError =&gt; error
  puts error.message
  puts option_parser
  exit
<B>end</B>

<B>unless</B> options.to
  puts <B>'Missing required argument --to or -t'</B>
  puts option_parser
  exit
<B>end</B>

options.subject = <B>'No subject'</B> <B>unless</B> options.subject
options.message = <B>''</B> <B>unless</B> options.message

<I># Concatenate the options into a proper command
</I>command = <B>'sendemail -o tls=yes -s smtp.gmail.com -f from@gmail.com -xu from@gmail.com -xp secret'</B>
command += <B>&quot;-t '#{options.to}' -u '#{options.subject}' -m '#{options.message}' &quot;</B>

<I># Append the filenames with the -a option to send them as attachments
</I><I># Only the non options (the filenames) are left in ARGV
</I><B>unless</B> ARGV.empty?
  command += <B>&quot; -a #{ARGV.join(' ')}&quot;</B>
<B>end</B>

<I># Print the command to screen if using verbose mode.
</I>puts command <B>if</B> options.verbose
system command

Growl.notify <B>&quot;#{options.subject}\n#{options.message}&quot;</B>, :icon =&gt; :jpeg, :title =&gt; <B>&quot;Email sent to #{options.to}&quot;</B>
</pre>
<p>The script requires you to install <strong>sendemail</strong>. It also requires you to install the <strong>growlnotify</strong> command line utility that is distributed with <a href="http://growl.info/">Growl</a> and the gem that uses this utility, also conveniently named <strong>growl</strong>.</p>
<h3>Install required dependencies on OS X</h3>
<pre>
<I># Install sendemail and capabilty to send secure mail, required by Gmail
</I>sudo port install sendemail p5-net-ssleay p5-io-socket-ssl

<I># Install growl command utility from the mounted image
</I>sudo sh /Volumes/Growl-1.2/Extras/growlnotify/install.sh

<I># Install the growl gem
</I>sudo gem install growl
</pre>
<p>That&#8217;s it, a simple script that will allow you to send messages and files through<br />
gmail from the command line.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/01/16/scripting-in-ruby/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

