예제 #1
0
    def _insert_item(self, root, data):
        """Insert a item on the treeview and fills columns from data"""

        tree = self.treeview
        treelabel = data.get_id()
        row = col = ''
        if root != '' and 'layout' in data:
            row = data.get_layout_property('row')
            col = data.get_layout_property('column')

            #fix row position when using copy and paste
            #If collision, increase by 1
            row_count = self.get_max_row(root)
            if row_count > int(row) and int(col) == 0:
                row = str(row_count + 1)
                data.set_layout_property('row', row)

        image = ''
        try:
            image = StockImage.get('16x16-tk.default')
        except StockImageException as e:
            pass

        try:
            image = StockImage.get('16x16-{0}'.format(data.get_class()))
        except StockImageException as e:
            pass

        values = (data.get_class(), row, col)
        item = tree.insert(root, 'end', text=treelabel, values=values,
                image=image)
        data.attach(self)
        self.app.set_changed()

        return item
예제 #2
0
    def _setup_styles(self):
        self.mainwindow.option_add('*Dialog.msg.width', 34)
        self.mainwindow.option_add("*Dialog.msg.wrapLength", "6i")

        s = ttk.Style()
        s.configure('ColorSelectorButton.Toolbutton',
                    image=StockImage.get('mglass'))
        s.configure('ImageSelectorButton.Toolbutton',
                    image=StockImage.get('mglass'))
        s.configure('ComponentPalette.Toolbutton', font='TkSmallCaptionFont')
        s.configure('ComponentPalette.TNotebook.Tab',
                    font='TkSmallCaptionFont')
        s.configure('PanelTitle.TLabel',
                    background='#808080',
                    foreground='white',
                    font='TkSmallCaptionFont')
        s.configure('Template.Toolbutton', padding=5)
        # ToolbarFrame scroll buttons
        s.configure(ToolbarFrame.BTN_LEFT_STYLE,
                    image=StockImage.get('arrow-left2'))
        s.configure(ToolbarFrame.BTN_RIGHT_STYLE,
                    image=StockImage.get('arrow-right2'))
        if sys.platform == 'linux':
            #change background of comboboxes
            color = s.lookup('TEntry', 'fieldbackground')
            s.map('TCombobox', fieldbackground=[('readonly', color)])
            s.map('TSpinbox', fieldbackground=[('readonly', color)])
예제 #3
0
파일: main.py 프로젝트: codetestcode/pygubu
 def _setup_styles(self):
     s = ttk.Style()
     s.configure('ColorSelectorButton.Toolbutton', image=StockImage.get('mglass'))
     s.configure('ImageSelectorButton.Toolbutton', image=StockImage.get('mglass'))
     if sys.platform == 'linux':
         #change background of comboboxes
         color = s.lookup('TEntry', 'fieldbackground')
         s.map('TCombobox', fieldbackground=[('readonly', color)])
예제 #4
0
    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)
예제 #5
0
파일: __init__.py 프로젝트: tisttsf/pygubu
 def __load_image(self, path):
     name = os.path.basename(path)
     if not StockImage.is_registered(name):
         ipath = self.__find_image(path)
         if ipath is not None:
             StockImage.register(name, ipath)
         else:
             msg = "Image '%s' not found in resource paths."
             logger.warning(msg, name)
예제 #6
0
 def on_close_execute(self):
     quit = True
     if self.is_changed:
         quit = messagebox.askokcancel(_('File changed'),
                                       _('Changes not saved. Quit anyway?'))
     if quit:
         #prevent tk image errors on python2 ?
         StockImage.clear_cache()
     return quit
예제 #7
0
파일: main.py 프로젝트: codetestcode/pygubu
 def on_close_execute(self):
     quit = True
     if self.is_changed:
         quit = messagebox.askokcancel(_('File changed'),
             _('Changes not saved. Quit anyway?'))
     if quit:
         #prevent tk image errors on python2 ?
         StockImage.clear_cache()
     return quit
예제 #8
0
    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()
