Beispiel #1
0
    def _parse_custom_widget(self, widget_name, node):
        """Parse a widget changing its property types"""
        for child in node.childNodes:
            if child.nodeType != child.ELEMENT_NODE:
                continue

            if child.nodeName == 'property':
                prop_name = str(child.getAttribute('name'))
                full_name = '%s::%s' % (widget_name, prop_name)
                attrs = {}
                for i in range(child.attributes.length):
                    attr = child.attributes.item(i)
                    name = str(attr.name)
                    value = attr.value
                    if name == 'name':
                        continue

                    if name == 'default':
                        value = _valuefromstring(widget_name, prop_name, value)

                    elif name in ('readable', 'writable', 'enabled',
                                  'translatable', 'editable'):
                        value = str2bool(value)

                    elif name == 'priority':
                        value = int(value)

                    else:
                        print 'Customization of attribute %s is not supported' % name
                        continue

                    attrs[str(attr.name)] = value

                if 'default' in attrs.keys():
                    attrs['has_custom_default'] = True

                prop_registry.override_simple(full_name, **attrs)

            else:
                print 'Unknown node: %s' % child.nodeName
Beispiel #2
0
def register_widgets():
    for gobj, editor, data_type in [
        (ProxyEntry, EntryDataType, DataType),
        (ProxyDateEntry, None, DateOnlyDataType),
        (ProxyButton, ButtonDataType, DataType),
        (ProxyColorButton, ButtonDataType, DataType),
        (ProxyCheckButton, None, BoolOnlyDataType),
        (ProxyLabel, LabelDataType, DataType),
        (ProxyComboBox, ComboBoxDataType, DataType),
        (ProxyComboBoxEntry, ComboBoxEntryDataType, DataType),
        (ProxyComboEntry, ComboEntryDataType, DataType),
        (ProxySpinButton, SpinBtnDataType, DataType),
        (ProxyHScale, HScaleDataType, DataType),
        (ProxyVScale, VScaleDataType, DataType),
        (ProxyRadioButton, None, BoolOnlyDataType),
        (ProxyTextView, TextViewDataType, DataType)
    ]:
        # Property overrides, used in the editor
        type_name = gobject.type_name(gobj)

        data_name = type_name + '::data-type'
        if editor:
            prop_registry.override_simple(data_name,
                                          data_type,
                                          custom_editor=editor)
        else:
            prop_registry.override_simple(data_name, data_type)

        prop_registry.override_simple(type_name + '::model-attribute',
                                      ModelProperty)

        if issubclass(gobj, ProxyRadioButton):
            prop_registry.override_simple(type_name + '::data-value',
                                          DataValueProperty)
        # Register custom adapters, since gobject.new is broken in 2.6
        # Used by loader, eg in gazpacho and in applications
        # ComboBox is registered above
        if gobj == ProxyComboBox:
            continue

        adapter_name = 'Kiwi%sAdapter' % gobj.__name__
        klass = type(adapter_name, (PythonWidgetAdapter, ),
                     dict(object_type=gobj, __name__=adapter_name))
        adapter_registry.register_adapter(klass)
Beispiel #3
0
def register_widgets():
    for gobj, editor, data_type in [
        (ProxyEntry, EntryDataType, DataType),
        (ProxyDateEntry, None, DateOnlyDataType),
        (ProxyButton, ButtonDataType, DataType),
        (ProxyColorButton, ButtonDataType, DataType),
        (ProxyCheckButton, None, BoolOnlyDataType),
        (ProxyLabel, LabelDataType, DataType),
        (ProxyComboBox, ComboBoxDataType, DataType),
        (ProxyComboBoxEntry, ComboBoxEntryDataType, DataType),
        (ProxyComboEntry, ComboEntryDataType, DataType),
        (ProxySpinButton, SpinBtnDataType, DataType),
        (ProxyHScale, HScaleDataType, DataType),
        (ProxyVScale, VScaleDataType, DataType),
        (ProxyRadioButton, None, BoolOnlyDataType),
        (ProxyTextView, TextViewDataType, DataType)
        ]:
        # Property overrides, used in the editor
        type_name = gobject.type_name(gobj)

        data_name = type_name + '::data-type'
        if editor:
            prop_registry.override_simple(data_name, data_type, custom_editor=editor)
        else:
            prop_registry.override_simple(data_name, data_type)

        prop_registry.override_simple(type_name + '::model-attribute',
                                      ModelProperty)

        if issubclass(gobj, ProxyRadioButton):
            prop_registry.override_simple(type_name + '::data-value',
                                          DataValueProperty)
        # Register custom adapters, since gobject.new is broken in 2.6
        # Used by loader, eg in gazpacho and in applications
        # ComboBox is registered above
        if gobj == ProxyComboBox:
            continue

        adapter_name = 'Kiwi%sAdapter' % gobj.__name__
        klass = type(adapter_name, (PythonWidgetAdapter,),
                     dict(object_type=gobj,
                          __name__=adapter_name))
        adapter_registry.register_adapter(klass)
