コード例 #1
0
    def on_preferences_saved(self, event=None):
        # Setup ttk theme if changed
        theme = pref.get_option('ttk_theme')
        self._change_ttk_theme(theme)

        # Get the preferred default layout manager, in case it has changed.
        self.tree_editor.default_layout_manager = pref.get_option(
            'default_layout_manager')
コード例 #2
0
 def _generate_id(self, classname, index):
     class_base_name = classname.split('.')[-1]
     name = class_base_name
     name = '{0}{1}'.format(name, index)
     if pref.get_option('widget_naming_separator') == 'UNDERSCORE':
         name = '{0}_{1}'.format(name, index)
     name = name.lower()
     if pref.get_option('widget_naming_ufletter') == 'yes':
         name = name.capitalize()
     return name
コード例 #3
0
 def setup_app_preferences(self):
     # Restore windows position and size
     geom = pref.get_window_size()
     self.mainwindow.geometry(geom)
     # Load preferred ttk theme
     theme = pref.get_option('ttk_theme')
     self._change_ttk_theme(theme)
コード例 #4
0
    def get_ttk_style_definitions(cls):
        contents = None
        style_definition_path = pref.get_option('v_style_definition_file')

        if path.isfile(style_definition_path):
            with open(style_definition_path) as f:
                contents = f.read()
        return contents
コード例 #5
0
ファイル: main.py プロジェクト: OscarZunigaLara/electricidad
    def create_treeview_widget_list(self, treelist):
        # sbhelper widget
        sbhelper = ScrollbarHelper(self.widgetlist, scrolltype='both')

        # widgetlisttv widget
        widgetlisttv = ttk.Treeview(sbhelper)
        widgetlisttv.configure(selectmode='browse', show='tree')
        widgetlisttv.grid(column='0', row='0', sticky='nsew')

        sbhelper.add_child(widgetlisttv)
        sbhelper.configure(usemousewheel='true')
        sbhelper.grid(column='0', row='0', sticky='nsew')

        #Default widget image:
        default_image = ''
        try:
            default_image = StockImage.get('22x22-tk.default')
        except StockImageException as e:
            pass

        #Start building widget tree selector
        roots = {}
        sections = {}
        for key, wc in treelist:
            root, section = key.split('>')
            #insert root
            if root not in roots:
                roots[root] = widgetlisttv.insert('', 'end', text=root)
            #insert section
            if key not in sections:
                sections[key] = widgetlisttv.insert(roots[root],
                                                    'end',
                                                    text=section)
            #insert widget
            w_image = default_image
            try:
                w_image = StockImage.get('22x22-{0}'.format(wc.classname))
            except StockImageException as e:
                pass

            widgetlisttv.insert(sections[key],
                                'end',
                                text=wc.label,
                                image=w_image,
                                tags='widget',
                                values=(wc.classname, ))
        widgetlisttv.tag_bind('widget', '<Double-1>',
                              self.on_widgetlist_dclick)

        #Expand prefered widget set
        hidews = 'tk'
        prefws = get_option('widget_set')
        if hidews == prefws:
            hidews = 'ttk'
        widgetlisttv.item(roots[hidews], open=False)
        widgetlisttv.item(roots[prefws], open=True)
        for child in widgetlisttv.get_children(roots[prefws]):
            widgetlisttv.item(child, open=True)
コード例 #6
0
    def get_ttk_style_definitions(cls):
        contents = None
        style_definition_path = Path(
            pref.get_option('v_style_definition_file'))

        if style_definition_path.is_file():
            with style_definition_path.open() as f:
                contents = f.read()
        return contents