예제 #9
0
    def _create_ui(self):
        self._dsize = '12'  # default font size

        self._name = w = ChoicePropertyEditor(self)
        w.grid(row=0, column=0, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)
        w.bind('<<PropertyChanged>>', self._on_fontname_changed, add=True)

        self._optionsframe = container1 = ttk.Frame(self)
        container1.grid(row=1, column=0, sticky='we')

        w = ttk.Label(container1, text='size:', font='TkSmallCaptionFont')
        w.grid(row=0, column=0)
        self._size = w = ChoicePropertyEditor(container1)
        w.parameters(width=4)
        w.grid(row=0, column=1, sticky='w')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        w = ttk.Label(container1, text='style:', font='TkSmallCaptionFont')
        w.grid(row=0, column=2, sticky='w', padx=5)

        self._bold = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-bold')
        w.parameters(
            style='Toolbutton', text='B', image=img, onvalue='bold', offvalue=''
        )
        w.grid(row=0, column=3, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self._italic = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-italic')
        w.parameters(
            style='Toolbutton', text='I', image=img, onvalue='italic', offvalue=''
        )
        w.grid(row=0, column=4, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self._underline = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-underline')
        w.parameters(
            style='Toolbutton', text='U', image=img, onvalue='underline', offvalue=''
        )
        w.grid(row=0, column=5, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self._overstrike = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-strikethrough')
        w.parameters(
            style='Toolbutton', text='S', image=img, onvalue='overstrike', offvalue=''
        )
        w.grid(row=0, column=6, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self.columnconfigure(0, weight=1)
        self._populate_options()
예제 #10
0
 def _setup_styles(self):
     s = ttk.Style()
     s.configure('ColorSelectorButton.Toolbutton',
                 image=StockImage.get('mglass'))
     s.configure('ImageSelectorButton.Toolbutton',
                 image=StockImage.get('mglass'))
     if sys.platform == 'linux':
         #change background of comboboxes
         color = s.lookup('TEntry', 'fieldbackground')
         s.map('TCombobox', fieldbackground=[('readonly', color)])
         s.map('TSpinbox', fieldbackground=[('readonly', color)])
예제 #11
0
    def on_close_execute(self):
        quit = True
        if self.is_changed:
            msg = _('Do you want to save the changes before closing?')
            quit = self.ask_save_changes(msg)
        if quit:
            # prevent tk image errors on python2 ?
            StockImage.clear_cache()

            # Save window size and position
            geom = self.mainwindow.geometry()
            pref.save_window_size(geom)
        return quit
예제 #12
0
파일: fontentry.py 프로젝트: DaZhu/pygubu
    def _create_ui(self):
        self._dsize = '12'  # default font size

        self._name = w = ChoicePropertyEditor(self)
        w.grid(row=0, column=0, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)
        w.bind('<<PropertyChanged>>', self._on_fontname_changed, add=True)

        self._optionsframe = container1 = ttk.Frame(self)
        container1.grid(row=1, column=0, sticky='we')

        w = ttk.Label(container1, text='size:', font='TkSmallCaptionFont')
        w.grid(row=0, column=0)
        self._size = w = ChoicePropertyEditor(container1)
        w.parameters(width=4)
        w.grid(row=0, column=1, sticky='w')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        w = ttk.Label(container1, text='style:', font='TkSmallCaptionFont')
        w.grid(row=0, column=2, sticky='w', padx=5)

        self._bold = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-bold')
        w.parameters(style='Toolbutton', text='B', image=img,
                     onvalue='bold', offvalue='')
        w.grid(row=0, column=3, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self._italic = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-italic')
        w.parameters(style='Toolbutton', text='I', image=img,
                     onvalue='italic', offvalue='')
        w.grid(row=0, column=4, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self._underline = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-underline')
        w.parameters(style='Toolbutton', text='U', image=img,
                     onvalue='underline', offvalue='')
        w.grid(row=0, column=5, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self._overstrike = w = CheckbuttonPropertyEditor(container1)
        img = StockImage.get('format-text-strikethrough')
        w.parameters(style='Toolbutton', text='S', image=img,
                     onvalue='overstrike', offvalue='')
        w.grid(row=0, column=6, sticky='we')
        w.bind('<<PropertyChanged>>', self._on_variable_changed)

        self.columnconfigure(0, weight=1)
        self._populate_options()
예제 #13
0
 def set_app_icon(tk_top_level):
     try:
         tk_top_level.wm_iconname('ezadb')
         tk_top_level.tk.call('wm', 'iconphoto', tk_top_level._w,
                              StockImage.get('ezadb'))
     except StockImageException as e:
         pass
예제 #14
0
파일: __init__.py 프로젝트: torrua/pygubu
 def get_image(self, path):
     """Return tk image corresponding to name which is taken form path."""
     image = ''
     name = os.path.basename(path)
     if not StockImage.is_registered(name):
         ipath = self.__find_image(path)
         if ipath is not None:
             StockImage.register(name, ipath)
         else:
             msg = "Image '%s' not found in resource paths."
             logger.warning(msg, name)
     try:
         image = StockImage.get(name)
     except StockImageException:
         # TODO: notify something here.
         pass
     return image
예제 #15
0
    def _insert_item(self, root, data, from_file=False):
        """Insert a item on the treeview and fills columns from data"""

        tree = self.treeview
        treelabel = data.get_id()
        row = col = ''
        if root != '' and 'layout' in data:
            row = data.get_layout_property('row')
            col = data.get_layout_property('column')

            # fix row position when using copy and paste
            # If collision, increase by 1
            row_count = self.get_max_row(root)
            if not from_file and (row_count > int(row) and int(col) == 0):
                row = str(row_count + 1)
                data.set_layout_property('row', row)

        image = ''
        try:
            image = StockImage.get('16x16-tk.default')
        except StockImageException:
            # TODO: notify something here
            pass

        try:
            image = StockImage.get('16x16-{0}'.format(data.get_class()))
        except StockImageException:
            # TODO: notify something here
            pass

        values = (data.get_class(), row, col)
        item = tree.insert(root,
                           'end',
                           text=treelabel,
                           values=values,
                           image=image)
        data.attach(self)
        self.treedata[item] = data

        # Update grid r/c data
        self._update_max_grid_rc(root, from_file=True)
        self.app.set_changed()

        return item
예제 #16
0
    def _insert_item(self, root, data, from_file=False):
        """Insert a item on the treeview and fills columns from data"""

        data.setup_defaults(
        )  # load default settings for properties and layout
        tree = self.treeview
        treelabel = '{0}: {1}'.format(data.identifier, data.classname)
        row = col = ''
        if root != '' and data.has_layout_defined():
            row = data.layout_property('row')
            col = data.layout_property('column')

            # fix row position when using copy and paste
            # If collision, increase by 1
            row_count = self.get_max_row(root)
            if not from_file and (row_count > int(row) and int(col) == 0):
                row = str(row_count + 1)
                data.layout_property('row', row)

        image = ''
        try:
            image = StockImage.get('16x16-tk.default')
        except StockImageException:
            # TODO: notify something here
            pass

        try:
            image = StockImage.get('16x16-{0}'.format(data.classname))
        except StockImageException:
            # TODO: notify something here
            pass

        values = (data.classname, row, col)
        item = tree.insert(root,
                           'end',
                           text=treelabel,
                           values=values,
                           image=image)
        data.attach(self)
        self.treedata[item] = data

        self.app.set_changed()

        return item
예제 #17
0
 def _setup_styles(self):
     s = ttk.Style()
     s.configure('ColorSelectorButton.Toolbutton',
                 image=StockImage.get('mglass'))
     s.configure('ImageSelectorButton.Toolbutton',
                 image=StockImage.get('mglass'))
     s.configure('ComponentPalette.Toolbutton', font='TkSmallCaptionFont')
     s.configure('ComponentPalette.TNotebook.Tab',
                 font='TkSmallCaptionFont')
     s.configure('PanelTitle.TLabel',
                 background='#808080',
                 foreground='white',
                 font='TkSmallCaptionFont')
     s.configure('Template.Toolbutton', padding=5)
     if sys.platform == 'linux':
         #change background of comboboxes
         color = s.lookup('TEntry', 'fieldbackground')
         s.map('TCombobox', fieldbackground=[('readonly', color)])
         s.map('TSpinbox', fieldbackground=[('readonly', color)])
예제 #18
0
 def _create_indicators(self):
     # selected indicators
     self.indicators = []
     anchors = {'nw': tk.SE, 'ne': tk.SW, 'sw': tk.NE, 'se': tk.NW}
     for sufix in self.indicators_tag:
         label = tk.Label(self.canvas, image=StockImage.get('indicator_' + sufix))
         self.indicators.append(label)
         self.canvas.create_window(
             -10, -10, anchor=anchors[sufix], window=label, tags=sufix
         )
예제 #19
0
파일: previewer.py 프로젝트: SMan23/pygubu
 def _create_indicators(self):
     # selected indicators
     self.indicators = []
     anchors = {'nw': tk.SE, 'ne': tk.SW, 'sw': tk.NE, 'se': tk.NW}
     for sufix in self.indicators_tag:
         label = tk.Label(self.canvas,
                          image=StockImage.get('indicator_' + sufix))
         self.indicators.append(label)
         self.canvas.create_window(-10, -10, anchor=anchors[sufix],
                                   window=label, tags=sufix)
예제 #20
0
파일: __init__.py 프로젝트: tisttsf/pygubu
 def get_image(self, path):
     """Return tk image corresponding to name which is taken form path."""
     image = ''
     name = os.path.basename(path)
     self.__load_image(path)
     try:
         image = StockImage.get(name)
     except StockImageException:
         # TODO: notify something here.
         pass
     return image
예제 #21
0
파일: __init__.py 프로젝트: tisttsf/pygubu
 def get_iconbitmap(self, path):
     """Return path to use as iconbitmap property."""
     image = None
     name = os.path.basename(path)
     self.__load_image(path)
     try:
         image = StockImage.as_iconbitmap(name)
     except StockImageException:
         # TODO: notify something here.
         pass
     return image
예제 #22
0
    def _insert_item(self, root, data, from_file=False):
        """Insert a item on the treeview and fills columns from data"""

        tree = self.treeview
        treelabel = data.get_id()
        row = col = ''
        if root != '' and 'layout' in data:
            row = data.get_layout_property('row')
            col = data.get_layout_property('column')

            # fix row position when using copy and paste
            # If collision, increase by 1
            row_count = self.get_max_row(root)
            if not from_file and (row_count > int(row) and int(col) == 0):
                row = str(row_count + 1)
                data.set_layout_property('row', row)

        image = ''
        try:
            image = StockImage.get('16x16-tk.default')
        except StockImageException:
            # TODO: notify something here
            pass

        try:
            image = StockImage.get('16x16-{0}'.format(data.get_class()))
        except StockImageException:
            # TODO: notify something here
            pass

        values = (data.get_class(), row, col)
        item = tree.insert(root, 'end', text=treelabel, values=values,
                           image=image)
        data.attach(self)
        self.treedata[item] = data

        # Update grid r/c data
        self._update_max_grid_rc(root, from_file=True)
        self.app.set_changed()

        return item
예제 #23
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)
예제 #24
0
파일: main.py 프로젝트: codetestcode/pygubu
    def _create_ui(self):
        """Creates all gui widgets"""

        self.preview = None
        self.about_dialog = None
        self.builder = builder = pygubu.Builder(translator)
        self.currentfile = None
        self.is_changed = False

        uifile = os.path.join(FILE_PATH,"ui/pygubu-ui.ui")
        self.builder.add_from_file(uifile)
        self.builder.add_resource_path(os.path.join(FILE_PATH, "images"))

        #build main ui
        self.builder.get_object('mainwindow', self.master)
        toplevel = self.master.winfo_toplevel()
        menu = self.builder.get_object('mainmenu', toplevel)
        toplevel['menu'] = menu

        #project name
        self.project_name = self.builder.get_object('projectname_lbl')

        #Class selector values
        self.widgetlist_sf = self.builder.get_object("widgetlist_sf")
        self.widgetlist = self.builder.get_object("widgetlist")
        self.configure_widget_list()

        #widget tree
        self.treeview = tree = self.builder.get_object('treeview1')
        self.bindings_frame = self.builder.get_object('bindingsframe')
        self.bindings_tree = self.builder.get_object('bindingstree')

        #Preview
        previewc = self.builder.get_object('preview_canvas')
        self.previewer = PreviewHelper(previewc)
        #tree editor
        self.tree_editor = WidgetsTreeEditor(self)
        #properties frame
        self.widget_props_frame = builder.get_object('propertiesframe')
        self.layout_props_frame = builder.get_object('layoutframe')
        self.properties_editor = WidgetPropertiesEditor(self)

        self.builder.connect_callbacks(self)

        #Status bar
        self.statusbar = self.builder.get_object('statusbar')
        handler = StatusBarHandler(self.statusbar)
        handler.setLevel(logging.INFO)
        logger.addHandler(handler)
        pygubu.builder.logger.addHandler(handler)

        #app grid
        self.set_resizable()

        #
        #Application bindings
        #
        master = self.master
        master.bind_all('<Control-KeyPress-n>',
                lambda e: self.on_file_menuitem_clicked('file_new'))
        master.bind_all('<Control-KeyPress-o>',
                lambda e: self.on_file_menuitem_clicked('file_open'))
        master.bind_all('<Control-KeyPress-s>',
                lambda e: self.on_file_menuitem_clicked('file_save'))
        master.bind_all('<Control-KeyPress-q>',
                lambda e: self.on_file_menuitem_clicked('file_quit'))
        master.bind_all('<Control-KeyPress-i>',
                lambda e: self.on_edit_menuitem_clicked('edit_item_up'))
        master.bind_all('<Control-KeyPress-k>',
                lambda e: self.on_edit_menuitem_clicked('edit_item_down'))

        #
        # Widget bindings
        #
        self.tree_editor.treeview.bind('<Control-KeyPress-c>',
                lambda e: self.tree_editor.copy_to_clipboard())
        self.tree_editor.treeview.bind('<Control-KeyPress-v>',
                lambda e: self.tree_editor.paste_from_clipboard())
        self.tree_editor.treeview.bind('<Control-KeyPress-x>',
                lambda e: self.tree_editor.cut_to_clipboard())
        self.tree_editor.treeview.bind('<KeyPress-Delete>',
                lambda e: self.on_edit_menuitem_clicked('edit_item_delete'))
        def clear_key_pressed(event, newevent):
            # when KeyPress, not Ctrl-KeyPress, generate event.
            if event.keysym_num == ord(event.char):
                self.tree_editor.treeview.event_generate(newevent)
        self.tree_editor.treeview.bind('<i>',
                lambda e: clear_key_pressed(e, '<Up>'))
        self.tree_editor.treeview.bind('<k>',
                lambda e: clear_key_pressed(e, '<Down>'))
        #grid move bindings
        self.tree_editor.treeview.bind('<Alt-KeyPress-i>',
                lambda e: self.on_edit_menuitem_clicked('grid_up'))
        self.tree_editor.treeview.bind('<Alt-KeyPress-k>',
                lambda e: self.on_edit_menuitem_clicked('grid_down'))
        self.tree_editor.treeview.bind('<Alt-KeyPress-j>',
                lambda e: self.on_edit_menuitem_clicked('grid_left'))
        self.tree_editor.treeview.bind('<Alt-KeyPress-l>',
                lambda e: self.on_edit_menuitem_clicked('grid_right'))


        #
        # Setup tkk styles
        #
        self._setup_styles()

        #
        # Setup dynamic theme submenu
        #
        self._setup_theme_menu()

        #app config
        top = self.master.winfo_toplevel()
        try:
            top.wm_iconname('pygubu')
            top.tk.call('wm', 'iconphoto', '.', StockImage.get('pygubu'))
        except StockImageException as e:
            pass

        self.set_title( _('Pygubu a GUI builder for tkinter') )
        self.set_size('640x480')
예제 #25
0
파일: main.py 프로젝트: codetestcode/pygubu
mwpath = os.path.dirname(mwidgets.__file__)
for mfile in os.listdir(mwpath):
    if mfile.endswith('.py') and not mfile.startswith('__'):
        modulename = "{0}.{1}".format(widgets_pkg, mfile[:-3])
        importlib.import_module(modulename)


#Initilize properties from custom widgets
for pname, descr in builder.CUSTOM_PROPERTIES.items():
    properties.register_custom(pname, descr)


#Initialize images
DESIGNER_DIR = os.path.dirname(os.path.abspath(__file__))
IMAGES_DIR = os.path.join(DESIGNER_DIR, "images")
StockImage.register_from_dir(IMAGES_DIR)
StockImage.register_from_dir(
        os.path.join(IMAGES_DIR, 'widgets', '22x22'), '22x22-')
StockImage.register_from_dir(
        os.path.join(IMAGES_DIR, 'widgets', '16x16'), '16x16-')

#Initialize logger
logger = logging.getLogger('pygubu.designer')
logger.setLevel(logging.INFO)


class StatusBarHandler(logging.Handler):
    def __init__(self, tklabel, level=logging.NOTSET):
        super(StatusBarHandler, self).__init__(level)
        self.tklabel = tklabel
        self._clear = True
예제 #26
0
    def __init__(self):
        """Creates all gui widgets"""

        self.translator = translator
        self.preview = None
        self.about_dialog = None
        self.preferences = None
        self.script_generator = None
        self.builder = pygubu.Builder(translator)
        self.currentfile = None
        self.is_changed = False
        self.current_title = 'new'

        uifile = os.path.join(FILE_PATH, "ui/pygubu-ui.ui")
        self.builder.add_from_file(uifile)
        self.builder.add_resource_path(os.path.join(FILE_PATH, "images"))

        #build main ui
        self.mainwindow = self.builder.get_object('mainwindow')
        #toplevel = self.master.winfo_toplevel()
        menu = self.builder.get_object('mainmenu', self.mainwindow)
        self.mainwindow.configure(menu=menu)

        # Recen Files management
        rfmenu = self.builder.get_object('file_recent_menu')
        self.rfiles_manager = RecentFilesManager(rfmenu, self.do_file_open)
        self.mainwindow.after_idle(lambda: self.rfiles_manager.load())

        #widget tree
        self.treeview = self.builder.get_object('treeview1')
        self.bindings_frame = self.builder.get_object('bindingsframe')
        self.bindings_tree = self.builder.get_object('bindingstree')

        # Load all widgets before creating the component pallete
        init_pygubu_widgets()

        # _pallete
        self.fpalette = self.builder.get_object('fpalette')
        self.create_component_palette(self.fpalette)

        #Preview
        previewc = self.builder.get_object('preview_canvas')
        self.previewer = PreviewHelper(previewc)
        #tree editor
        self.tree_editor = WidgetsTreeEditor(self)

        # Tab Code
        self.script_generator = ScriptGenerator(self)

        # Bottom Panel
        self.setup_bottom_panel()

        self.builder.connect_callbacks(self)

        #
        # Application Keyboard bindings
        #
        master = self.mainwindow
        master.bind_all('<Control-KeyPress>',
                        key_bind(Key.N, virtual_event(actions.FILE_NEW)))
        master.bind_all('<Control-KeyPress>',
                        key_bind(Key.O, virtual_event(actions.FILE_OPEN)),
                        add=True)
        master.bind_all('<Control-KeyPress>',
                        key_bind(Key.S, virtual_event(actions.FILE_SAVE)),
                        add=True)
        master.bind_all('<Control-KeyPress>',
                        key_bind(Key.Q, virtual_event(actions.FILE_QUIT)),
                        add=True)
        master.bind_all('<F5>',
                        virtual_event(actions.TREE_ITEM_PREVIEW_TOPLEVEL))
        master.bind_all('<F6>',
                        virtual_event(actions.PREVIEW_TOPLEVEL_CLOSE_ALL))

        # Tree Editing Keyboard events
        for widget in (self.treeview, previewc):
            widget.bind(
                '<Control-KeyPress>',
                key_bind(Key.I, virtual_event(actions.TREE_ITEM_MOVE_UP)))
            widget.bind('<Control-KeyPress>',
                        key_bind(Key.K,
                                 virtual_event(actions.TREE_ITEM_MOVE_DOWN)),
                        add=True)
            widget.bind('<Control-KeyPress>',
                        key_bind(
                            Key.C,
                            lambda e: self.tree_editor.copy_to_clipboard()),
                        add=True)
            widget.bind('<Control-KeyPress>',
                        key_bind(
                            Key.V,
                            lambda e: self.tree_editor.paste_from_clipboard()),
                        add=True)
            widget.bind(
                '<Control-KeyPress>',
                key_bind(Key.X, lambda e: self.tree_editor.cut_to_clipboard()),
                add=True)
            widget.bind('<KeyPress>',
                        key_bind(Key.I, virtual_event(actions.TREE_NAV_UP)))
            widget.bind('<KeyPress>',
                        key_bind(Key.K, virtual_event(actions.TREE_NAV_DOWN)),
                        add=True)
            widget.bind('<KeyPress-Delete>',
                        virtual_event(actions.TREE_ITEM_DELETE))

        #grid move bindings
        self.treeview.bind(
            '<Alt-KeyPress>',
            key_bind(Key.I, virtual_event(actions.TREE_ITEM_GRID_UP)))
        self.treeview.bind('<Alt-KeyPress>',
                           key_bind(Key.K,
                                    virtual_event(
                                        actions.TREE_ITEM_GRID_DOWN)),
                           add=True)
        self.treeview.bind('<Alt-KeyPress>',
                           key_bind(Key.J,
                                    virtual_event(
                                        actions.TREE_ITEM_GRID_LEFT)),
                           add=True)
        self.treeview.bind('<Alt-KeyPress>',
                           key_bind(
                               Key.L,
                               virtual_event(actions.TREE_ITEM_GRID_RIGHT)),
                           add=True)

        # Actions Bindings
        w = self.mainwindow
        w.bind(actions.FILE_NEW, self.on_file_new)
        w.bind(actions.FILE_OPEN, lambda e: self.do_file_open())
        w.bind(actions.FILE_SAVE, self.on_file_save)
        w.bind(actions.FILE_SAVEAS, lambda e: self.do_save_as())
        w.bind(actions.FILE_QUIT, lambda e: self.quit())
        w.bind(actions.FILE_RECENT_CLEAR,
               lambda e: self.rfiles_manager.clear())
        # On preferences save binding
        w.bind('<<PygubuDesignerPreferencesSaved>>', self.on_preferences_saved)

        #
        # Setup tkk styles
        #
        self._setup_styles()

        #
        # Setup dynamic theme submenu
        #
        self._setup_theme_menu()

        #app config
        top = self.mainwindow
        try:
            top.wm_iconname('pygubu')
            top.tk.call('wm', 'iconphoto', '.', StockImage.get('pygubu'))
        except StockImageException as e:
            pass
예제 #27
0
    def __init__(self):
        """Creates all gui widgets"""

        self.translator = translator
        self.preview = None
        self.about_dialog = None
        self.preferences = None
        self.script_generator = None
        self.builder = pygubu.Builder(translator)
        self.currentfile = None
        self.is_changed = False
        self.current_title = 'new'

        uifile = os.path.join(FILE_PATH, "ui/pygubu-ui.ui")
        self.builder.add_from_file(uifile)
        self.builder.add_resource_path(os.path.join(FILE_PATH, "images"))

        #build main ui
        self.mainwindow = self.builder.get_object('mainwindow')
        #toplevel = self.master.winfo_toplevel()
        menu = self.builder.get_object('mainmenu', self.mainwindow)
        self.mainwindow.configure(menu=menu)

        # Recen Files management
        rfmenu = self.builder.get_object('file_recent_menu')
        self.rfiles_manager = RecentFilesManager(rfmenu, self.do_file_open)
        self.mainwindow.after_idle(lambda: self.rfiles_manager.load())

        #widget tree
        self.treeview = self.builder.get_object('treeview1')
        self.bindings_frame = self.builder.get_object('bindingsframe')
        self.bindings_tree = self.builder.get_object('bindingstree')

        # Load all widgets before creating the component pallete
        init_pygubu_widgets()

        # _pallete
        self.fpalette = self.builder.get_object('fpalette')
        self.create_component_palette(self.fpalette)

        #Preview
        previewc = self.builder.get_object('preview_canvas')
        self.previewer = PreviewHelper(previewc)
        #tree editor
        self.tree_editor = WidgetsTreeEditor(self)

        # Tab Code
        self.script_generator = ScriptGenerator(self)

        # Bottom Panel
        self.setup_bottom_panel()

        self.builder.connect_callbacks(self)

        #
        #Application bindings
        #
        master = self.mainwindow
        master.bind_all('<Control-KeyPress-n>',
                        lambda e: self.on_file_menuitem_clicked('file_new'))
        master.bind_all('<Control-KeyPress-o>',
                        lambda e: self.on_file_menuitem_clicked('file_open'))
        master.bind_all('<Control-KeyPress-s>',
                        lambda e: self.on_file_menuitem_clicked('file_save'))
        master.bind_all('<Control-KeyPress-q>',
                        lambda e: self.on_file_menuitem_clicked('file_quit'))
        master.bind_all(
            '<Control-KeyPress-i>',
            lambda e: self.on_edit_menuitem_clicked('edit_item_up'))
        master.bind_all(
            '<Control-KeyPress-k>',
            lambda e: self.on_edit_menuitem_clicked('edit_item_down'))
        master.bind_all('<F5>',
                        lambda e: self.tree_editor.preview_in_toplevel())
        master.bind_all('<F6>',
                        lambda e: self.previewer.close_toplevel_previews())

        #
        # Widget bindings
        #
        for widget in (self.tree_editor.treeview, previewc):
            widget.bind('<Control-KeyPress-c>',
                        lambda e: self.tree_editor.copy_to_clipboard())
            widget.bind('<Control-KeyPress-v>',
                        lambda e: self.tree_editor.paste_from_clipboard())
            widget.bind('<Control-KeyPress-x>',
                        lambda e: self.tree_editor.cut_to_clipboard())
            widget.bind(
                '<KeyPress-Delete>',
                lambda e: self.on_edit_menuitem_clicked('edit_item_delete'))

        def clear_key_pressed(event, newevent):
            # when KeyPress, not Ctrl-KeyPress, generate event.
            if event.keysym_num == ord(event.char):
                self.tree_editor.treeview.event_generate(newevent)

        self.tree_editor.treeview.bind('<i>',
                                       lambda e: clear_key_pressed(e, '<Up>'))
        self.tree_editor.treeview.bind(
            '<k>', lambda e: clear_key_pressed(e, '<Down>'))

        #grid move bindings
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-i>',
            lambda e: self.on_edit_menuitem_clicked('grid_up'))
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-k>',
            lambda e: self.on_edit_menuitem_clicked('grid_down'))
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-j>',
            lambda e: self.on_edit_menuitem_clicked('grid_left'))
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-l>',
            lambda e: self.on_edit_menuitem_clicked('grid_right'))

        # On preferences save binding
        self.mainwindow.bind('<<PygubuDesignerPreferencesSaved>>',
                             self.on_preferences_saved)

        #
        # Setup tkk styles
        #
        self._setup_styles()

        #
        # Setup dynamic theme submenu
        #
        self._setup_theme_menu()

        #app config
        top = self.mainwindow
        try:
            top.wm_iconname('pygubu')
            top.tk.call('wm', 'iconphoto', '.', StockImage.get('pygubu'))
        except StockImageException as e:
            pass
예제 #28
0
    def __init__(self):
        """Creates all gui widgets"""

        self.translator = translator
        self.preview = None
        self.about_dialog = None
        self.preferences = None
        self.script_generator = None
        self.builder = pygubu.Builder(translator)
        self.currentfile = None
        self.is_changed = False
        self.current_title = 'new'

        self.builder.add_from_file(str(DESIGNER_DIR / "ui" / "pygubu-ui.ui"))
        self.builder.add_resource_path(str(DESIGNER_DIR / "images"))

        in_macos = sys.platform == 'darwin'
        # build main ui
        self.mainwindow = self.builder.get_object('mainwindow')
        self.main_menu = self.builder.get_object('mainmenu', self.mainwindow)
        self.context_menu = self.builder.get_object('context_menu',
                                                    self.mainwindow)

        # Initialize duplicate menu state
        self.duplicate_menu_state = 'normal'

        if in_macos:
            cmd = 'tk::mac::ShowPreferences'
            self.mainwindow.createcommand(cmd, self._edit_preferences)
            # cmd = 'tk::mac::ShowHelp'
            # self.mainwindow.createcommand(cmd, self.on_help_item_clicked)
            cmd = 'tk::mac::Quit'
            self.mainwindow.createcommand(cmd, self.quit)
            # In mac add apple menu
            m = tk.Menu(self.main_menu, name='apple')
            m.add_command(label=_('Quit …'),
                          accelerator='Cmd-Q',
                          command=self.quit)
            self.main_menu.insert_cascade(0, menu=m)

        # Set top menu
        self.mainwindow.configure(menu=self.main_menu)

        # Recen Files management
        rfmenu = self.builder.get_object('file_recent_menu')
        self.rfiles_manager = RecentFilesManager(rfmenu, self.do_file_open)
        self.mainwindow.after_idle(self.rfiles_manager.load)

        # widget tree
        self.treeview = self.builder.get_object('treeview1')
        self.bindings_frame = self.builder.get_object('bindingsframe')
        self.bindings_tree = self.builder.get_object('bindingstree')

        # Preview
        self.preview_canvas = self.builder.get_object('preview_canvas')
        self.previewer = PreviewHelper(self.preview_canvas,
                                       self.show_context_menu,
                                       self._should_center_preview_window)

        # Bottom Panel
        self.setup_bottom_panel()

        self.builder.connect_callbacks(self)

        # setup app preferences
        self.setup_app_preferences()

        #
        # Setup tkk styles
        #
        self._setup_styles()

        #
        # Setup dynamic theme submenu
        #
        self._setup_theme_menu()

        # App config
        top = self.mainwindow
        try:
            top.wm_iconname('pygubu')
            top.tk.call('wm', 'iconphoto', '.', StockImage.get('pygubu'))
        except StockImageException as e:
            pass

        # Load all widgets before creating the component pallete
        init_pygubu_widgets()

        # _pallete
        self.fpalette = self.builder.get_object('fpalette')
        self.create_component_palette(self.fpalette)

        # tree editor
        self.tree_editor = WidgetsTreeEditor(self)

        # Tab Code
        self.script_generator = ScriptGenerator(self)

        # App bindings
        self._setup_app_bindings()
예제 #29
0
    def _create_ui(self):
        """Creates all gui widgets"""

        self.preview = None
        self.about_dialog = None
        self.preferences = None
        self.builder = pygubu.Builder(translator)
        self.currentfile = None
        self.is_changed = False

        uifile = os.path.join(FILE_PATH, "ui/pygubu-ui.ui")
        self.builder.add_from_file(uifile)
        self.builder.add_resource_path(os.path.join(FILE_PATH, "images"))

        #build main ui
        self.builder.get_object('mainwindow', self.master)
        toplevel = self.master.winfo_toplevel()
        menu = self.builder.get_object('mainmenu', toplevel)
        toplevel['menu'] = menu

        #project name
        self.project_name = self.builder.get_object('projectname_lbl')

        #Class selector values
        self.widgetlist_sf = self.builder.get_object("widgetlist_sf")
        self.widgetlist = self.builder.get_object("widgetlist")
        self.configure_widget_list()

        #widget tree
        self.treeview = self.builder.get_object('treeview1')
        self.bindings_frame = self.builder.get_object('bindingsframe')
        self.bindings_tree = self.builder.get_object('bindingstree')

        #Preview
        previewc = self.builder.get_object('preview_canvas')
        self.previewer = PreviewHelper(previewc)
        #tree editor
        self.tree_editor = WidgetsTreeEditor(self)

        self.builder.connect_callbacks(self)

        #Status bar
        self.statusbar = self.builder.get_object('statusbar')
        handler = StatusBarHandler(self.statusbar)
        handler.setLevel(logging.INFO)
        logger.addHandler(handler)
        pygubu.builder.logger.addHandler(handler)

        #app grid
        self.set_resizable()

        #
        #Application bindings
        #
        master = self.master
        master.bind_all('<Control-KeyPress-n>',
                        lambda e: self.on_file_menuitem_clicked('file_new'))
        master.bind_all('<Control-KeyPress-o>',
                        lambda e: self.on_file_menuitem_clicked('file_open'))
        master.bind_all('<Control-KeyPress-s>',
                        lambda e: self.on_file_menuitem_clicked('file_save'))
        master.bind_all('<Control-KeyPress-q>',
                        lambda e: self.on_file_menuitem_clicked('file_quit'))
        master.bind_all(
            '<Control-KeyPress-i>',
            lambda e: self.on_edit_menuitem_clicked('edit_item_up'))
        master.bind_all(
            '<Control-KeyPress-k>',
            lambda e: self.on_edit_menuitem_clicked('edit_item_down'))
        master.bind_all('<F5>',
                        lambda e: self.tree_editor.preview_in_toplevel())
        master.bind_all('<F6>',
                        lambda e: self.previewer.close_toplevel_previews())

        #
        # Widget bindings
        #
        self.tree_editor.treeview.bind(
            '<Control-KeyPress-c>',
            lambda e: self.tree_editor.copy_to_clipboard())
        self.tree_editor.treeview.bind(
            '<Control-KeyPress-v>',
            lambda e: self.tree_editor.paste_from_clipboard())
        self.tree_editor.treeview.bind(
            '<Control-KeyPress-x>',
            lambda e: self.tree_editor.cut_to_clipboard())
        self.tree_editor.treeview.bind(
            '<KeyPress-Delete>',
            lambda e: self.on_edit_menuitem_clicked('edit_item_delete'))

        def clear_key_pressed(event, newevent):
            # when KeyPress, not Ctrl-KeyPress, generate event.
            if event.keysym_num == ord(event.char):
                self.tree_editor.treeview.event_generate(newevent)

        self.tree_editor.treeview.bind('<i>',
                                       lambda e: clear_key_pressed(e, '<Up>'))
        self.tree_editor.treeview.bind(
            '<k>', lambda e: clear_key_pressed(e, '<Down>'))

        #grid move bindings
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-i>',
            lambda e: self.on_edit_menuitem_clicked('grid_up'))
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-k>',
            lambda e: self.on_edit_menuitem_clicked('grid_down'))
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-j>',
            lambda e: self.on_edit_menuitem_clicked('grid_left'))
        self.tree_editor.treeview.bind(
            '<Alt-KeyPress-l>',
            lambda e: self.on_edit_menuitem_clicked('grid_right'))

        # On preferences save binding
        self.master.bind('<<PygubuDesignerPreferencesSaved>>',
                         self.on_preferences_saved)

        #
        # Setup tkk styles
        #
        self._setup_styles()

        #
        # Setup dynamic theme submenu
        #
        self._setup_theme_menu()

        #app config
        top = self.master.winfo_toplevel()
        try:
            top.wm_iconname('pygubu')
            top.tk.call('wm', 'iconphoto', '.', StockImage.get('pygubu'))
        except StockImageException as e:
            pass

        self.set_title(_('Pygubu a GUI builder for tkinter'))
        self.set_size('640x480')
