Stefano Mtangoo 455 Senior Poster

@EV
black sheep = Bad member of the family. The wrong one. The one they don't mention in public or polite conversation.

I didn't knew that hehehehe!
:)

Stefano Mtangoo 455 Senior Poster

mh I'm newbee somehow.
would you take me step by step? I'm lost in your good explanation. Because I'm novice

Stefano Mtangoo 455 Senior Poster

It looks like you have all of the essentials, except one thing...no FormArray definition in the code above.
Nothing in -> nothing out.
Put some names and types in there and it should work.

No JRM,
The array is passed in the constructor during instantiation of the class.
see this comment

//pass array to build a form in form of name=>type eg username=>text to a constructor

Also the code works but I don't know how to add a field for labels. This code just displays controls and no labels. I lack technique to add labels

Thanks for reply

Stefano Mtangoo 455 Senior Poster

Hi I want to make form dynamically by just passing array of stuffs. I have tried but cannot may be due to my limitation in PHP. Here is what I have so far. Please help me!

class MyForm{
    private  $formArray;
    //pass array to build a form in form of name=>type eg username=>text to a constructor
    public  function   __construct($postArray) {
        //make the form POST variables available to the class
        $this->formArray = $postArray;
        //print_r($this->formArray);
    }

    //construct a form
    public  function  buildForm($actionFilePath='login.php'){
        echo "<form action='$actionFilePath' method='POST' id='loginform'>";
        echo "<table border='1', cellpadding='5'> ";
        foreach ($this->formArray as $name => $type) {
            echo "<tr>
                 <td><input type='$type' name='$name' id='$name' /></td>
                 </tr>";
            

        }//end foreach

        echo "</table>";
    }



}// end form class
Stefano Mtangoo 455 Senior Poster

I plan to make Java image viewer
I just started today and I had hard time with GridBagSizer
After long time of pain it turned to be fruitful. Here is what I have so far. I want the following, of which I have failed:
1. Make the components fill the whole window when resized
2. I want the tree to be list of directories than what it is now. In wxPython there is Directory control I dont know of Swing
3. How will I hold the list of directories and files to play with. In Python there are lists, tuples and dictionaries

Thanks for your time.

package imageviewer;

import javax.swing.*;
import java.awt.event.* ;
import java.awt.*;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: Hosanna Technologies
 * Date: Jan 30, 2010
 * Time: 12:56:54 AM
 */
public class MainClass {
    public static void main(String args[]){
        Viewer iviewer = new Viewer() ;
        JFrame frame = new JFrame("Hosanna Image Viewer"); //add our panel
        frame.getContentPane().add(iviewer, BorderLayout.WEST);
        iviewer.MakeMenu(frame);
        frame.setSize(500, 500);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
}


class Viewer extends JPanel{
    private GridBagConstraints c ;
    private JButton prev;
    private JButton slideshow;
    private JButton next;
    private JButton zoom;
    private JButton delete;
    private JButton rotateleft;
    private JButton rotateright;
    private JButton fill;
    private JTree imagedir;
    private JPanel viewer;

    public Viewer(){
        this.setLayout(new GridBagLayout());
        c = new GridBagConstraints();

        imagedir = new JTree();
        c.fill = c.VERTICAL;
        c.gridx = 0;
        c.gridy = 0;
        c.insets = new Insets(0, 10, 0, 0);
        c.gridwidth = 1;
        c.gridheight = 10; …
Stefano Mtangoo 455 Senior Poster

Ok guys, I hope the man will apologize. Apologizing when you are wrong is sign of maturity!
@Ardav, what black sheep means ;)

@JRM what will hapen if your son is of like manner? will you avoid him? ;)

Its fine guys, whatever you want. I hope Midnite will do apologize to set things straight

Cheers buddies!

Stefano Mtangoo 455 Senior Poster

Better get used to Visual Studio. It's the most used IDE for Windows development out there by far.
It's actually a very good (in the later versions, not talking v.6 here) product, but it's very large and complex which means beginners often don't like it because there's so much to learn.

Yes you are right! There was so many stuffs in VS 2008 Express that I uninstalled

Stefano Mtangoo 455 Senior Poster

If that doesn't work use the wxStaticText's SetLabel() mathod

Stefano Mtangoo 455 Senior Poster

Oh sorry. My browser stopped loading and the code you typed didn't show up.
Anyway, I tried that and it printed out, just not in the GUI. It ended up printing it in the idle shell

It should print in both console and Label

Stefano Mtangoo 455 Senior Poster

Your last post and the first one now makes alot of sense. I have read alot of wxDCs and they are very useful!
Thanks alot

Stefano Mtangoo 455 Senior Poster

Absolutely bloody ridiculous. I'm in your class (CSC108) and I know the prof has offered office hours to help people with the assignment. There's no excuse for you to just paste the whole assignment into an online forum expecting someone to do it for you while other students are sitting here busting their balls trying to get it done on their own.

Nice work ethic, although I suppose it's my fault for expecting more from UofT students.

Laziness is virtue ONLY if you are lazy enough to be lazy person

Stefano Mtangoo 455 Senior Poster

I already Know Ancient Dragon is fan of MSVS due to its debugging features and I use C::B because it is the only I have come to love after failing to love both VS Express and Codelite. So what do you love to use when it come to C/C++?
Just curious ;)

