views:

33

answers:

0

Hello! I write the simple example with gtk.FileChooserDialog. It works fine, but there is one problem under WIndows: I see '\' in first button instead of real drive names, such as 'C:\', 'D:\' and so on. I explored FileChooserDialog structure and tried to change '\' by real drive name, but it works unstable. Can anybody help me?

import os
import gtk

def on_folder_change(widget):
    buttons = []
    find_widget(widget, 'GtkPathBar', buttons)
    if buttons:
        try:
            buttons[-1].set_label(os.path.splitdrive( \
                chooser.get_current_folder())[0] + '\\')
        except:
            pass


def find_widget(widget, widget_name, widgets):
    if widgets:
        return
    if hasattr(widget, 'get_children'):
        children = widget.get_children()
    if (widget.get_name() == widget_name) and (widget_name == 'GtkFileChooserDefault'):
        widgets.append(widget)
        return
    elif widget.get_name() == widget_name and widget_name == 'GtkPathBar':
        for widget in children:
            if type(widget) == gtk.ToggleButton:
                widgets.append(widget)
        return
    else:
        for child in children:
            find_widget(child, widget_name, widgets)



chooser = gtk.FileChooserDialog("My dialog", None,
    gtk.DIALOG_MODAL, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
    gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

# find GtkFileChooserDefault widget
widgets = []
find_widget(chooser, 'GtkFileChooserDefault', widgets)
widgets[0].connect('selection-changed', on_folder_change)

chooser.run()