예제 #30
0
    def configure_widget_list(self):
        acf = AccordionFrame(self.widgetlist)
        acf.grid(sticky=tk.NSEW)
        acf.bind('<<AccordionGroupToggle>>', self.on_widgetlist_group_toogle)

        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)

        #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()

        #hide tk widget by default
        acf.group_toogle('tk')
        self.widgetlist_sf.reposition()
예제 #31
0
 def show_invalid(self, value=True):
     img = ''
     if value:
         img = StockImage.get('property_invalid')
     self._error_label.configure(image=img)
예제 #32
0
try:
    import tkinter as tk
    import tkinter.ttk as ttk
except:
    import Tkinter as tk
    import ttk

from pygubu.stockimage import StockImage, StockImageException
from pygubu.widgets.scrollbarhelper import ScrollbarHelper

FILE_DIR = os.path.dirname(os.path.abspath(__file__))
IMAGES_DIR = os.path.join(FILE_DIR, "..", "images", "widgets",
                          "propertyeditor")
IMAGES_DIR = os.path.abspath(IMAGES_DIR)
StockImage.register_from_dir(IMAGES_DIR)


class PropertyEditor(ttk.Frame):
    def __init__(self, master=None, **kw):
        self._variable = tk.StringVar()
        self._initvalue = None
        self.value = ''
        ttk.Frame.__init__(self, master, **kw)
        self._create_ui()

    def _create_ui(self):
        pass

    def _validate(self):
        return True