Stefano Mtangoo 455 Senior Poster

I did not intend to join an ongoing service - I only wanted to find the answer to ONE question, which I did not get. I am not savvy enough to make us of your Forum. Please unsubscribe me immediately.

And who did subscribe you? and secondly which question are you talking about?

Stefano Mtangoo 455 Senior Poster

Why keep yelling? and who is Daniweb here? I'm curious why you are so mad at email notifications that you agreed to receive? did anyone forced you to? If no then you should be asking politely than threating putting curses! You should learn acronym R.E.S.P.E.C.T.

Now I see, you want to avoid flood of email from DaniWeb.
You can:
2 Try your Python skills and write small program to UNsubscribe you. :)

Yup! That's very funny H.

Stefano Mtangoo 455 Senior Poster

glad I helped

Stefano Mtangoo 455 Senior Poster

in this line where do you get username.screen_name?

wx.StaticText(panel, -1, username.screen_name, (10,100))

change to something like this

#
for username in userlist:
#
wx.StaticText(panel, -1, username, size = (10,100))
Stefano Mtangoo 455 Senior Poster

are you asking something like this? or this one?

Stefano Mtangoo 455 Senior Poster

You run this little program ...

# the base64 image string has been created with this short
# program, the resulting string is then copied and pasted
import base64
jpg_file = "Btn_next.jpg"
jpg2base64string = base64.encodestring(open(jpg_file,"rb").read())
print "Btn_next_jpg_b64='''\\\n" + jpg2base64string + "'''"

Make sure you have the image file in the working folder.

If you use it much of the time you can make a GUI app to embed all images in folder in same file and give them same name as their names.

Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

Even after that, resizing the frame/canvas still screws with the event loop. So I would recommend fixing the frame size like this:

Yes, it works! So what was wrong?

Stefano Mtangoo 455 Senior Poster

Hello Python community,

I've just finished building an app with Python and I'd like to share my experiences and get some feedback. This was from scratch (no code templates) all the way to compile and distribution on a Windows environment. Now all my colleagues at work are using the app with no problems.

Bravo!

I'll start off with some queries and questions that I had building the app, that I couldn't solve and then we'll move on to my experiences.

1. What is the standard way to put images on your toolbar buttons on other languages? Do you put your images in the install folder (i.e. the folder within the C:\Program Files\ folder) ??? or do you embed them in the code either directly or putting them into a DLL file or something. And is what I am doing right in terms of creating the toolbar buttons and images?

All those are possible
- Put images in folder and load them using wx.Bitmap while adding to let say toolbar
Untested but to give flavor

mytoolbar.AddLabelTool(.....wx.Bitmap("./icons/exit.png", wx.BITMAP_TYPE_PNG))

- You can embed them using base_64 encode. See somewhere in your wxPython folder. I hope you will go on writing GUI front end for that tool ;)
- You can Put them in DLL or use DLL your friend wrote for you in C++ and use ctypes to access it

2. This is a related question. How do we normally package and distribute apps and their respective …

Stefano Mtangoo 455 Senior Poster

Hello to all my fellow IT people!

I have two questions!

I would like to start learning how to program! Is Java a good beginners language to start with and if it is not what is a good language?

My second question is if Java is a good language then what are some good books or websites that could help me with learning the language.

Java is one of the best languages out there if you meant that but I don't recommend it to begin with though it is possible to learn with Java. The reason is, there is easier and elegant language called Python. Start with that. It is full of free and printed books out there

Stefano Mtangoo 455 Senior Poster

I'm really tired and I cannot do anything useful with your code for now. But I tried to google for such stuffs and you may look at these links:

http://stackoverflow.com/questions/1513618/copy-all-files-and-folder-from-one-directory-to-another-directory-php
http://www.codingforums.com/showthread.php?t=146554

Check and see how they are related to your problem :)

