Defines the GridBox layout from a simple and intuitive ascii art table Pipe "|" is the column separator. Rows are separated by \n . Identical rows are considered as unique bigger rows. Single table cells must contain the 'key' string value of the cont
(self, asciipattern, column_gap=0, row_gap=0)
| 1831 | self.style['grid-row-gap'] = value |
| 1832 | |
| 1833 | def set_from_asciiart(self, asciipattern, column_gap=0, row_gap=0): |
| 1834 | """Defines the GridBox layout from a simple and intuitive ascii art table |
| 1835 | |
| 1836 | Pipe "|" is the column separator. |
| 1837 | Rows are separated by \n . |
| 1838 | Identical rows are considered as unique bigger rows. |
| 1839 | Single table cells must contain the 'key' string value of the contained widgets. |
| 1840 | Column sizes are proportionally applied to the defined grid. |
| 1841 | Columns must be alligned between rows. |
| 1842 | The gap values eventually defined by set_column_gap and set_row_gap are overwritten. |
| 1843 | |
| 1844 | es. |
| 1845 | \"\"\" |
| 1846 | | |label|button | |
| 1847 | | |text | | |
| 1848 | \"\"\" |
| 1849 | |
| 1850 | Args: |
| 1851 | asciipattern (str): The ascii defined grid |
| 1852 | column_gap (int): Percentage value of the total width to be used as gap between columns |
| 1853 | row_gap (int): Percentage value of the total height to be used as gap between rows |
| 1854 | |
| 1855 | """ |
| 1856 | rows = asciipattern.split("\n") |
| 1857 | # remove empty rows |
| 1858 | for r in rows[:]: |
| 1859 | if len(r.replace(" ", "")) < 1: |
| 1860 | rows.remove(r) |
| 1861 | for ri in range(0, len(rows)): |
| 1862 | # slicing row removing the first and the last separators |
| 1863 | rows[ri] = rows[ri][rows[ri].find("|")+1:rows[ri].rfind("|")] |
| 1864 | |
| 1865 | columns = collections.OrderedDict() |
| 1866 | row_count = 0 |
| 1867 | row_defs = collections.OrderedDict() |
| 1868 | row_max_width = 0 |
| 1869 | |
| 1870 | row_sizes = [] |
| 1871 | for ri in range(0, len(rows)): |
| 1872 | if ri > 0: |
| 1873 | if rows[ri] == rows[ri-1]: |
| 1874 | row_sizes[row_count-1] = row_sizes[row_count-1] + 1 # increment identical row count |
| 1875 | continue |
| 1876 | |
| 1877 | row_defs[row_count] = rows[ri].replace(" ","").split("|") |
| 1878 | row_sizes.append(1) |
| 1879 | # placeholder . where cell is empty |
| 1880 | row_defs[row_count] = ['.' if (elem == '') else elem for elem in row_defs[row_count]] |
| 1881 | row_count = row_count + 1 |
| 1882 | row_max_width = max(row_max_width, len(rows[ri])) |
| 1883 | |
| 1884 | i = rows[ri].find("|",0) |
| 1885 | while i > -1: |
| 1886 | columns[i] = i |
| 1887 | i = rows[ri].find("|", i+1) |
| 1888 | |
| 1889 | columns[row_max_width] = row_max_width |
| 1890 |
no test coverage detected