예제 #1
0
파일: base.py 프로젝트: minyez/pygraceplot
    def export(self):
        """export all object attributes as a list of string

        Each member is a line in agr file"""
        slist = []
        prefix = deepcopy(self._marker).replace("_", " ")
        try:
            affix = self.__getattribute__('_affix')
            is_p = self.__getattribute__('_is_prefix')
            if is_p:
                prefix = str(affix) + prefix
            else:
                prefix += str(affix)
        except (TypeError, AttributeError):
            pass

        for attr, (typ, _, f) in self._attrs.items():
            attrv = self.__getattribute__(attr)
            if typ in [list, tuple, set]:
                temps = attr.replace("_", " ") + " " + f.format(*attrv)
            # special property marked by the type as bool
            elif typ is bool:
                # for Symbol
                if attr == "type":
                    temps = f.format(attrv)
                # for on off attribute
                if attr.endswith("_switch"):
                    temps = attr.replace("_switch",
                                         "") + " " + Switch.get_str(attrv)
                # for inout attribute
                elif attr.endswith("_pointing"):
                    temps = attr.replace("_pointing",
                                         "") + " " + Pointing.get_str(attrv)
                elif attr.endswith("_placement"):
                    temps = attr.replace("_placement",
                                         "") + " " + Placement.get_str(attrv)
                # for location-like attribute
                elif attr.endswith("_location"):
                    temps = attr.replace("_location",
                                         "") + " " + f.format(*attrv)
                # for arbitray string attribute
                elif attr.endswith("_comment"):
                    temps = attr.replace("_comment", "") + " " + encode_string(
                        f.format(attrv))
                # remove the marker name in the attribute to avoid duplicate
                temps = temps.replace(self._marker, "").replace("_", " ")
            else:
                temps = attr.replace("_", " ") + " " + f.format(attrv)
            s = prefix + " " + temps
            slist.append(s)

        # cover extra lines with an _extra_export attribute
        try:
            slist += self.__getattribute__('_extra_export')
        except (TypeError, AttributeError):
            pass

        return slist
예제 #2
0
 def test_super_or_subscript(self):
     """encoding either super or subscript """
     subs = [
         ("A_{b}", "A\\sb\\N"),
         ("A_{b}C_{d}", "A\\sb\\NC\\sd\\N"),
         ("C^{d}", "C\\Sd\\N"),
         ("A^{b}C_{d}", "A\\Sb\\NC\\sd\\N"),
         ]
     for latex, encoded in subs:
         self.assertEqual(encode_string(latex), encoded)
예제 #3
0
파일: base.py 프로젝트: minyez/pygraceplot
 def export(self):
     slist = _BaseOutput.export(self)
     if self.__getattribute__("spec_type") in ["ticks", "both"]:
         slist.append("{:s} spec {:d}".format(self._marker,
                                              len(self.spec_ticks)))
         for i, (loc, m) in enumerate(zip(self.spec_ticks,
                                          self.spec_majors)):
             slist.append("{:s} {:s} {:d}, {:.3f}".format(
                 self._marker, m, i, loc))
     if self.__getattribute__("spec_type") == "both":
         for i, (label,
                 m) in enumerate(zip(self.spec_labels, self.spec_majors)):
             if m == "major":
                 slist.append("ticklabel {:d}, \"{:s}\"".format(
                     i, encode_string(label)))
     return slist
예제 #4
0
 def test_greek(self):
     """encoding greek"""
     self.assertEqual(encode_string(r"\Gamma \beta"), r"\xG\f{} \xb\f{}")
예제 #5
0
 def test_italic(self):
     """encoding special characters"""
     self.assertEqual(encode_string(r"/this is italic/, this not"),
                      r"\f{Times-Italic}this is italic\f{}, this not")
     self.assertEqual(encode_string(r"/italic here/, /also here/"),
                      r"\f{Times-Italic}italic here\f{}, \f{Times-Italic}also here\f{}")
예제 #6
0
 def test_special(self):
     """encoding special characters"""
     self.assertEqual(encode_string(r"\AA \BB"), r"\cE\C \BB")