예제 #33
0
DESIGNER_DIR = os.path.dirname(os.path.abspath(__file__))

imgformat = 'images-gif'
if tk.TkVersion >= 8.6:
    imgformat = 'images-png'

IMAGES_DIR = os.path.join(DESIGNER_DIR, "images")
IMAGE_PATHS = [  #(dir, tag)
    (IMAGES_DIR, ''),
    (os.path.join(IMAGES_DIR, imgformat), ''),
    (os.path.join(IMAGES_DIR, imgformat, 'widgets', '22x22'), '22x22-'),
    (os.path.join(IMAGES_DIR, imgformat, 'widgets', '16x16'), '16x16-'),
    (os.path.join(IMAGES_DIR, imgformat, 'widgets', 'fontentry'), ''),
]
for dir_, prefix in IMAGE_PATHS:
    StockImage.register_from_dir(dir_, prefix)


class StatusBarHandler(logging.Handler):
    def __init__(self, app, level=logging.NOTSET):
        super(StatusBarHandler, self).__init__(level)
        self.app = app
        formatter = logging.Formatter('%(asctime)s %(levelname)s:%(message)s',
                                      datefmt='%H:%M:%S')
        self.setFormatter(formatter)

    def emit(self, record):
        try:
            msg = self.format(record)
            self.app.log_message(msg, record.levelno)
        except (KeyboardInterrupt, SystemExit):
