Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:42:08+00:00 2026-05-16T17:42:08+00:00

I’m currently writing a PyGTK application and I’d like some advice as to the

  • 0

I’m currently writing a PyGTK application and I’d like some advice as to the best way to structure my application. Basically the application will read a specific file specification and present it in a GUI for editing.

Currently I have a parser.py which handles all the low level file IO and parsing of the file. I’m displaying the contents of the file in a treeview, which means that I need to use a treestore as my data type.

The problem I’ve ran into is that I’ve only thought of two solutions to this problem. The first is that my parser could build a treestore and pass it to my ui class. That requires my parser depending on pygtk, and minimizes the potential reuse for the class. The second would be storing a reference to my ui class in parser, which would also potentially limit the reuse of my parser class as a standalone library.

To condense my question into a short one liner: Is there a way to accomplish my goals in a more pythonic or OO-friendly way?

If looking at my code would help anyone trying to answer my question: https://code.launchpad.net/~blainepace/nbtparser/trunk

Other pythonic suggestions welcome, this is my first python program and I may be stuck in a more C++ style of thinking. I plan on refactoring a lot of it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:42:08+00:00Added an answer on May 16, 2026 at 5:42 pm

    You should take a look at the tutorial “Sub-classing GObject in Python”. This goes through using GObject’s type system to create signals and properties, which allow you to model underlying behavior in a way that is easy to integrate with typical PyGTK semantics (connecting to signals, waiting for property notifications, etc).

    Both your parser and UI should have only properties and signals to connect to. You then have a third class that connects up these signals and callbacks and starts the main loop in a if __name__ == __main__ block.

    Typically, mine look something like:

    class MyApp(gtk.Window):
    
        def __init__(self, parser, ui):
            gtk.Window.__init__(self)
            parser.connect("some-signal", ui.update_this)
            parser.connect("some-other-signal", ui.update_that, extra_params)
            ui.connect("refresh-clicked", parser.reparse_file)
            self.add(ui)
    

    …and then in your main script:

    parser = parser.Parser(...)
    ui = view.ParseView(...)
    app = MyApp(parser, ui)
    
    app.show_all()
    
    gtk.main()
    

    Of course, this is often different depending on eg. am I using Glade? Do I subclass widgets for the main app or wrap them? etc.

    The great thing about this is that you can then write, say, a test parser that does nothing but return pre-programmed responses, or uses a known test file. Swapping it in is as easy as changing one line above:

    parser = parser.DummyParser(...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.