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

  • SEARCH
  • Home
  • 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 4024854
In Process

The Archive Base Latest Questions

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

I’m trying to create a custom ComboBox that behaves like the one in here:

  • 0

I’m trying to create a custom ComboBox that behaves like the one in here: http://chir.ag/projects/name-that-color/

I’ve got two problems right now:

  1. I can’t seem to find a way to have a scrollbar on the side; the gtk.rc_parse_string function should do that, since the ComboBox widget has a “appears-as-list” style property, but my custom widget seems unaffected for some reason.

  2. When you select a color from my widget, then click the ComboBox again, instead of showing the selected item and its neighbours, the scrolled window starts from the top, for no apparent reason.

This is the code, you can pretty much ignore the __load_name_palette method. You need the /usr/share/X11/rgb.txt file to run this code, it looks like this: http://pastebin.com/raw.php?i=dkemmEdr

import gtk
import gobject
from os.path import exists

def window_delete_event(*args):
   return False

def window_destroy(*args):
    gtk.main_quit()

class ColorName(gtk.ComboBox):
    colors = []
    def __init__(self, name_palette_path, wrap_width=1):
        gtk.ComboBox.__init__(self)
        liststore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING,
                                 gobject.TYPE_STRING)
        name_palette = self.__load_name_palette(name_palette_path)
        for c in name_palette:
            r, g, b, name = c
            if ((r + g + b) / 3.) < 128.:
                fg = '#DDDDDD'
            else:
                fg = '#222222'
            bg = "#%02X%02X%02X" % (r, g, b)
            liststore.append((name, bg, fg))

        self.set_model(liststore)
        label = gtk.CellRendererText()
        self.pack_start(label, True)
        self.set_attributes(label, background=1, foreground=2, text=0)
        self.set_wrap_width(wrap_width)

        if len(name_palette) > 0:
            self.set_active(0)
        self.show_all()

    def __load_name_palette(self, name_palette_path):
        if exists(name_palette_path):
            try:
                f = open(name_palette_path,'r')
                self.colors = []
                palette = set()
                for l in f:
                    foo = l.rstrip().split(None,3)
                    try:
                        rgb = [int(x) for x in foo[:3]]
                        name, = foo[3:]
                    except:
                        continue
                    k = ':'.join(foo[:3])
                    if k not in palette:
                        palette.add(k)
                        self.colors.append(rgb + [name])
                f.close()
                return self.colors
            except IOError as (errno, strerror):
                print "error: failed to open {0}: {1}".format(name_palette_path, strerror)
                return []
            else:
                return []

if __name__ == '__main__':
    win = gtk.Window()
    #colname = ColorName('./ntc.txt')
    colname = ColorName('/usr/share/X11/rgb.txt')
    gtk.rc_parse_string("""style "mystyle" { GtkComboBox::appears-as-list = 1 }
    class "GtkComboBox" style "mystyle" """)
    print 'appears-as-list:', colname.style_get_property('appears-as-list')
    model = gtk.ListStore(gobject.TYPE_STRING)
    hbox = gtk.HBox()
    win.add(hbox)
    hbox.pack_start(colname)
    win.connect('delete-event', window_delete_event)
    win.connect('destroy', window_destroy)
    win.show_all()
    gtk.main()
  • 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-20T10:46:25+00:00Added an answer on May 20, 2026 at 10:46 am

    The problem was the self.show_all() line. Also, you can’t have a list AND a wrap_width != 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.