예제 #34
0
    def _insert_item(self,
                     root,
                     data,
                     from_file=False,
                     is_first_widget_pasted=False):
        """Insert a item on the treeview and fills columns from data

        The argument: is_first_widget_pasted (bool) will be True if we're about to
        insert the first widget that was pasted from the clipboard or duplicated.
        Here 'first widget' is basically the 'outer widget' - the widget whose direct 
        parent is the container that it was pasted in.

        If we're currently on an outer widget (is_first_widget_pasted=True) that was 
        pasted or duplicated, we need to see if any of its siblings have the same 
        row AND column, and if they do, we need to give the pasted widget a new unique 
        row number so it doesn't overlap with its new siblings.

        If we're not currently dealing with an outer widget, that means it's a child of 
        the outer widget and we should not change the row/columns of the outer widget's 
        children widgets.
        """

        data.setup_defaults(
        )  # load default settings for properties and layout
        tree = self.treeview
        treelabel = '{0}: {1}'.format(data.identifier, data.classname)
        row = col = ''
        if root != '' and data.has_layout_defined():
            if data.manager == 'grid':
                row = data.layout_property('row')
                col = data.layout_property('column')
                # Fix grid row position when using copy and paste
                if not from_file:
                    if is_first_widget_pasted:
                        # Increase the pasted widget by 1 row (if necessary)
                        # so that it doesn't overlap
                        row = self.get_available_row(root, data)

                    data.layout_property('row', row)

        image = ''
        try:
            image = StockImage.get('16x16-tk.default')
        except StockImageException:
            # TODO: notify something here
            pass

        try:
            image = StockImage.get('16x16-{0}'.format(data.classname))
        except StockImageException:
            # TODO: notify something here
            pass

        values = (data.classname, row, col)
        item = tree.insert(root,
                           'end',
                           text=treelabel,
                           values=values,
                           image=image)
        data.attach(self)
        self.treedata[item] = data

        self.app.set_changed()

        return item