Stefano Mtangoo 455 Senior Poster

I'm IntelliJ since I learn how to read and write (just joking)

I started with JCreator which is very simple and handy tool to avoid general confusion of all the functionality provided by big names. I moved on to NetBeans, but mobile development with is painful so now I use it very sparely. Unfortunately me & Eclipse relation never worked out. Never fear Eclipse is not the only one free and with plenty of plugins for this or that, IntelliJ is toooo...

So IntelliJ FTW!

Actually someone called Peter Budo was source of me trying IntelliJ Idea. I heard he is such a fanatic of it and was excited to see how it looks like ;)

I still believe Eclipse is superior to all IDEs I know, (including Netbeans?) but not sure how it compares to IJ. So I'm trying IJ to see what is under the hood!

Stefano Mtangoo 455 Senior Poster

EV - this is what he said:

He doesn't have the time, but thinks that we do. He even gave me a neg rep for pointing out this erroneous thinking. Well, that's the end of any help I'm prepared to offer. Huh, I can imagine that he'll get himself a new login with the name Midnite003!:icon_lol:

All of us here have little time which we share whatever we can. Whatever happened, I think we should forgive each other especially in hot things like this. I have seen many best friend who one day quarreled heavily and were potential candindate for enemnity. Let's forget and move helping the guy!

No preaching intended as it is techie forum ;)

Stefano Mtangoo 455 Senior Poster

Switched from JBuilder to Eclipse a few years ago and never looked back.

Can you share what caused the turn-over? ;)

Stefano Mtangoo 455 Senior Poster

Here is a very simple example ...

Thanks Vega it works but it flickers and only stabilize while resizing to then flicker and flicker.... ad infinitum! What is the cause and how can I tame it?

BTW you didn't include that fat duck image :D

Stefano Mtangoo 455 Senior Poster

right, I was raising an error with that certain condition, sorry about the wording earlier.

Just another question though, what if I wanted the '6' from the raiser to be changed to an int so that the print "Passed 2" statement you used earlier would not be printed? would the condition I used earlier

x != int(x)

be correct? or no?

Don't understand what you mean here!

Ideally, I wanted raiser('6') to pass normally without raising any exceptions, just like raiser(6) passes normally for the program.

what are you trying to accomplish in very summary?

Stefano Mtangoo 455 Senior Poster

the error still comes out the same

That is not error, it is exactly what you're telling it to do! You tell it to raise value error and it does right? Remember computers aren't intelligent at all, garbage in garbage out!

use this code to see what is going on

class  E2Exception (Exception):
    pass

class  E2OddException (E2Exception):
    pass

def raiser(x):
    if x == 'So sue me!':
        raise E2Exception, "New Yorker"
    elif ((int(x)) % 2) != 0:
        print "Passed 1"
    elif ((x != 'So sue me!') and (x != int(x))):
        print "Passed 2"
    return

if __name__ == '__main__':
    raiser('6')
Stefano Mtangoo 455 Senior Poster

try this

elif ((x != 'So sue me!') and (x != int(x))):
        raise ValueError

Mind you that it raises value error because you might be converting non-numeric string (that is, x is not a numeric string like "f"). Posting your whole code will help to pinpoint the problem

Stefano Mtangoo 455 Senior Poster

I have tried that is the POINT I dont know where to start i am new to this so i dont understand the syntax ?

As far as I know, one cannot learn a language before learning the basics. So before you tr to do anything, grab the basics

Then go back to scripts given before and make whatever you want out of them. If you fail somewhere, come back and ask.

nav33n commented: Bingo! +6
Stefano Mtangoo 455 Senior Poster

Ok, we have your assignment here, where are your efforts?

Stefano Mtangoo 455 Senior Poster

So where is the code? We are humans and cannot see your codes hidden under HDD to poke for errors ;)

Stefano Mtangoo 455 Senior Poster

I was sitting Idle and I decided to write simple image viewer to try myself on DC/Canvas but I didn't find any tutorial to guide me as I have never done that before. Here there are some restriction and I cannot view showme do. So anyone to help me with basics how to draw image to a wxPanel?

Thanks!

Stefano Mtangoo 455 Senior Poster

I wanted to know how people here in DW use which templating system

Stefano Mtangoo 455 Senior Poster

This is not seek for IDE thread but rather want just to know your beloved IDE.

For Me, up to recently I used Eclipse but now I'm trying IntelliJ Idea community. Not very used to it but looks promising. What about you friend?

Stefano Mtangoo 455 Senior Poster

where have you reached so far?
I can assist you with little time I have. Just post where have you reached so far and what is the problem ;)

