• Subscribe to the RSS feed! RSS icon
  • Subscribe by Email
  • home
  • blog
  • dev
  • Recent Posts

    • Automatically upload screenshots in XFCE4
    • Zend Framework full page cache tips
    • No more Wordpress
    • Xdebug is full of awesome
    • Creating a chat bot with PHP and Dbus
    • A year in review: 2011
    • Notes on shell scripting
    • Listening to Dbus signals with PHP
    • Configuring 2 monitors with xrandr
    • A quick note on Dojo's data grids and dojox.data.HtmlStore
  • Recent Comments

    • Robert on Zend Framework full page cache tips
    • Stephen S. Musoke on Zend Framework full page cache tips
    • David on Zend Framework full page cache tips
    • Anon on A quick note on Dojo's data grids and dojox.data.HtmlStore
    • James on Communicating with Pidgin from PHP via D-Bus
    • Robert on A Zend Framework 2 EventManager use case
    • Jowee on A Zend Framework 2 EventManager use case
    • Jurian Sluiman on A Zend Framework 2 EventManager use case
    • Jurian Sluiman on A Zend Framework 2 EventManager use case
    • djozsef on Webkonf 2011 recap
  • Tags

    php, about, random, framework, zend, example, ubuntu, blog, site, zend framework, book, conference, me, python, wordpress, apache, introduction, lamp, linux, open source, review, script, setup, signals, ape, community, contributing, dbus, dojo, events, hack, mysql, netbeans, pidgin, plugin, pyqt, security, shell, svn, talk
  • Categories

    • Blablabla
    • Development
    • Free time
    • Places on the web
    • Programming
    • Software
    • Uncategorized
  • Archives

    • February, 2012
    • January, 2012
    • December, 2011
    • November, 2011
    • October, 2011
    • September, 2011
    • August, 2011
    • July, 2011
    • May, 2011
    • April, 2011
    • March, 2011
    • January, 2011
    • December, 2010
    • November, 2010
    • October, 2010
    • July, 2010
    • June, 2010
    • April, 2010
    • February, 2010
    • January, 2010
    • December, 2009
    • November, 2009
    • October, 2009
    • August, 2009
    • May, 2009
    • March, 2009
    • February, 2009
    • January, 2009
    • December, 2008
    • November, 2008
    • October, 2008
    • September, 2008

Archive for the 'Programming' Category

Playing with Zend Framework and Dojo

by Robert Basic on March 2nd, 2011

Yesterday there was some talk on Twitter including Zend Framework and Dojo. I didn't quite follow it through, something about why Dojo and not jQuery, it's not that popular blablabla. Anyway, who cares? We have Zend_Dojo, we have ZendX_Jquery. I'm using ZendX_Jquery, but only as far as setting it up and loading jquery and jqueryui via the view helpers. Tried to use it on forms, to use tabs and whatnot, but in the end it was easier to write up a separate javascript file and do the jquery stuff there. But, I've never used Zend_Dojo before. Guess I was a bit scared away with all that dojo, dijit, dojox stuff... So, last night, being bored and all, I've decided to try and use it. Oh boy. How wrong was I for not diving into it before. OK, so far I've created only one form with dojo, but damn it's good.

In short: set up the Zend_Dojo view helpers, pick a theme, make the forms extend Zend_Dojo_Form, change the elements from Zend_Form_Element_* to Zend_Dojo_Form_Element_*, if needed add/tweak some attributes and bang! the form is all sexy with nice colors & rounded borders & (error) messages in a nice little tooltip. And I haven't wrote a single line of javascript. Not.a.single.line. Magic, I like it.

Setting it up

All I did was to set up dojo is:

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    public function _initViewHelpers()
    {
        $this->bootstrap('layout');
        $this->_layout = $this->getResource('layout');
        $this->_view = $this->_layout->getView();

        $this->_view->addHelperPath('Zend/Dojo/View/Helper','Zend_Dojo_View_Helper');

        $this->_view->dojo()
                        ->enable()
                        ->setCdnBase(Zend_Dojo::CDN_BASE_GOOGLE)
                        ->setCdnVersion('1.5.0')
                        ->setCdnDojoPath(Zend_Dojo::CDN_DOJO_PATH_GOOGLE)
                        ->addStyleSheetModule('dijit.themes.claro')
                        ->useCdn();
    }