예제 #35
0
파일: main.py 프로젝트: codetestcode/pygubu
    def configure_widget_list(self):
        acf = AccordionFrame(self.widgetlist)
        acf.grid(sticky=tk.NSEW)
        acf.bind('<<AccordionGroupToggle>>', self.on_widgetlist_group_toogle)

        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)

        #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()

        #hide tk widget by default
        acf.group_toogle('tk')
        self.widgetlist_sf.reposition()
예제 #36
0
파일: fontentry.py 프로젝트: DaZhu/pygubu
    import tkinter.ttk as ttk
    import tkinter.font
except:
    import Tkinter as tk
    import ttk
    import tkFont
    tk.font = tkFont

from pygubu.stockimage import StockImage, StockImageException
from pygubudesigner.widgets.propertyeditor import *

RE_FONT = re.compile("(?P<family>\{\w+(\w|\s)*\}|\w+)\s?(?P<size>-?\d+)?\s?(?P<modifiers>\{\w+(\w|\s)*\}|\w+)?")
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
IMAGES_DIR = os.path.join(FILE_DIR, "..", "images", "widgets", "fontentry")
IMAGES_DIR = os.path.abspath(IMAGES_DIR)
StockImage.register_from_dir(IMAGES_DIR)

PREDEFINED_FONTS = [
    'TkDefaultFont', 'TkTextFont', 'TkFixedFont',
    'TkMenuFont', 'TkHeadingFont', 'TkCaptionFont',
    'TkSmallCaptionFont', 'TkIconFont', 'TkTooltipFont']