Beispiel #4
0
    def _init_property_meta_data(self, dialog):
        """
        Set the metadata for some of the properties. This should not
        set default values of the properties since that is not always
        what we want.
        """
        # XXX not sure if we can assume that there actually is a vbox
        # and an action_area here?

        vbox = Gadget.from_widget(dialog.vbox)
        if vbox:
            vbox.get_prop('border-width').editable = False

        action_area = Gadget.from_widget(dialog.action_area)
        if action_area:
            action_area.get_prop('border-width').editable = False
            action_area.get_prop('spacing').editable = False

    def load(self, context, widget):
        gadget = super(WindowAdaptor, self).load(context, widget)
        self._init_property_meta_data(widget)
        return gadget

class MessageDialogAdaptor(DialogAdaptor):
    def post_create(self, context, dialog, interactive=True):
        dialog.set_default_size(400, 115)

# GtkDialog
prop_registry.override_simple('GtkDialog::has-separator', default=False)

Beispiel #5
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

from gazpacho.properties import prop_registry, CustomProperty, \
     ProxiedProperty, AdjustmentType, FloatType, IntType

class SpinAdjustmentType(AdjustmentType):
    def __init__(self, gobj):
        super(AdjustmentType, self).__init__(gobj)
        # Initialize us to the value fetch from the loader
        self._value = gobj.widget.get_adjustment()

prop_registry.override_simple('GtkSpinButton::adjustment', SpinAdjustmentType)

# Value is never saved, because it's already saved as the first item in the
# adjustment. Infact get_property in gtkspinbutton.c just returns
# spinbutton->adjustment->value, so it makes sense to ignore it.
class Value(CustomProperty):
    def save(self):
        pass
prop_registry.override_simple('GtkSpinButton::value', Value)

class AdjustmentProxy(ProxiedProperty):
    def get_target(self):
        return self.object.get_adjustment()

    def save(self):
        # Not saving, they're saved in GtkSpinButton::adjustment instead
Beispiel #6
0
from gazpacho.properties import prop_registry, TransparentProperty, EnumType, \
     CustomProperty
from gazpacho.widgets.base.base import ContainerAdaptor, ObjectDataProp

class WindowAdaptor(ContainerAdaptor):
    def create(self, context, interactive=True):
        window = super(WindowAdaptor, self).create(context, interactive)
        window.set_default_size(440, 250)
        return window

class TypeHintProperty(CustomProperty, EnumType):
    def get(self):
        value = self.object.get_data('gazpacho::type-hint')
        return value or gtk.gdk.WINDOW_TYPE_HINT_NORMAL

    def set(self, value):
        self.object.set_data('gazpacho::type-hint', value)

prop_registry.override_simple('GtkWindow::modal', ObjectDataProp,
                              qdata='gazpacho::modal')

prop_registry.override_simple('GtkWindow::type-hint', TypeHintProperty)

prop_registry.override_simple('GtkWindow::default-width',
                              minimum=-1, maximum=10000)
prop_registry.override_simple('GtkWindow::default-height',
                              minimum=-1, maximum=10000)
prop_registry.override_simple('GtkWindow::type', TransparentProperty,
                              editable=False)