and then just called echo $this->dojo(); in the layout and added class="cairo" to the body element. I think this body thing can also be done via the helpers. The biggest struggle I had with the theme. Where do I download it? There's no "download theme x" on the dojo website. How do I set it up? What is this madness? Then I realized it can pull not just the javascript files from the CDN, but also the CSS and images! Very cool.

A simple form

Next step: spice up the forms with Zend_Dojo_Form:

<?php
class My_Form extends Zend_Dojo_Form
{
    public function init()
    {
        $this->addElement(
            'ValidationTextBox',
            'title',
            array(
                'label' => 'Title:',
                'missingMessage' => 'You have to enter something', // overriding the default "This value is required."
                'promptMessage' => 'Enter a title', // on focus
                'invalidMessage' => 'Type some random characters, 3 min, 100 max', // error message for the failed regExp
                'regExp' => '.{3,100}', // regexp for validation
                'required' => true,
                'validators' => array(
                    array(
                        'validator' => 'StringLength', 'options' => array(3, 100)
                    )
                ),
                'filters' => array(
                    array(
                        'filter' => 'StringTrim',
                        'filter' => 'StripTags'
                    )
                )
            )
        );

With these ~20 lines I've got some basic client side validation with a pretty nice look and feel to it while still having all of the Zend_Form power to do the validation and filtering on the server side. Still need to figure out what those "constraints" are and how and for what to use them (they're in the ZF manual, so they gotta be good for something), how to add for example a dojox.validate.isEmailAddress validator to the element, but for starters, this is quite impressive.

Besides this, I've also played with Zend_Dojo_Form_Element_Editor which is a WYSIWYG editor, extended Zend_Dojo_Form_Element_Button to create my own ResetButton (for some odd reason there is no reset button in Zend_Dojo), played around with the decorators... But that's for some future rambling, gotta go to work now.

In the end, I feel stupid for not using Zend_Dojo before, well, Zend_Dojo_Form at least, but I definitely will be from now on. Here's to hoping that it will be included in Zend Framework 2, too :)

Happy hackin'!

Tags: dojo, form, zend framework, zend_dojo.
Categories: Programming.
Comments: 1 comment.

A real gem - PHP_CompatInfo

by Robert Basic on December 27th, 2010

Last night I was pondering how nice would it be to have a tool of some sort, that would simply spit out what version of PHP does my app require. Something like: here are my .php files, what PHP version and/or extensions do I need for it? First I thought about jumping right in and writing it myself, but hey, this kind of a tool sounds way to useful not to be written already! After a bit of a googling there it was: PHP_CompatInfo. A nice PEAR package that can tell me everything I want about my code and even a bit more.

It tells what's the minimum overall PHP version needed, all the PHP extensions used and the PHP versions and extensions file by file.

Installing PHP_CompatInfo is easy: pear install php_compatinfo and that's about it. Using it isn't much harder:

<?php

require_once 'PHP/CompatInfo.php';

$source = '/home/robert/www/Zend/';

$driverType = 'xml';
$driverOptions = array();

$info = new PHP_CompatInfo($driverType, $driverOptions);
$info->parseDir($source);

Include the main PHP_CompatInfo file, set the path to the file or directory you want to check and then just run it. By default it'll just var_dump the results, which is pretty much OK for a few files and directories. For a library like Zend Framework, I found the XML output to be the best. Besides the var_dumping and XML, there are other options for the output like CSV, a simple HTML table and Text, which is used when using the CLI. Oh, right, you can run it either from the console or from your web browser. PHP_CompatInfo's documentation is very well written and describes all part of it, so I won't be bugging you with that.

So yea, this little gem goes right into my box of must have tools.

Tags: extensions, info, information, php, version.
Categories: Development, Programming.
Comments: None.

Passing arguments to custom slots in PyQt

by Robert Basic on November 30th, 2010

While hacking on ape, I came to a situation where I need to pass some arguments to a custom defined slot. The slot is being called from different signals, one where the argument is passed by PyQt itself and a second one where I need to programmatically pass the argument to the slot.

First I tried with something like:

action = QAction("My action", parent)
action.triggered.connect(my_slot(my_argument))

which ended in an error: TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'

After a bit of poking around I passed a lambda function to the connect() method:

action = QAction("My action", parent)
action.triggered.connect(lambda arg=my_argument: my_slot(arg))

Works like a charm.

Also this is my first try to use github gists as a way to embed/highlight code. Hope it'll work out.

Happy hackin'!

Tags: ape, lambda, pyqt, python, signals, slots.
Categories: Programming.
Comments: None.

Connecting signals and slots with PyQt - the new style

by Robert Basic on November 9th, 2010

While working on ape I had a problem with figuring out how to properly connect a signal to a slot, where the signal is emitted by a QTreeView widget. As this is not my first app with python and pyqt, I was doing something like (this is, btw, the "old style"):

self.connect(widget, SIGNAL("emitted_signal()"), self.my_slot)

but it simply didn't work. Nothing happened. I was trying all different of connect/signal/slot combinations but everything was just dead silent. Google gave only pretty much old posts talking about QT3. Then I figured that, because the QTreeView is "sitting" inside a QDockWidget, maybe that dock widget thingy is somehow intercepting/taking over the signals. Nope. Wth? Wtf is going on? Current pyqt version is (on my machine) 4.6. Last time I used pyqt it was something like 4.2 or 4.3. Something must've been changed in the mean time. Off to the pyqt docs I go (btw, I use the official QT docs, the C++ version, there isn't really a big difference from pyqt): PyQt reference, chapter 7 - "New-style Signal and Slot Support". A-ha! They changed it! Here is an example of the "new style":

widget.emmited_signal.connect(self.my_slot)

Oh my, isn't that just beautiful?! Much more readable and simpler, for me at least. And it works! Yay! The QTreeView signals are happily connected to slots, thus, I'm happy too.

A few paragraphs later, turns out that the "old style" isn't thrown out, it should still work. Why it didn't work for me escapes me at the moment, but honestly, I don't really care as long as the new style is working.

Happy hackin'!

P.S.: The syntax highlighter is a bit out dated thus breaking python code. Will fix it. Some day.

Tags: ape, pyqt, python, signals, slots.
Categories: Development, Programming.
Comments: None.

ape is a PHP editor

by Robert Basic on November 6th, 2010

A week ago I started working on a simple editor/IDE for PHP called ape. That's my weak try on creating a reverse acronym as ape stands for - ape is a PHP editor. This is kind of an introductory post into the whole developing process of it, as my intention is to blog about it a bit more :)

Why?

First, to answer the question everyone is giving me when I mention I'm writing ape:
"Why the hell do you do that (to yourself)?"

Programming is fun. Programming is interesting. Programming makes me learn new things. I like having fun and I do this to learn more about programming and having even more fun. I'm writing web applications each and every day, so writing a desktop app requires a different way of thinking and leaving my "comfort zone" (altho, I'm quite comfortable in front of the keyboard hackin' away code). ape is written in python and pyqt, but again, it's not about the language used, for me it is about programming.

The idea

Netbeans is my main IDE for quite some time now and I love it. I know my way around vim, too. But, netbeans has too many features for my taste - I use SVN, git, (on rare occasions I write them) run unit tests from the console. As for vim, maybe I just don't get it enough, but I feel less productive with it. Debugging PHP apps ends up var_dump-ing things all over the place. So, basically what I want/need from an editor is grouping files into projects, regex search/replace, code coloring & completion and, of course, file editing.

I plan to write a feature a day. On my personal projects I usually want to push out as much code as I can during one day as I'm highly motivated, but this time want to try a different approach. So far I didn't got far, figured out syntax highlighting, opening files from a file browser widget thingy and things like that, but more on that in other posts.

If anyone wants to take a look, the source code is up on github. It is licensed under GNU GPL v2, as pyqt is licensed under it and I don't want to waste my time on figuring out could I use MIT or some other license.

Happy hackin'!

Enhanced by Zemanta
Tags: ape, editor, ide, php, pyqt, python.
Categories: Development, Programming.
Comments: 8 comments.
« ‹ 3 4 5 6 7 › »
Robert Basic © 2008 — 2012
Design & graphics by: Livia Radvanski
Coded by: Robert Basic
Home page last updated on November 30th, 2009.
Frameworks used: Zend Framework, Dojo, 960 Grid System