Skip to content

Commit

Permalink
AllOcticons page for cells-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandros Tzannes committed Jun 30, 2023
1 parent 406897e commit 9d76a7a
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion object_database/web/cells_demo/octicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
from object_database.web import cells as cells
from object_database.web.CellsTestPage import CellsTestPage

Expand Down Expand Up @@ -52,3 +52,80 @@ def cell(self):

def text(self):
return "You should see an octicon. Clicking on the button shouldn't crash us."


class AllOcticons(CellsTestPage):
def cell(self):
# Open CSS file and find the octicons we know about. Their names are between
# the following two "anchors"
leftAnchor = ".octicon-"
rightAnchor = ":before{content"

ownDir = os.path.dirname(os.path.abspath(__file__))
octiconCssPath = os.path.abspath(
os.path.join(
ownDir, "..", "..", "web", "content", "dependencies", "octicons.min.css"
)
)
with open(octiconCssPath, "r") as fd:
octiconCssText = fd.read()

octiconCells = []
for octiconText in octiconCssText.split(leftAnchor)[1:]:
if rightAnchor in octiconText:
octicon = octiconText.split(rightAnchor)[0]
octiconCells.append(
cells.HorizontalSequence(
[
# cells.Sized(height=100, width=100) *
cells.Octicon(
octicon, color="black", hoverText=octicon, small=True
),
cells.Padding(padding=10),
# cells.Sized(height=100, width=100) *
# cells.Text(octicon, fontSize=20),
cells.Text(octicon),
]
)
)

# Arrange sequence of octicons into a grid iterating "vertically" one column at a time
columnWidth = 8

rowCount = len(octiconCells) // columnWidth
if len(octiconCells) % columnWidth != 0:
rowCount += 1

rows = [[] for _ in range(rowCount)]

rowIx = 0
colIx = 0
for octiconCell in octiconCells:
rows[rowIx].append(octiconCell)
rowIx += 1
if rowIx == rowCount:
rowIx = 0
colIx += 1

while rowIx < rowCount:
rows[rowIx].append(None)
rowIx += 1
if rowIx == rowCount:
colIx += 1

assert colIx == columnWidth, (colIx, columnWidth)

rows = [tuple(row) for row in rows]

table = cells.Table(
colFun=lambda: list(range(columnWidth)),
rowFun=lambda: rows,
headerFun=lambda x: x,
rendererFun=lambda row, col: row[col],
maxRowsPerPage=1000,
)

return cells.Scrollable(table)

def text(self):
return "You should see ALL known octicons."

0 comments on commit 9d76a7a

Please sign in to comment.