prop_registry.override_simple('GtkWindow::role', translatable=False)
Beispiel #7
0
                #print load_gadget_from_widget(label, project)
                no = self.object.append_page(
                    Placeholder(), label)
                label.set_text('Page %d' % (no + 1))
                #project.add_widget(label)
                old_size += 1
        else:
            # The notebook has shrunk. Remove pages

            # Thing to remember is that GtkNotebook starts the
            # page numbers from 0, not 1 (C-style). So we need to do
            # old_size-1, where we're referring to "nth" widget.
            while old_size > new_size:
                child_widget = self.object.get_nth_page(old_size - 1)
                child_gadget = Gadget.from_widget(child_widget)
                # If we got it, and it's not a placeholder, remove it
                # from the project
                if child_gadget:
                    self._project.remove_widget(child_widget)

                self.object.remove_page(old_size - 1)
                old_size -= 1

prop_registry.override_property('GtkNotebook::n-pages', NPagesProp)

# Do not save property, since we need loader support since
# Gtk+ ignores the value of the property.
prop_registry.override_simple('GtkNotebook::page', persistent=False)

Beispiel #8
0
# XXX: This is too complex, fix properties API
#      TransparentProperty doesn't work, why?
class Items(CustomProperty, StringType):
    label = 'Items'
    default = ''
    def load(self):
        model = self.object.get_model()
        if not model:
            # Hack warning, only needed for GtkComboBoxEntry
            model = gtk.ListStore(str)
            self.object.set_model(model)
        self._value = '\n'.join([row[0] for row in model])
        self._initial = self.default

    def get(self):
        return self._value

    def set(self, value):
        self._value = value
        combobox_set_content_from_string(self.object, value)
prop_registry.override_property('GtkComboBox::items', Items)

# These properties are buggy in GTK+ 2.4
prop_registry.override_simple('GtkComboBox::column-span-column', editable=False)
prop_registry.override_simple('GtkComboBox::row-span-column', editable=False)

# GtkComboBoxEntry
prop_registry.override_simple('GtkComboBoxEntry::text-column', default=0)

Beispiel #9
0
    def get_widgets(self):
        return self._tree.get_widgets()

    def signal_autoconnect(self, dic):
        self._tree.signal_autoconnect(dic)

    def get_sizegroups(self):
        return self._tree.sizegroups


# Normal widgets
for prop in ('normal-color', 'normal-underline', 'normal-bold', 'hover-color',
             'hover-underline', 'hover-bold', 'active-color',
             'active-underline', 'active-bold'):
    prop_registry.override_simple('HyperLink::%s' % prop, editable=False)


class HyperLinkAdaptor(ContainerAdaptor):
    def fill_empty(self, context, widget):
        pass

    def post_create(self, context, widget, interactive):
        widget.set_text(widget.get_name())


class ComboEntryAdaptor(BoxAdaptor):
    def get_children(self, context, comboentry):
        return []

Beispiel #10
0
        return ""

    def load(self):
        value = super(FileProp, self).load()
        self._initial = value
        self.set(value)

    def get(self):
        return self.object.get_data('image-file-name')

    def set(self, value):
        if value:
            self.object.set_data('image-file-name', value)
            self.object.set_property('file', value)

    def save(self):
        return self.get()

prop_registry.override_simple('GtkImage::file', FileProp)

class StockProp(CustomProperty, StringType):
    default = "gtk-missing-image"
    translatable = False
    editor = EditorPropertyStock
    def save(self):
        if self.object.get_data('image-file-name'):
            return
        return super(StockProp, self).save()

prop_registry.override_simple('GtkImage::stock', StockProp)
Beispiel #11
0
                    return

            # and then remove widgets
            child = self.object.get_children()[-1]
            while old_size > new_size and child:
                gadget = Gadget.from_widget(child)
                if gadget: # It may be None, e.g a placeholder
                    gadget.project.remove_widget(child)

                gtk.Container.remove(self.object, child)
                child = self.object.get_children()[-1]
                old_size -= 1
        self.notify()

prop_registry.override_property('GtkBox::size', BoxSizeProp)
prop_registry.override_simple('GtkBox::spacing', minimum=0)

