Beispiel #1
0
 def close_pattern(self):
     if self.pattern_established:
         self.pattern_established = False
         if self.pattern_end is not None:
             write_string_utf8(
                 self.f, self.pattern_end.format_map(self.format_dictionary)
             )
Beispiel #2
0
 def open_pattern(self):
     if not self.pattern_established:
         self.pattern_established = True
         if self.pattern_start is not None:
             write_string_utf8(
                 self.f, self.pattern_start.format_map(self.format_dictionary)
             )
Beispiel #3
0
 def write_opens(self):
     if self.document_opening:
         self.document_opening = False
         if self.document_start is not None:
             write_string_utf8(self.f, self.document_start.format_map(self.format_dictionary))
     if self.color_opening:
         self.color_opening = False
         if self.color_join is not None and self.color_index != 0:
             write_string_utf8(self.f, self.color_join.format_map(self.format_dictionary))
         if self.color_start is not None:
             write_string_utf8(self.f, self.color_start.format_map(self.format_dictionary))
     if self.block_opening:
         self.block_opening = False
         if self.block_join is not None and self.block_index != 0:
             write_string_utf8(self.f, self.block_join.format_map(self.format_dictionary))
         if self.block_start is not None:
             write_string_utf8(self.f, self.block_start.format_map(self.format_dictionary))
Beispiel #4
0
    def write_segment(self, segment):
        # SEGMENT
        if self.segment_start is not None:
            write_string_utf8(self.f, self.segment_start.format_map(self.format_dictionary))

        write_string_utf8(self.f, segment.format_map(self.format_dictionary))

        # SEGMENT JOIN
        if self.segment_join is not None:
            write_string_utf8(self.f, self.segment_join.format_map(self.format_dictionary))

        # SEGMENT_END
        if self.segment_end is not None:
            write_string_utf8(self.f, self.segment_end.format_map(self.format_dictionary))
Beispiel #5
0
 def write_closes(self):
     if self.block_closing:
         self.block_closing = False
         if self.block_end is not None:
             write_string_utf8(self.f, self.block_end.format_map(self.format_dictionary))
     if self.color_closing:
         self.color_closing = False
         if self.color_end is not None:
             write_string_utf8(self.f, self.color_end.format_map(self.format_dictionary))
     if self.document_closing:
         self.document_closing = False
         if self.document_end is not None:
             write_string_utf8(self.f, self.document_end.format_map(self.format_dictionary))
Beispiel #6
0
    def write(self):
        pattern = self.pattern
        f = self.f
        settings = self.settings

        if settings is None:
            return

        # DOCUMENT STATISTICS
        self.set_document_statistics()

        self.open_pattern()
        if self.metadata_entry is not None:
            for i, key in enumerate(pattern.extras):
                value = pattern.extras[key]
                self.format_dictionary.update({
                    "metadata_index": i,
                    "metadata_key": str(key),
                    "metadata_value": str(value),
                })
                write_string_utf8(
                    self.f, self.metadata_entry.format_map(self.format_dictionary)
                )

        if self.thread_entry is not None:
            for i, thread in enumerate(pattern.threadlist):
                self.format_dictionary.update({
                    "thread_index": i,
                    "thread_color": thread.hex_color(),
                    "thread_description": thread.description,
                    "thread_brand": thread.brand,
                    "thread_catalog_number": thread.catalog_number,
                    "thread_chart": thread.chart,
                    "thread_details": thread.details,
                    "thread_weight": thread.weight,
                    "thread_red": thread.get_red(),
                    "thread_green": thread.get_green(),
                    "thread_blue": thread.get_blue(),
                })
                write_string_utf8(
                    self.f, self.thread_entry.format_map(self.format_dictionary)
                )
        for self.command_index in range(0, len(pattern.stitches)):
            self.update_command()
            write_segment = self.get_write_segment(self.cmd)

            # MAIN CODE, there is something to write.
            if write_segment is not None:
                self.update_positions(self.x, self.y, self.cmd)
                if self.cmd == SEQUIN_MODE:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # SEQUIN
                if self.cmd == SEQUIN_EJECT:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # STITCH
                if self.cmd == STITCH:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # TRIM
                if self.cmd == TRIM:
                    self.open_document()
                    self.open_color()

                # JUMP
                if self.cmd == JUMP:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # COLOR CHANGE
                if self.cmd == COLOR_CHANGE:
                    self.open_document()

                # NEEDLE SET
                if self.cmd == NEEDLE_SET:
                    self.open_document()
                    self.open_color()

                # STOP COMMAND
                if self.cmd == STOP:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # SLOW COMMAND
                if self.cmd == SLOW:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # FAST COMMAND
                if self.cmd == FAST:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                # END COMMAND
                if self.cmd == END:
                    self.open_document()
                    self.open_color()
                    self.open_block()

                self.write_opens()
                self.write_segment(write_segment)

                if self.cmd == SEQUIN_MODE:
                    pass

                # SEQUIN
                if self.cmd == SEQUIN_EJECT:
                    pass

                # STITCH
                if self.cmd == STITCH:
                    pass

                # TRIM
                if self.cmd == TRIM:
                    self.close_block()

                # JUMP
                if self.cmd == JUMP:
                    pass

                # COLOR CHANGE
                if self.cmd == COLOR_CHANGE:
                    self.close_block()
                    self.close_color()

                # NEEDLE SET
                if self.cmd == NEEDLE_SET:
                    pass

                # STOP COMMAND
                if self.cmd == STOP:
                    pass

                # SLOW COMMAND
                if self.cmd == SLOW:
                    pass

                # FAST COMMAND
                if self.cmd == FAST:
                    pass

                # END COMMAND
                if self.cmd == END:
                    self.close_block()
                    self.close_color()
                    self.close_document()
                self.write_closes()

        self.close_block()
        self.close_color()
        self.close_document()
        self.close_pattern()