コード例 #7
0
ファイル: main.py プロジェクト: OscarZunigaLara/electricidad
    def create_accordion_widget_list(self, treelist):
        acf = AccordionFrame(self.widgetlist)
        acf.grid(sticky=tk.NSEW)
        acf.bind('<<AccordionGroupToggle>>', self.on_widgetlist_group_toogle)

        #Default widget image:
        default_image = ''
        try:
            default_image = StockImage.get('22x22-tk.default')
        except StockImageException as e:
            pass

        #Start building widget tree selector
        roots = {}
        sections = {}
        for key, wc in treelist:
            root, section = key.split('>')
            #insert root
            if root not in roots:
                roots[root] = acf.add_group(root, root)
            #insert section
            if key not in sections:
                sectionacf = AccordionFrame(roots[root])
                sectionacf.grid(sticky=tk.NSEW, padx='5 0')
                sectionacf.bind('<<AccordionGroupToggle>>',
                                self.on_widgetlist_group_toogle)
                sectiongrp = sectionacf.add_group(key, section)
                sections[key] = AutoArrangeFrame(sectiongrp)
                sections[key].grid(sticky=tk.NSEW)

            #insert widget
            w_image = default_image
            try:
                w_image = StockImage.get('22x22-{0}'.format(wc.classname))
            except StockImageException as e:
                pass

            #define callback for button
            def create_cb(cname):
                return lambda: self.on_add_widget_event(cname)

            b = ttk.Button(sections[key],
                           text=wc.label,
                           image=w_image,
                           style='Toolbutton',
                           command=create_cb(wc.classname))
            tooltip.create(b, wc.classname)
            b.grid()

        #Expand prefered widget set
        hidews = 'tk'
        prefws = get_option('widget_set')
        if hidews == prefws:
            hidews = 'ttk'
        acf.group_toogle(hidews)
        self.widgetlist_sf.reposition()
コード例 #8
0
 def _should_center_preview_window(self) -> bool:
     """
     Check whether the option has been enabled to center
     the preview window or not.
     :return: bool (True if we should center the preview window, otherwise False)
     """
     self.tree_editor.center_preview = pref.get_option("center_preview")
     if self.tree_editor.center_preview == "yes":
         return True
     else:
         return False
コード例 #9
0
    def _setup_theme_menu(self):
        menu = self.builder.get_object('preview_themes_submenu')
        s = ttk.Style()
        styles = s.theme_names()
        self.__theme_var = var = tk.StringVar()
        theme = pref.get_option('ttk_theme')
        var.set(theme)

        for name in styles:

            def handler(theme=name):
                self._change_ttk_theme(theme)

            menu.add_radiobutton(label=name,
                                 value=name,
                                 variable=self.__theme_var,
                                 command=handler)
コード例 #10
0
    def check_definition_file(self, force_reload=False):
        # print('checking definitions')
        # Get the path to the style definition file.
        style_definition_path = Path(
            pref.get_option('v_style_definition_file'))

        do_reload = False
        has_definition_file = False
        is_new_file = False
        if style_definition_path.is_file():
            has_definition_file = True
            file_mtime = style_definition_path.stat().st_mtime
            if StyleHandler.last_definition_file != style_definition_path:
                do_reload = True
                is_new_file = True
                StyleHandler.last_definition_file = style_definition_path
                StyleHandler.last_modified_time = file_mtime
            if not is_new_file:
                if file_mtime > StyleHandler.last_modified_time:
                    do_reload = True
                    StyleHandler.last_modified_time = file_mtime
        if do_reload or (has_definition_file and force_reload):
            contents = None
            with style_definition_path.open() as f:
                contents = f.read()

            # Clear and reload all the definitions.

            # Reason: so that definitions that are no longer in the definition file
            # will no longer populate in the style combobox.
            StyleRegister.STYLE_DEFINITIONS.clear()

            self._apply_ttk_styles(contents)

            # Re-select the selected item so the style combobox
            # will show the latest styles from the definition file.
            if self.reselect_item_func is not None:
                self.reselect_item_func()

        # schedule new check
        self.after_token = self.mframe.after(1000, self.check_definition_file)
コード例 #11
0
    def create_component_palette(self, fpalette):
        #Default widget image:
        default_image = ''
        try:
            default_image = StockImage.get('22x22-tk.default')
        except StockImageException as e:
            pass

        treelist = self.create_treelist()
        self._pallete = ComponentPalette(fpalette)

        #Start building widget tree selector
        roots = {}
        sections = {}
        for key, wc in treelist:
            root, section = key.split('>')
            if section not in sections:
                roots[root] = self._pallete.add_tab(section, section)
                sections[section] = 1

            #insert widget
            w_image = default_image
            try:
                w_image = StockImage.get('22x22-{0}'.format(wc.classname))
            except StockImageException as e:
                pass

            #define callback for button
            def create_cb(cname):
                return lambda: self.on_add_widget_event(cname)

            wlabel = wc.label
            if wlabel.startswith('Menuitem.'):
                wlabel = wlabel.replace('Menuitem.', '')
            callback = create_cb(wc.classname)
            self._pallete.add_button(section, root, wlabel, wc.classname,
                                     w_image, callback)
        default_group = get_option('widget_set')
        self._pallete.show_group(default_group)