Stefano Mtangoo 455 Senior Poster

Thanks alot. I know the "general" work of try/exception. But I lack a lot for PHP. Thanks for your clear explanation. So can you explain a little more about how for example to do throw. For example in python I would do

try:
    #some code
except IOError:
    #do Some Code

Where do you specify something Like IOError? Or there is nothing like that in PHP?

Stefano Mtangoo 455 Senior Poster

I got putty to work with Ximing though ximing is having problems as I can't start my apps. Is there another X-server for windows?

Stefano Mtangoo 455 Senior Poster

and this is the code that you can use to test. put the files in one dir
index.php

<html>
    <head><title>Test Login Form</title></head>

    <body>
        <?php

            require('inc.form.php');
            echo '<h1>Register</h1>';
            $formArray = array('username'=>'text', 'password'=>'password', 'submit'=>'submit');
            //print_r($formArray);
            $form = new MyForm($formArray);
            $form->buildForm('inc.form.php');
        ?>


    </body>



</html>
Stefano Mtangoo 455 Senior Poster

Ok, I'm rebuilding everything according to Kay's idea. First thing is to build a form dynamically. After thinking a lot I produced this class and works. But I have no Idea how to add labels without adding complexity to the arrays. Currently it is as simple as you see. So please advise me how to add labels without making it totally convoluted. Also there might be another way of doing it so I'm waiting to hear from you guys
Thanks

inc.form.php

class MyForm{
    private  $formArray;
    //pass array to build a form in form of name=>type eg username=>text to a constructor
    public  function   __construct($postArray) {
        //make the form POST variables available to the class
        $this->formArray = $postArray;
        //print_r($this->formArray);
    }

    //construct a form
    public  function  buildForm($actionFilePath='login.php'){
        echo "<form action='$actionFilePath' method='POST' id='loginform'>";
        echo "<table border='1', cellpadding='5'> ";
        foreach ($this->formArray as $name => $type) {
            echo "<tr>
                 <td><input type='$type' name='$name' id='$name' /></td>
                 </tr>";
            

        }//end foreach

        echo "</table>";
    }



}// end form class
Stefano Mtangoo 455 Senior Poster

till now I have never done anything dealing with exceptions.
Now I have to deal with exception. Basically I have function below which I want to wrap in try/exception. I want to connect to database and if database connection failed then it should catch exception that will do some stuffs and then return false.
If successful it just returns true.

Can one explain with grain of salt how exceptions are done in PHP. I have tried a lot to read but I get lost. I have only experience with Python exceptions that are a lot easier than in PHP

here is a function in question

public function __construct() {
        $conn = mysql_connect($this->dbuser, $this->dbpass , $this->dbhost) or die("Cannot connect to database: Error - ".mysql_error());
        mysql_select_db($this->dbname);
        return $conn;
    }
Stefano Mtangoo 455 Senior Poster

Personally, I'd stay clear of js if possible - header() if used correctly shouldn't cause an error ("headers already sent")..

JS is the best way to go but only if you are sure your users will not turn off JS in their browsers. No one in the world can guarantee that so here is what I do:
1. Create Pure XHTM/PHP site
2. Add JS to do PHP stuffs at Client.
If user's JS is on some basic things like empty field will be dealt at user level and relieve server of unnecessary queries

Cheers ;)

Stefano Mtangoo 455 Senior Poster
$conn = mysql_connect($this->dbuser, $this->dbpass , $this->dbhost) or die("Cannot connect to database: Error - ".mysql_error());

I don't like this. In my code I would like to know if something succeeds/fails, so additional handling can be done (e.g. logging). A die() will also stop my own code. Either use a return value or property to read the outcome, or throw an exception.

Ooops! Such a foolish mistake ;)
I have to change that to return either true or false in case of any error! Thanks for pointing that

Stefano Mtangoo 455 Senior Poster

I prefer SetValue than write why? Because it is generic to all widgets

Stefano Mtangoo 455 Senior Poster

Its not really doing that. The class is creating the JFrame. In this case the class also happens to be the JPanel :)

Ooh! I understand now.

Stefano Mtangoo 455 Senior Poster

I heard some people that SPE doesn't work well with Pytho2.6
May be Ubuntu guys tweaked it a little. Check Wing IDE or Eclipse with Python plugin, Pydev

Stefano Mtangoo 455 Senior Poster

to be comfortable with arrays check foreach loop

Stefano Mtangoo 455 Senior Poster

header is what you need

Stefano Mtangoo 455 Senior Poster

if you know how to do it from CLI then try subprocess