class AppendGadgetCommand(Command):
    """
    Command for adding a widget to a box. This command isn't inteded
    to be used directly but to be subclasses by other commands.
    """

    def __init__(self, source_gadget, box, pos, description=None):
        """
        Initialize the command. Note that the source_gadget has to be
        a new widget that is not already in use in the project.

        @param source_gadget: the widget that is to be inserted
        @type source_gadget: L{gazpacho.gadget.Gadget}
        @param box: the box into which the widget should be inserted
Beispiel #12
0
# Copyright (C) 2004,2005 by SICEm S.L. and Imendio AB
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

from gazpacho.properties import prop_registry, CustomProperty, BooleanType

class HasResizeGripProp(CustomProperty, BooleanType):
    label = "Has Resize Grip"
    default = True
    def get(self):
        return self.object.get_has_resize_grip()

    def set(self, value):
        self.object.set_has_resize_grip(value)

prop_registry.override_simple('GtkStatusbar::has-resize-grip',
                              HasResizeGripProp)

Beispiel #13
0
            if col is column.widget:
                return i

    def get_model(self, tree_view):
        return GazpachoModel.from_model(tree_view.widget.get_model())

    def delete(self, context, widget):        
        model = GazpachoModel.from_model(widget.get_model())
        context.get_project().model_manager.remove_model(model)
        return model

    def restore(self, context, widget, model):
        context.get_project().model_manager.add_model(model)

# Disable headers-clickable, see bug #163851
prop_registry.override_simple('GtkTreeView::headers-clickable', enabled=False)

class ModelPropEditor(PropertyCustomEditorWithDialog):
    dialog_class = ModelEditorDialog
    button_text = _('Edit Model...')

class ModelAdaptor(CustomProperty, StringType):
    """This represents a fake property to edit the model of a TreeView"""
    custom_editor = ModelPropEditor
    translatable = False

    def get(self):
        model = self.object.get_model()
        if model:
            gzmodel = GazpachoModel.from_model(model)
            return gzmodel.get_name()
Beispiel #14
0
        return widget

    def get_widgets(self):
        return self._tree.get_widgets()

    def signal_autoconnect(self, dic):
        self._tree.signal_autoconnect(dic)

    def get_sizegroups(self):
        return self._tree.sizegroups

# Normal widgets
for prop in ('normal-color', 'normal-underline', 'normal-bold',
             'hover-color', 'hover-underline', 'hover-bold',
             'active-color', 'active-underline', 'active-bold'):
    prop_registry.override_simple('HyperLink::%s' % prop, editable=False)

class HyperLinkAdaptor(ContainerAdaptor):
    def fill_empty(self, context, widget):
        pass

    def post_create(self, context, widget, interactive):
        widget.set_text(widget.get_name())

class ComboEntryAdaptor(BoxAdaptor):
    def get_children(self, context, comboentry):
        return []

class DateEntryAdaptor(BoxAdaptor):
    def get_children(self, context, comboentry):
        return []
Beispiel #15
0
                                (w - fontw) / 2,
                                (h - fonth) / 2,
                                self._layout)
        return False

# Adapter
class CustomAdaptor(WidgetAdaptor):
    type = Custom
    name = 'Custom'

# Loader
class CustomLoaderAdapter(LoaderAdapter):
    object_type = Custom
    def construct(self, name, gtype, properties):
        return Custom()
adapter_registry.register_adapter(CustomLoaderAdapter)

CUSTOM_TYPE = 'gazpacho+widgets+base+custom+Custom'
prop_registry.override_simple(CUSTOM_TYPE + '::int1',
                              translatable=False, minimum=-1)
prop_registry.override_simple(CUSTOM_TYPE + '::int2',
                              translatable=False, minimum=-1)
prop_registry.override_simple(CUSTOM_TYPE + '::string1',
                              translatable=False)
prop_registry.override_simple(CUSTOM_TYPE + '::string2',
                              translatable=False)
prop_registry.override_simple(CUSTOM_TYPE + '::creation-function',
                              translatable=False)
prop_registry.override_simple(CUSTOM_TYPE + '::last-modification-time',
                              translatable=False, editable=False)