How to use the pygubu.builder.CLASS_MAP function in pygubu

To help you get started, we’ve selected a few pygubu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alejandroautalan / pygubu / pygubudesigner / widgeteditor.py View on Github external
if parent != root:
                if self._validate_add(parent, wclass):
                    root = parent
                else:
                    return
            else:
                return

        #root item should be set at this point
        #setup properties
        widget_id = self.get_unique_id(wclass)

        data = WidgetDescr(wclass, widget_id)

        #setup default values for properties
        for pname in builder.CLASS_MAP[wclass].classobj.properties:
            pdescription = {}
            pgroup = properties.GROUP_WIDGET
            if pname in properties.PropertiesMap[pgroup]:
                pdescription = properties.PropertiesMap[pgroup][pname]
            else:
                pgroup = properties.GROUP_CUSTOM
                pdescription = properties.PropertiesMap[pgroup][pname]
            if wclass in pdescription:
                pdescription = dict(pdescription, **pdescription[wclass])
            default_value = str(pdescription.get('default', ''))
            data.set_property(pname, default_value)
            #default text for widgets with text prop:
            if pname in ('text', 'label'):
                data.set_property(pname, widget_id)

        #default grid properties
github alejandroautalan / pygubu / pygubudesigner / bindingseditor.py View on Github external
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see .

from __future__ import unicode_literals
try:
    import tkinter as tk
    import tkinter.ttk as ttk
except:
    import Tkinter as tk
    import ttk

from pygubu import builder

CLASS_MAP = builder.CLASS_MAP


class BindingsEditor:
    def __init__(self, etreeview):
        self.tv = etreeview
        self._curr_data = None
        self._adder = 'adder'
        self._allow_edit = False
        self._parent = etreeview.nametowidget(etreeview.winfo_parent())
        self.tv.insert('', tk.END, iid=self._adder, values=('+',))
        self.tv.bind('<>', self._on_inplace_edit)
        self.tv.bind('<>', self._on_cell_edited)
        self.tv.bind('', self._on_add_clicked, add=True)

        self._del_btn = ttk.Button(self.tv, text='-',
                                   command=self._on_del_clicked)
github alejandroautalan / pygubu / pygubudesigner / propertieseditor.py View on Github external
import logging

try:
    import tkinter as tk
    import tkinter.ttk as ttk
except:
    import Tkinter as tk
    import ttk

from pygubu import builder
from pygubudesigner.widgets.propertyeditor import create_editor
from pygubudesigner import properties
from pygubudesigner.i18n import translator as _

logger = logging.getLogger(__name__)
CLASS_MAP = builder.CLASS_MAP


class PropertiesEditor(object):
    def __init__(self, frame):
        self._current = None
        self._sframe = frame
        self._frame = None
        self._propbag = {}
        self._create_properties()
        self.hide_all()

    def _create_properties(self):
        """Populate a frame with a list of all editable properties"""
        self._frame = f = ttk.Labelframe(self._sframe.innerframe,
                                         text=_('Widget properties'))
        f.grid(sticky='nswe')
github alejandroautalan / pygubu / pygubudesigner / main.py View on Github external
def create_treelist(self):
        root_tagset = set(('tk', 'ttk'))

        #create unique tag set
        tagset = set()
        for c in builder.CLASS_MAP.keys():
            wc = builder.CLASS_MAP[c]
            tagset.update(wc.tags)
        tagset.difference_update(root_tagset)

        treelist = []
        for c in builder.CLASS_MAP.keys():
            wc = builder.CLASS_MAP[c]
            ctags = set(wc.tags)
            roots = (root_tagset & ctags)
            sections = (tagset & ctags)
            for r in roots:
                for s in sections:
                    key = '{0}>{1}'.format(r, s)
                    treelist.append((key, wc))

        #sort tags by label
github alejandroautalan / pygubu / pygubudesigner / uitreeeditor.py View on Github external
def _validate_add(self, root_item, classname, show_warnings=True):
        is_valid = True

        new_boclass = builder.CLASS_MAP[classname].builder
        root = root_item
        if root:
            root_classname = self.treedata[root].get_class()
            root_boclass = builder.CLASS_MAP[root_classname].builder
            # print('rootclass:', root_classname)

            allowed_children = root_boclass.allowed_children
            # print('allowed_children:', allowed_children)

            if allowed_children:
                if classname not in allowed_children:
                    str_children = ', '.join(allowed_children)
                    msg = _('Allowed children: {0}.')
                    msg = msg.format(str_children)
                    if show_warnings:
                        logger.warning(msg)
                    is_valid = False
                    return is_valid

            children_count = len(self.treeview.get_children(root))
github alejandroautalan / pygubu / pygubudesigner / layouteditor.py View on Github external
from __future__ import unicode_literals, print_function

try:
    import tkinter as tk
    import tkinter.ttk as ttk
except:
    import Tkinter as tk
    import ttk

from pygubu import builder
from pygubudesigner.widgets.propertyeditor import create_editor
from pygubudesigner import properties
from pygubudesigner.i18n import translator as _
from pygubudesigner.propertieseditor import PropertiesEditor

CLASS_MAP = builder.CLASS_MAP


class LayoutEditor(PropertiesEditor):

    def _create_properties(self):
        """Populate a frame with a list of all editable properties"""
        self._rcbag = {}  # bag for row/column prop editors
        self._fgrid = f = ttk.Labelframe(self._sframe.innerframe,
                                         text=_('Grid options:'), padding=5)
        f.grid(sticky='nswe')
        #  hack to resize correctly when properties are hidden
        label = ttk.Label(f)
        label.grid()

        label_tpl = "{0}:"
        row = 0
github alejandroautalan / pygubu / pygubudesigner / main.py View on Github external
def create_treelist(self):
        root_tagset = set(('tk', 'ttk'))

        #create unique tag set
        tagset = set()
        for c in builder.CLASS_MAP.keys():
            wc = builder.CLASS_MAP[c]
            tagset.update(wc.tags)
        tagset.difference_update(root_tagset)

        treelist = []
        for c in builder.CLASS_MAP.keys():
            wc = builder.CLASS_MAP[c]
            ctags = set(wc.tags)
            roots = (root_tagset & ctags)
            sections = (tagset & ctags)
            for r in roots:
                for s in sections:
                    key = '{0}>{1}'.format(r, s)
                    treelist.append((key, wc))

        #sort tags by label
        def by_label(t):
            return "{0}{1}".format(t[0], t[1].label)
        treelist.sort(key=by_label)
        return treelist