コード例 #12
0
ファイル: main.py プロジェクト: OscarZunigaLara/electricidad
 def configure_widget_list(self):
     treelist = self.create_treelist()
     if get_option('widget_palette') == 'accordion':
         self.create_accordion_widget_list(treelist)
     else:
         self.create_treeview_widget_list(treelist)
コード例 #13
0
 def on_preferences_saved(self, event=None):
     # Setup ttk theme if changed
     theme = pref.get_option('ttk_theme')
     self._change_ttk_theme(theme)
コード例 #14
0
    def __init__(self, app):
        self.app = app
        self.treeview = app.treeview
        self.previewer = app.previewer
        self.treedata = {}
        self.counter = Counter()
        self.virtual_clipboard_for_duplicate = None
        self.duplicating = False
        self.duplicate_parent_iid = None

        # Get the default layout manager based on the user's configuration.
        self.__preferred_layout_manager_var = tk.StringVar()
        current_default_layout = pref.get_option('default_layout_manager')
        if not current_default_layout:
            self.__preferred_layout_manager_var.set("pack")
        else:
            self.__preferred_layout_manager_var.set(current_default_layout)

        # Set the default layout manager
        self.default_layout_manager = self.__preferred_layout_manager_var.get()

        # Filter vars
        self.filter_on = False
        self.filtervar = app.builder.get_variable('filtervar')
        self.filter_btn = app.builder.get_object('filterclear_btn')
        self.filter_prev_value = ''
        self.filter_prev_sitem = None
        self._detached = []
        self._listen_object_updates = True

        self.config_treeview()
        self.config_filter()

        # current item being edited
        self.current_edit = None

        # Widget Editor
        pframe = app.builder.get_object('propertiesframe')
        lframe = app.builder.get_object('layoutframe')
        bframe = app.builder.get_object('bindingsframe')
        bindingstree = app.builder.get_object('bindingstree')
        self.properties_editor = PropertiesEditor(
            pframe,
            id_validator=self.is_id_unique,
            reselect_item_func=partial(self.on_treeview_select, None))
        self.layout_editor = LayoutEditor(lframe)
        self.bindings_editor = BindingsEditor(bindingstree, bframe)
        self.treeview.bind_all('<<PreviewItemSelected>>',
                               self._on_preview_item_clicked)
        f = lambda e, manager='grid': self.change_container_manager(manager)
        lframe.bind_all('<<LayoutEditorContainerManagerToGrid>>', f)
        f = lambda e, manager='pack': self.change_container_manager(manager)
        lframe.bind_all('<<LayoutEditorContainerManagerToPack>>', f)

        # Tree Editing
        tree = self.treeview
        tree.bind_all(TREE_ITEM_COPY, lambda e: self.copy_to_clipboard())
        tree.bind_all(TREE_ITEM_PASTE, lambda e: self.paste_from_clipboard())
        tree.bind_all(TREE_ITEM_CUT, lambda e: self.cut_to_clipboard())
        tree.bind_all(TREE_ITEM_DELETE, self.on_tree_item_delete)
        tree.bind_all(TREE_ITEM_DUPLICATE, self.on_tree_item_duplicate)
        tree.bind_all(TREE_ITEM_GRID_DOWN,
                      lambda e: self.on_item_grid_move(self.GRID_DOWN))
        tree.bind_all(TREE_ITEM_GRID_LEFT,
                      lambda e: self.on_item_grid_move(self.GRID_LEFT))
        tree.bind_all(TREE_ITEM_GRID_RIGHT,
                      lambda e: self.on_item_grid_move(self.GRID_RIGHT))
        tree.bind_all(TREE_ITEM_GRID_UP,
                      lambda e: self.on_item_grid_move(self.GRID_UP))
        tree.bind_all(TREE_ITEM_MOVE_UP, self.on_item_move_up)
        tree.bind_all(TREE_ITEM_MOVE_DOWN, self.on_item_move_down)
        tree.bind_all(TREE_NAV_UP, self.on_item_nav_up)
        tree.bind_all(TREE_NAV_DOWN, self.on_item_nav_down)
        tree.bind_all(TREE_ITEM_PREVIEW_TOPLEVEL, self.on_preview_in_toplevel)