Beispiel #1
0
    def draw(self):
        self.pages = Pmw.NoteBook(self.body)
        self.pages.pack(anchor='w', pady=0, padx=0, fill='both', expand=1)
        # COMMON
        common_page = self.pages.add(_('Common'))
        # LINE
        line_group = Pmw.Group(common_page, tag_text=_('Line'))
        line_group.pack(fill='x')
        # line width
        self.line_width = widgets.WidthChooser(line_group.interior(),
                                               self.standard.line_width,
                                               label=_('Line width'))
        self.line_width.pack(anchor='nw', padx=10, pady=5)
        # COLORS
        color_group = Pmw.Group(common_page, tag_text=_('Color'))
        color_group.pack(fill='x')
        # line color
        self.line_color = widgets.ColorButtonWithTransparencyChecker(
            color_group.interior(),
            color=self.standard.line_color,
            text=_("Line color"))
        self.line_color.pack(side='left', padx=10, pady=5)
        # area color
        self.area_color = widgets.ColorButtonWithTransparencyChecker(
            color_group.interior(),
            color=self.standard.area_color,
            text=_("Area color"))
        self.area_color.pack(side='right', padx=10, pady=5)

        # ATOM
        atom_group = self.pages.add(_('Atom'))
        self.show_hydrogens = Tkinter.IntVar()
        self.show_hydrogens.set(int(self.standard.show_hydrogens))
        sh = Tkinter.Checkbutton(atom_group,
                                 text=_('Show hydrogens on visible atoms'),
                                 variable=self.show_hydrogens)
        sh.pack(anchor='w', padx=10, pady=10)

        # BOND
        bond_group = self.pages.add(
            _("Bond"))  #Pmw.Group( self.body, tag_text=_('Bond'))
        # bond width
        self.bond_width = widgets.WidthChooser(bond_group,
                                               self.standard.bond_width,
                                               label=_('Bond width'))
        self.bond_width.pack(anchor='ne', padx=10, pady=5)
        # wedge bond width
        self.wedge_width = widgets.WidthChooser(bond_group,
                                                self.standard.wedge_width,
                                                label=_('Wedge/Hatch width'))
        self.wedge_width.pack(anchor='ne', padx=10, pady=5)
        # bond length
        self.bond_length = widgets.LengthChooser(bond_group,
                                                 self.standard.bond_length,
                                                 label=_('Bond length'))
        self.bond_length.pack(anchor='ne', padx=10, pady=5)
        # double bond length ratio
        self.double_length_ratio = widgets.RatioCounter(
            bond_group,
            self.standard.double_length_ratio,
            label=_('Double-bond length ratio'))
        self.double_length_ratio.pack(anchor='ne', padx=10, pady=5)

        # FONT
        font_group = self.pages.add(_('Font'))
        # font size
        self.font_size = widgets.FontSizeChooser(font_group,
                                                 self.standard.font_size)
        self.font_size.pack(anchor='nw')
        # font family
        self.font_family = widgets.FontFamilyChooser(font_group,
                                                     self.standard.font_family)
        self.font_family.pack(anchor="nw", side='bottom')

        # PAPER
        # paper type
        self.paper = self.parent.paper
        paper_group = self.pages.add(_('Paper'))
        if self.paper._paper_properties['type'] == 'custom':
            t = _('Custom')
        else:
            t = self.paper._paper_properties['type']
        paper_types = data.paper_types.keys()
        paper_types.sort()
        self.paper_type_chooser = Pmw.OptionMenu(
            paper_group,
            items=paper_types,  #+[_('Custom')],
            initialitem=t,
            labelpos='w',
            label_text=_('Paper size') + ':',
            menubutton_width=10)
        self.paper_type_chooser.pack(anchor='w', padx=10, pady=10)
        # paper orientation
        self.paper_orientation_chooser = Pmw.RadioSelect(
            paper_group, buttontype='radiobutton', orient='vertical', pady=0)
        self.paper_orientation_chooser.add(_('Portrait'))
        self.paper_orientation_chooser.add(_('Landscape'))
        self.paper_orientation_chooser.pack(anchor='w', padx=10, pady=10)
        if self.paper._paper_properties['orientation'] == 'portrait':
            i = 0
        else:
            i = 1
        self.paper_orientation_chooser.invoke(i)
        # full svg or just the filled part
        self.crop_paper_in_svg = Tkinter.IntVar()
        self.crop_paper_in_svg.set(self.paper.get_paper_property('crop_svg'))
        crop = Tkinter.Checkbutton(paper_group,
                                   text=_('Auto crop image in SVG?'),
                                   variable=self.crop_paper_in_svg)
        crop.pack(anchor='w', padx=10, pady=10)
        # crop margin
        margin = self.paper.get_paper_property('crop_margin')
        self.margin_entry = Pmw.Counter(
            paper_group,
            labelpos='w',
            label_text=_("Margin for cropped image (in pixels):"),
            entryfield_value=margin,
            entryfield_validate={
                'validator': 'integer',
                'min': 0,
                'max': 1000
            },
            entry_width=5,
            increment=5,
            datatype='integer')
        self.margin_entry.pack(anchor='w', padx=10, pady=10)

        # DIALOG WIDE PART
        # how to apply?
        apply_group = Pmw.Group(self.body, tag_text=_('Apply'))
        apply_group.pack(fill='x', padx=5, pady=5)
        # apply all or only the changed ones? - it must be created before apply_button because
        # of the callback that operates on activity of apply_button2
        self.apply_button2 = Pmw.RadioSelect(apply_group.interior(),
                                             buttontype='radiobutton',
                                             orient='vertical',
                                             pady=0)
        self.apply_button2.add(_("changed values only"))
        self.apply_button2.add(_("all values"))
        self.apply_button2.invoke(0)
        # apply to current drawing?
        self.apply_button = Pmw.RadioSelect(
            apply_group.interior(),
            buttontype='radiobutton',
            command=self._apply_button_callback,
            orient='vertical',
            pady=0)
        self.apply_button.add(_("to new drawings only"))
        self.apply_button.add(_("to selected and new drawings (no resize)"))
        self.apply_button.add(_("to the whole drawing (no resize)"))
        self.apply_button.invoke(0)
        self.apply_button.pack(padx=0, pady=0, anchor='w')
        # we pack the button2 here to get a better organization
        self.apply_button2.pack(padx=0, pady=10, anchor='w')

        self.pages.setnaturalsize()