WIN_FONTS = (
    'system', 'ansi', 'device', 'systemfixed', 'ansifixed', 'oemfixed')
MAC_FONTS = (
    'system','application','menu',
    'systemSystemFont', 'systemEmphasizedSystemFont', 'systemSmallSystemFont',
    'systemSmallEmphasizedSystemFont', 'systemApplicationFont',
    'systemLabelFont', 'systemViewsFont', 'systemMenuTitleFont',
    'systemMenuItemFont', 'systemMenuItemMarkFont', 'systemMenuItemCmdKeyFont',
    'systemWindowTitleFont', 'systemPushButtonFont',
    'systemUtilityWindowTitleFont', 'systemAlertHeaderFont',
예제 #37
0
            if dirname not in sys.path:
                sys.path.append(dirname)
            modulename = fname[:-3]
            try:
                importlib.import_module(modulename)
            except Exception as e:
                logger.exception(e)
                msg = _("Failed to load custom widget module: \n'{0}'")
                msg = msg.format(path)
                messagebox.showerror(_('Error'), msg)


#Initialize images
DESIGNER_DIR = os.path.dirname(os.path.abspath(__file__))
IMAGES_DIR = os.path.join(DESIGNER_DIR, "images")
StockImage.register_from_dir(IMAGES_DIR)
StockImage.register_from_dir(os.path.join(IMAGES_DIR, 'widgets', '22x22'),
                             '22x22-')
StockImage.register_from_dir(os.path.join(IMAGES_DIR, 'widgets', '16x16'),
                             '16x16-')


class StatusBarHandler(logging.Handler):
    def __init__(self, tklabel, level=logging.NOTSET):
        super(StatusBarHandler, self).__init__(level)
        self.tklabel = tklabel
        self._clear = True
        self._cb_id = None

    def emit(self, record):
        try:
예제 #38
0
    def __init__(self):
        """Creates all gui widgets"""

        self.translator = translator
        self.preview = None
        self.about_dialog = None
        self.preferences = None
        self.script_generator = None
        self.builder = pygubu.Builder(translator)
        self.currentfile = None
        self.is_changed = False
        self.current_title = 'new'

        uifile = os.path.join(FILE_PATH, "ui/pygubu-ui.ui")
        self.builder.add_from_file(uifile)
        self.builder.add_resource_path(os.path.join(FILE_PATH, "images"))

        in_macos = (sys.platform == 'darwin')
        #build main ui
        self.mainwindow = self.builder.get_object('mainwindow')
        menu = self.builder.get_object('mainmenu', self.mainwindow)

        if in_macos:
            cmd = 'tk::mac::ShowPreferences'
            self.mainwindow.createcommand(cmd, self._edit_preferences)
            #cmd = 'tk::mac::ShowHelp'
            #self.mainwindow.createcommand(cmd, self.on_help_item_clicked)
            cmd = 'tk::mac::Quit'
            self.mainwindow.createcommand(cmd, self.quit)
            # In mac add apple menu
            m = tk.Menu(menu, name='apple')
            m.add_command(label=_('Quit …'),
                          accelerator='Cmd-Q',
                          command=self.quit)
            menu.insert_cascade(0, menu=m)

        # Set top menu
        self.mainwindow.configure(menu=menu)

        # Recen Files management
        rfmenu = self.builder.get_object('file_recent_menu')
        self.rfiles_manager = RecentFilesManager(rfmenu, self.do_file_open)
        self.mainwindow.after_idle(lambda: self.rfiles_manager.load())

        #widget tree
        self.treeview = self.builder.get_object('treeview1')
        self.bindings_frame = self.builder.get_object('bindingsframe')
        self.bindings_tree = self.builder.get_object('bindingstree')

        # Load all widgets before creating the component pallete
        init_pygubu_widgets()

        # _pallete
        self.fpalette = self.builder.get_object('fpalette')
        self.create_component_palette(self.fpalette)

        #Preview
        previewc = self.builder.get_object('preview_canvas')
        self.previewer = PreviewHelper(previewc)
        #tree editor
        self.tree_editor = WidgetsTreeEditor(self)

        # Tab Code
        self.script_generator = ScriptGenerator(self)

        # Bottom Panel
        self.setup_bottom_panel()

        self.builder.connect_callbacks(self)

        #
        # Application Keyboard bindings
        #
        CONTROL_KP_SEQUENCE = '<Control-KeyPress>'
        ALT_KP_SEQUENCE = '<Alt-KeyPress>'
        if in_macos:
            CONTROL_KP_SEQUENCE = '<Command-KeyPress>'
            ALT_KP_SEQUENCE = '<Control-KeyPress>'
            # Fix menu accelerators
            for m, itemtype, index in menu_iter_children(menu):
                if itemtype != 'separator':
                    accel = m.entrycget(index, 'accelerator')
                    accel = accel.replace('Ctrl+', 'Cmd-')
                    accel = accel.replace('Alt+', 'Ctrl+')
                    m.entryconfigure(index, accelerator=accel)

        master = self.mainwindow
        master.bind_all(CONTROL_KP_SEQUENCE,
                        key_bind(Key.N, virtual_event(actions.FILE_NEW)))
        master.bind_all(CONTROL_KP_SEQUENCE,
                        key_bind(Key.O, virtual_event(actions.FILE_OPEN)),
                        add=True)
        master.bind_all(CONTROL_KP_SEQUENCE,
                        key_bind(Key.S, virtual_event(actions.FILE_SAVE)),
                        add=True)
        master.bind_all(CONTROL_KP_SEQUENCE,
                        key_bind(Key.Q, virtual_event(actions.FILE_QUIT)),
                        add=True)
        master.bind_all('<F5>',
                        virtual_event(actions.TREE_ITEM_PREVIEW_TOPLEVEL))
        master.bind_all('<F6>',
                        virtual_event(actions.PREVIEW_TOPLEVEL_CLOSE_ALL))

        # Tree Editing Keyboard events
        for widget in (self.treeview, previewc):
            widget.bind(
                CONTROL_KP_SEQUENCE,
                key_bind(Key.I, virtual_event(actions.TREE_ITEM_MOVE_UP)))
            widget.bind(CONTROL_KP_SEQUENCE,
                        key_bind(Key.K,
                                 virtual_event(actions.TREE_ITEM_MOVE_DOWN)),
                        add=True)
            widget.bind(CONTROL_KP_SEQUENCE,
                        key_bind(
                            Key.C,
                            lambda e: self.tree_editor.copy_to_clipboard()),
                        add=True)
            widget.bind(CONTROL_KP_SEQUENCE,
                        key_bind(
                            Key.V,
                            lambda e: self.tree_editor.paste_from_clipboard()),
                        add=True)
            widget.bind(
                CONTROL_KP_SEQUENCE,
                key_bind(Key.X, lambda e: self.tree_editor.cut_to_clipboard()),
                add=True)
            widget.bind('<KeyPress>',
                        key_bind(Key.I, virtual_event(actions.TREE_NAV_UP)))
            widget.bind('<KeyPress>',
                        key_bind(Key.K, virtual_event(actions.TREE_NAV_DOWN)),
                        add=True)
            # avoid double delete dialog in macos
            if not in_macos:
                widget.bind('<KeyPress-Delete>',
                            virtual_event(actions.TREE_ITEM_DELETE))

            #grid move bindings
            widget.bind(
                ALT_KP_SEQUENCE,
                key_bind(Key.I, virtual_event(actions.TREE_ITEM_GRID_UP)))
            widget.bind(ALT_KP_SEQUENCE,
                        key_bind(Key.K,
                                 virtual_event(actions.TREE_ITEM_GRID_DOWN)),
                        add=True)
            widget.bind(ALT_KP_SEQUENCE,
                        key_bind(Key.J,
                                 virtual_event(actions.TREE_ITEM_GRID_LEFT)),
                        add=True)
            widget.bind(ALT_KP_SEQUENCE,
                        key_bind(Key.L,
                                 virtual_event(actions.TREE_ITEM_GRID_RIGHT)),
                        add=True)

        # Actions Bindings
        w = self.mainwindow
        w.bind(actions.FILE_NEW, self.on_file_new)
        w.bind(actions.FILE_OPEN, lambda e: self.do_file_open())
        w.bind(actions.FILE_SAVE, self.on_file_save)
        w.bind(actions.FILE_SAVEAS, lambda e: self.do_save_as())
        w.bind(actions.FILE_QUIT, lambda e: self.quit())
        w.bind(actions.FILE_RECENT_CLEAR,
               lambda e: self.rfiles_manager.clear())
        # On preferences save binding
        w.bind('<<PygubuDesignerPreferencesSaved>>', self.on_preferences_saved)

        # setup app preferences
        self.setup_app_preferences()

        #
        # Setup tkk styles
        #
        self._setup_styles()

        #
        # Setup dynamic theme submenu
        #
        self._setup_theme_menu()

        # App config
        top = self.mainwindow
        try:
            top.wm_iconname('pygubu')
            top.tk.call('wm', 'iconphoto', '.', StockImage.get('pygubu'))
        except StockImageException as e:
            pass