예제 #1
0
    def copy_lines(self) -> Dict[int, SccCaptionLine]:
        """Copy paragraph lines (without time attributes)"""
        lines_copy = {}
        for row, orig_line in self._caption_lines.items():
            new_line = SccCaptionLine(orig_line.get_row(),
                                      orig_line.get_indent())

            for orig_text in orig_line.get_texts():
                new_text = SccCaptionText(orig_text.get_text())
                new_line.add_text(new_text)
            lines_copy[row] = new_line

        return lines_copy
예제 #2
0
 def get_line_right_offset(line: SccCaptionLine) -> int:
     return SCC_ROOT_CELL_RESOLUTION_COLUMNS - (line.get_indent() +
                                                line.get_length())
예제 #3
0
 def new_caption_line(self):
     """Appends a new caption text content, and keeps reference on it"""
     self._caption_lines[self._cursor[0]] = SccCaptionLine(
         self._cursor[0], self._cursor[1])
     self._current_line = self._caption_lines[self._cursor[0]]
예제 #4
0
  def test_line(self):
    row = 6
    indent = 2
    caption_line = SccCaptionLine(row, indent)

    self.assertEqual(row, caption_line.get_row())
    self.assertEqual(indent, caption_line.get_indent())

    caption_line.set_row(7)
    caption_line.indent(2)

    self.assertEqual(7, caption_line.get_row())
    self.assertEqual(4, caption_line.get_indent())

    self.assertIsNone(caption_line.get_current_text())
    self.assertEqual(0, caption_line.get_cursor())
    self.assertEqual(0, caption_line.get_length())
    self.assertTrue(caption_line.is_empty())
    self.assertListEqual([], caption_line.get_texts())

    caption_line.set_cursor(10)
    self.assertEqual(0, caption_line.get_cursor())

    caption_line.add_text("Hello ")
    caption_text = caption_line.get_current_text()

    self.assertIsNotNone(caption_text)
    self.assertEqual("Hello ", caption_text.get_text())
    self.assertEqual(6, caption_text.get_cursor())
    self.assertEqual(6, caption_text.get_length())

    self.assertEqual(6, caption_line.get_cursor())
    self.assertEqual(6, caption_line.get_length())
    self.assertListEqual([caption_text], caption_line.get_texts())

    another_caption_text = SccCaptionText("World!")

    caption_line.add_text(another_caption_text)

    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual("World!", another_caption_text.get_text())
    self.assertEqual(6, another_caption_text.get_cursor())
    self.assertEqual(6, another_caption_text.get_length())

    self.assertEqual(12, caption_line.get_cursor())
    self.assertEqual(12, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.set_cursor(6)
    self.assertEqual(another_caption_text, caption_line.get_current_text())

    caption_line.add_text("hello")

    self.assertEqual("hello!", another_caption_text.get_text())
    self.assertEqual(5, another_caption_text.get_cursor())
    self.assertEqual(6, another_caption_text.get_length())

    self.assertEqual(11, caption_line.get_cursor())
    self.assertEqual(12, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.set_cursor(5)
    self.assertEqual(caption_text, caption_line.get_current_text())
    self.assertEqual(5, caption_text.get_cursor())

    caption_line.add_text(", abcd")

    self.assertEqual("Hello,", caption_text.get_text())
    self.assertEqual(6, caption_text.get_cursor())
    self.assertEqual(6, caption_text.get_length())

    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual(" abcd!", another_caption_text.get_text())
    self.assertEqual(5, another_caption_text.get_cursor())
    self.assertEqual(6, another_caption_text.get_length())

    self.assertEqual(11, caption_line.get_cursor())
    self.assertEqual(12, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.set_cursor(7)
    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual(1, another_caption_text.get_cursor())

    caption_line.add_text("123456789")

    self.assertEqual(another_caption_text, caption_line.get_current_text())
    self.assertEqual(" 123456789", another_caption_text.get_text())
    self.assertEqual(10, another_caption_text.get_cursor())
    self.assertEqual(10, another_caption_text.get_length())

    self.assertEqual(16, caption_line.get_cursor())
    self.assertEqual(16, caption_line.get_length())
    self.assertListEqual([caption_text, another_caption_text], caption_line.get_texts())

    caption_line.clear()
    self.assertEqual(0, caption_line.get_cursor())
    self.assertEqual(0, caption_line.get_length())
    self.assertListEqual([], caption_line.get_texts())
예제 #5
0
  def test_line_text_leading_and_trailing_spaces(self):
    line = SccCaptionLine(0, 0)
    line.add_text("123")
    self.assertEqual(0, line.get_leading_spaces())
    self.assertEqual(0, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text("   123")
    self.assertEqual(3, line.get_leading_spaces())
    self.assertEqual(0, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text("123   ")
    self.assertEqual(0, line.get_leading_spaces())
    self.assertEqual(3, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text(" 123  ")
    self.assertEqual(1, line.get_leading_spaces())
    self.assertEqual(2, line.get_trailing_spaces())

    line = SccCaptionLine(0, 0)
    line.add_text("   ")
    line.add_text(SccCaptionText(" 123 "))
    line.add_text(SccCaptionText(" "))
    line.add_text(SccCaptionText("  "))
    self.assertEqual(4, line.get_leading_spaces())
    self.assertEqual(4, line.get_trailing_spaces())