Beispiel #2
0
    def __init__(self, parent, items):
        self.items = items
        self.changes_made = 0
        self.parent = parent
        self.dialog = Pmw.Dialog(parent,
                                 buttons=(_('OK'), _('Cancel')),
                                 defaultbutton=_('OK'),
                                 title=_('Configuration'),
                                 command=self.done,
                                 master='parent')
        #parent.bind_all( "<Button-1>", self.raise_me, add='+')
        self.pages = Pmw.NoteBook(self.dialog.interior())
        self.pages.pack(anchor='w', pady=0, padx=0, fill='both', expand=1)

        # create pages for different item types
        self.atom_page = None
        self.bond_page = None
        self.arrow_page = None
        self.text_page = None
        self.plus_page = None
        self.font_page = None
        self.common_page = None
        arrows = []
        for o in items:
            if o.object_type == 'point':
                items.remove(o)
                if o.arrow not in arrows:
                    arrows.append(o.arrow)
        items += arrows
        types = misc.filter_unique([o.object_type for o in items])

        if 'atom' in types:
            self.atom_page = self.pages.add(_('Atom'))
            # charge
            charges = misc.filter_unique(
                [o.charge for o in items if hasattr(o, 'charge')])
            if len(charges) == 1:
                charge = charges[0]
            else:
                charge = ''
            self.atom_charge = Pmw.Counter(self.atom_page,
                                           labelpos='w',
                                           label_text=_('Charge'),
                                           entryfield_value=charge,
                                           entryfield_validate={
                                               'validator': 'integer',
                                               'min': -4,
                                               'max': 4
                                           },
                                           entry_width=3,
                                           increment=1,
                                           datatype='integer')
            self.atom_charge.pack(anchor='nw', padx=10, pady=5)
            # show?
            shows = misc.filter_unique(
                [o.show for o in items if hasattr(o, 'show')])
            if len(shows) == 1:
                show = int(shows[0])
            else:
                show = 2  # means the show should be preserved as is
            self.atom_show = Pmw.OptionMenu(self.atom_page,
                                            labelpos='nw',
                                            label_text=_('Atom name'),
                                            items=(_("don't show"), _("show"),
                                                   u""),
                                            initialitem=show)
            self.atom_show.pack(anchor='nw')
            # positioning
            poss = misc.filter_unique(
                [o.pos for o in items if o.object_type == 'atom'])
            if not poss:
                pos = None
            elif len(poss) == 1 and poss[0]:
                pos = ['center-first', 'center-last'].index(poss[0])
            else:
                pos = 2  # means the centering should be preserved as is
            if pos == None:
                self.atom_pos = None
            else:
                self.atom_pos = Pmw.OptionMenu(
                    self.atom_page,
                    labelpos='nw',
                    label_text=_('Atom positioning'),
                    items=(_("center first letter"), _("center last letter"),
                           u""),
                    initialitem=pos)

                self.atom_pos.pack(anchor='nw')
            # show hydrogens
            shows = misc.filter_unique(
                [o.show_hydrogens for o in items if o.object_type == 'atom'])
            if len(shows) == 1:
                show = shows[0]
            else:
                show = 2  # means the show should be preserved as is
            self.atom_show_h = Pmw.OptionMenu(self.atom_page,
                                              labelpos='nw',
                                              label_text=_('Hydrogens'),
                                              items=(_("off"), _("on"), u""),
                                              initialitem=show)

            self.atom_show_h.pack(anchor='nw')

            # marks
            #self.marks = widgets.GraphicalAngleChooser( self.atom_page, 270)
            #self.marks.pack()

        # BOND
        if 'bond' in types:
            self.bond_page = self.pages.add(_('Bond'))
            # bond_widths (former distances)
            dists = misc.filter_unique(
                map(abs,
                    [o.bond_width for o in items if o.object_type == 'bond']))
            if len(dists) == 1:
                dist = dists[0]
            else:
                dist = ''
            if not misc.split_number_and_unit(dist)[1]:
                dist = str(dist) + 'px'
            self.bond_dist = widgets.WidthChooser(self.bond_page,
                                                  dist,
                                                  label=_('Bond width'))
            self.bond_dist.pack(anchor='ne', padx=10, pady=5)

            # wedge_widths
            dists = misc.filter_unique(
                map(abs,
                    [o.wedge_width for o in items if o.object_type == 'bond']))
            if len(dists) == 1:
                dist = dists[0]
            else:
                dist = ''
            if not misc.split_number_and_unit(dist)[1]:
                dist = str(dist) + 'px'
            self.wedge_width = widgets.WidthChooser(
                self.bond_page, dist, label=_('Wedge/Hatch width'))
            self.wedge_width.pack(anchor='ne', padx=10, pady=5)

            # double bond length ratio
            ratios = misc.filter_unique([
                o.double_length_ratio for o in items if o.object_type == 'bond'
            ])
            if len(ratios) == 1:
                ratio = ratios[0]
            else:
                ratio = ''
            self.double_length_ratio = widgets.RatioCounter(
                self.bond_page, ratio, label=_('Double-bond length ratio'))
            self.double_length_ratio.pack(anchor='nw', padx=10, pady=5)

        # ARROW
        if 'arrow' in types:
            self.arrow_page = self.pages.add(_('Arrow'))
            self.arrow_end_changed = 0
            self.arrow_start_changed = 0
            arrow_items = [o for o in items if o.object_type == 'arrow']

            # arrow start pins
            arrow_starts = misc.filter_unique(
                [o.get_pins()[0] for o in arrow_items])
            self.arrow_start = Tkinter.IntVar()
            if len(arrow_starts) == 1:
                self.arrow_start.set(arrow_starts[0])
            else:
                self.arrow_start.set(0)
            self.arrow_start_entry = Tkinter.Checkbutton(
                self.arrow_page,
                text=_('Arrow-head on start'),
                variable=self.arrow_start,
                command=self._arrow_start_changed)
            self.arrow_start_entry.pack(anchor='w')

            # arrow end pins
            arrow_ends = misc.filter_unique(
                [o.get_pins()[1] for o in arrow_items])
            self.arrow_end = Tkinter.IntVar()
            if len(arrow_ends) == 1:
                self.arrow_end.set(arrow_ends[0])
            else:
                self.arrow_end.set(0)
            self.arrow_end_entry = Tkinter.Checkbutton(
                self.arrow_page,
                text=_('Arrow-head on end'),
                variable=self.arrow_end,
                command=self._arrow_end_changed)
            self.arrow_end_entry.pack(anchor='w')

            # spline?
            splines = misc.filter_unique([o.spline for o in arrow_items])
            self.spline = Tkinter.IntVar()
            if len(splines) == 1:
                self.spline.set(splines[0])
            else:
                self.spline.set(0)
            self.spline_entry = Tkinter.Checkbutton(
                self.arrow_page,
                text=_('Spline arrow'),
                variable=self.spline,
                command=self._spline_changed)
            self.spline_changed = 0
            self.spline_entry.pack(anchor='w')

        # TEXTS

        # PLUS

        # FONT
        font_items = filter(lambda x: hasattr(x, 'font_family'), items)
        if font_items:
            self.font_page = self.pages.add(_('Font'))

            sizes = misc.filter_unique([o.font_size for o in font_items])
            if len(sizes) == 1:
                size = sizes[0]
            else:
                size = ''
            self.font_size = widgets.FontSizeChooser(self.font_page, size)
            self.font_size.pack(anchor='nw')

            used_families = misc.filter_unique(
                [o.font_family for o in font_items])
            if len(used_families) == 1:
                self.used_family = used_families[0]
            else:
                self.used_family = ''
            self.font_family = widgets.FontFamilyChooser(
                self.font_page, self.used_family)
            self.font_family.pack(anchor="nw", side='bottom')

        # COMMON
        self.common_page = self.pages.add(_('Common'))
        line_items = filter(lambda x: hasattr(x, 'line_width'), items)
        if line_items:
            widths = misc.filter_unique([o.line_width for o in line_items])
            if len(widths) == 1:
                width = widths[0]
            else:
                width = ''
            if not misc.split_number_and_unit(width)[1]:
                width = str(width) + 'px'
            self.line_width = widgets.WidthChooser(self.common_page,
                                                   width,
                                                   label=_('Line width'))
            self.line_width.pack(anchor='nw', padx=10, pady=5)

        line_color_items = filter(lambda x: hasattr(x, 'line_color'), items)
        if line_color_items:
            lines = misc.filter_unique(
                [o.line_color for o in line_color_items])
            if len(lines) == 1:
                line = lines[0]
            else:
                line = None
            self.line_color = widgets.ColorButtonWithTransparencyChecker(
                self.common_page, color=line, text=_("Line color"))
            self.line_color.pack(anchor='nw', padx=10, pady=10)

        area_color_items = filter(lambda x: hasattr(x, 'area_color'), items)
        if area_color_items:
            areas = misc.filter_unique(
                [o.area_color for o in area_color_items])
            if len(areas) == 1:
                area = areas[0]
            else:
                area = None
            self.area_color = widgets.ColorButtonWithTransparencyChecker(
                self.common_page, color=area, text=_("Area color"))
            self.area_color.pack(anchor='nw', padx=10, pady=5)

        # RUN IT ALL
        self.pages.setnaturalsize()
        self.dialog.activate(globalMode=0)