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 1013579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:07:24+00:00 2026-05-16T10:07:24+00:00

I wrote a simple PyGTK script to show some basic process information in a

  • 0

I wrote a simple PyGTK script to show some basic process information in a TreeView:

import gtk
import os
import pwd
import grp

class ProcParser:
    """
    Parses the status file of a particular process
    """
    def __init__(self, fname):
        self.lines = map(lambda x: x[:-1], open(fname).readlines())

    def get_by_val(self, val):
        for line in self.lines:
            if line.startswith(val):
                return line.split()
        return []

class Proc:
    """
    A process in the /proc filesystem

    This class uses a ProcParser to determine it's own information
    """
    def __init__(self, pid):
        self.pid = int(pid)
        self.parser = ProcParser("/proc/{0}/status".format(self.pid))
        self._from_file()

    def _from_file(self):
        self.uid = self.parser.get_by_val("Uid")[1]
        self.gid = self.parser.get_by_val("Gid")[1]
        self.name = self.parser.get_by_val("Name")[1]
        self.user = pwd.getpwuid(int(self.uid)).pw_name
        self.group = grp.getgrgid(int(self.gid)).gr_name

class ProcTree:
    "A tree that displays all running processes"
    def __init__(self):
        self.view = gtk.ScrolledWindow()
        self.store = gtk.ListStore(str, int, str, str)
        self.tree = gtk.TreeView(self.store)
        self.cells = [
            gtk.CellRendererText(),
            gtk.CellRendererText(),
            gtk.CellRendererText(),
            gtk.CellRendererText()
        ]
        self.tvcols = [
            gtk.TreeViewColumn("Name"),
            gtk.TreeViewColumn("Pid"),
            gtk.TreeViewColumn("User"),
            gtk.TreeViewColumn("Group")
        ]

    def __call__(self):
        return self.view

    def config(self):
        for col, cell in zip(self.tvcols, self.cells):
            col.pack_start(cell, True)
            col.add_attribute(cell, "text", 0)
            self.tree.append_column(col)
        self._update_store()
        self.view.add_with_viewport(self.tree)

    def show(self):
        self.tree.show()
        self.view.show()

    def _update_store(self):
        self.store.clear()
        for item in os.listdir("/proc"):
            try: pwid = int(item)
            except: continue
            pr = Proc(pwid)
            self.store.append((pr.name, int(pr.pid), pr.user, pr.group))

class Window:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.proctree = ProcTree()

    def config(self):
        self.proctree.config()
        self.window.add(self.proctree())
        self.window.set_title("Process Viewer")

    def show(self):
        self.proctree.show()
        self.window.show()

    def run(self):
        self.config()
        self.show()

win = Window()
win.run()
gtk.main()

My issue is that all of the columns’ values are the same.

Notes:

  1. Apparently this is correlated with the first column (ie If I change the first column’s data, then that’s what all of the other data become)

(Will add more as suggestions are posted)

  • 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-16T10:07:24+00:00Added an answer on May 16, 2026 at 10:07 am

    for append on treview you should do

        rendererText = gtk.CellRendererText()
        tvcols = ["Name", "Pid", "User", "Group"]
    
        for num, name in enumerate(tvcols):
            column_name = gtk.TreeViewColumn(name ,rendererText, text=num)
            self.tree.append_column(column_name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote simple class that on the start it just increase the value of
I wrote a simple plugin which sets some css code using wp_options. It all
I wrote simple script test echo hello #<-- inside test if I press one
I wrote simple GUI page: public class Test01 { RootPanel r = RootPanel.get(); public
For get device id in android sdk i wrote simple This code :: import
I wrote simple application that send some data to my server. Somehow the data
I wrote simple class in JS witch works, but i had problem when i
I wrote simple console script for scraping with capybara (selenium driver) but doesn't want
Using some tutorials I wrote simple widget but it causes error declare customwidget.TestDijit: mixin
I wrote a simple batch file as a PowerShell script, and I am getting

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.