Results 1 to 9 of 9

Thread: First python script - Ubuntu Control Panel

  1. #1
    Join Date
    Jan 2007
    Location
    California
    Beans
    46
    Distro
    Ubuntu 7.04 Feisty Fawn

    First python script - Ubuntu Control Panel

    Hello everyone, I'd thought I'd show off my first, biggest, and only python script. It is a control panel for Ubuntu. I was reading in the wiki that there is need for a Control Panel to keep all of the settings programs together. I decided that I wanted to write it. As my first python script I wrote a text-based version to get the concept down, i'll probably work on a GUI one soon. Tips would be great!

    Get the script here

  2. #2
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: First python script - Ubuntu Control Panel

    Without thinking too much about it (or even running it), just from surface:

    1) First impression: Not bad for a first script.
    2) Missing docstrings, you may want to read coding standards of team who will integrate your script somewhere to Ubuntu, they may require them.
    3) one-letter variable names are hard to search for. Minor detail, but sometimes might save you time to use ii, kk ect. Or even better: meaningful names.
    k is key, l is label, i is in?
    4) I would probably tried to avoid magical category numbers and related text strings, instead put menu in some dictionary. But it is possibly premature optimization, check how Ubuntu wants to do it for i18n (=internationalization) so it can be translated, if you want to learn the ropes to get it included.

    Again, commenting on style only, without actualy trying to understand how it works.
    Last edited by pmasiar; January 3rd, 2007 at 02:51 PM.

  3. #3
    Join Date
    Jun 2005
    Location
    Malta
    Beans
    4,187
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: First python script - Ubuntu Control Panel

    Not bad. Hardware doesn't work for me though.

    Good luck upon the gui version, and keep it up.

    Error for Hardware :

    --Hardware--
    Mouse
    Removeable Drives and Media
    Keyboard Shortcuts
    Keyboard
    Traceback (most recent call last):
    File "ubuntucontrolpanel.py", line 113, in ?
    main()
    File "ubuntucontrolpanel.py", line 110, in main
    menu.selectCategory()
    File "ubuntucontrolpanel.py", line 95, in selectCategory
    self.printMenu(3)
    File "ubuntucontrolpanel.py", line 78, in printMenu
    self.selectCategory()
    File "ubuntucontrolpanel.py", line 93, in selectCategory
    self.printMenu(2)
    File "ubuntucontrolpanel.py", line 51, in printMenu
    while i != "exit":
    UnboundLocalError: local variable 'i' referenced before assignment

  4. #4
    Join Date
    Jan 2007
    Location
    California
    Beans
    46
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: First python script - Ubuntu Control Panel

    Ok, thanks for the input. I'll definitely work on it a bit more.
    Last edited by Cirdan7; January 4th, 2007 at 04:24 AM.

  5. #5
    Join Date
    Jan 2007
    Location
    Italy
    Beans
    15
    Distro
    Xubuntu 9.10 Karmic Koala

    Re: First python script - Ubuntu Control Panel

    Nice ^_^.

    I have a problem on Hardware too:

    Mouse
    Removeable Drives and Media
    Keyboard Shortcuts
    Keyboard
    Traceback (most recent call last):
    File "ubuntucontrolpanel.py", line 113, in ?
    main()
    File "ubuntucontrolpanel.py", line 110, in main
    menu.selectCategory()
    File "ubuntucontrolpanel.py", line 93, in selectCategory
    self.printMenu(2)
    File "ubuntucontrolpanel.py", line 51, in printMenu
    while i != "exit":
    UnboundLocalError: local variable 'i' referenced before assignment


    Try to build a GUI with zenity, it is very easy .

  6. #6
    Join Date
    Jun 2005
    Location
    Malta
    Beans
    4,187
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: First python script - Ubuntu Control Panel

    Or else try using PyGTK. I did some work on it in the holidays and it wasn't too hard.

    BTW, are you a fan of LOTR, Cirdan7?

  7. #7
    Join Date
    Dec 2006
    Beans
    57

    Re: First python script - Ubuntu Control Panel

    of course everyone will have a problem with option 2, he forgot to add a line before the while in category 2. i = self.getInput() at line 51, just a common mistake. keep the work going

  8. #8
    Join Date
    Jul 2005
    Location
    Remote Desert, USA
    Beans
    683

    Re: First python script - Ubuntu Control Panel

    Download pgst from SourceForge.net, open it up, and learn how it works. I made it after seeing how RedHat made their Python control panel items. I used Glade-2 to draw the GUI and then used some tricks in Python to load the GUI and respond to signals from it.

    Another approach:

    Learn XUL from Mozilla and build a custom XUL chrome that you can load with a special command line option in Firefox. Have it connect back to a thin, embeddable web service on an alternate port like 26224. Thttpd is a good one. Have it use CGI to call either Perl, Python, or PHP. If you need a database and an ordinary CONF file won't work, then use SQLite because it's got a great license and is designed especially to be suitable as an embeddable standalone database for small projects.
    SuperMike
    When in doubt, follow the penguins.
    Evil Kitty is watching you

  9. #9
    Join Date
    Jan 2007
    Location
    California
    Beans
    46
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: First python script - Ubuntu Control Panel

    Quote Originally Posted by Lord Illidan View Post
    Or else try using PyGTK. I did some work on it in the holidays and it wasn't too hard.

    BTW, are you a fan of LOTR, Cirdan7?
    Somewhat...I've only seen the movies. Long story short, I put my name into a LOTR name generator and this popped out. I did it because my last username was quite common.

    As for the UI, I was planning on using pyGTK. Maby I'll look at the XUL thing if its not too complex.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •