@@ -549,14 +549,46 @@ def table_html_header(self, columns, table_uid, border_style):
549
549
"""Helper method for print_table() method
550
550
551
551
Return html <thead><tr><th> row for the table header
552
+
552
553
Args:
553
554
columns (list[str]): list of column names
554
555
table_uid (str): a unique ID for this table's CSS classes
556
+ border_style (str): CSS border style string for table cells
555
557
558
+ Returns:
559
+ str: HTML string containing the table header row
560
+
561
+ Examples:
562
+ ```python
563
+ output = pyrevit.output.get_output()
564
+
565
+ # Basic usage - called internally by print_table()
566
+ columns = ["Name", "Age", "City"]
567
+ table_uid = 1
568
+ border_style = "border: 1px solid black;"
569
+ header_html = output.table_html_header(
570
+ columns, table_uid, border_style)
571
+ # Returns: "<thead><tr style='border: 1px solid black;'>" \
572
+ # "<th class='head_title-1-0' align='left'>Name</th>" \
573
+ # "<th class='head_title-1-1' align='left'>Age</th>" \
574
+ # "<th class='head_title-1-2' align='left'>City</th>" \
575
+ # "</tr></thead>"
576
+
577
+ # Without border style
578
+ header_html = output.table_html_header(
579
+ columns, table_uid, "")
580
+ # Returns: "<thead><tr>" \
581
+ # "<th class='head_title-1-0' align='left'>Name</th>" \
582
+ # "<th class='head_title-1-1' align='left'>Age</th>" \
583
+ # "<th class='head_title-1-2' align='left'>City</th>" \
584
+ # "</tr></thead>"
585
+ ```
556
586
"""
557
587
html_head = "<thead><tr {}>" .format (border_style )
558
588
for i , c in enumerate (columns ):
559
- html_head += "<th class='head_title-{}-{}' align='left'>{}</th>" .format (table_uid , i , c )
589
+ html_head += \
590
+ "<th class='head_title-{}-{}' align='left'>{}</th>" .format (
591
+ table_uid , i , c )
560
592
# pyRevit original print_table uses align='left'.
561
593
# This is now overridden by CSS if specified
562
594
html_head += "</tr></thead>"
@@ -565,25 +597,59 @@ def table_html_header(self, columns, table_uid, border_style):
565
597
566
598
567
599
def table_check_input_lists (self ,
568
- table_data ,
569
- columns ,
570
- formats ,
571
- input_kwargs ):
600
+ table_data ,
601
+ columns ,
602
+ formats ,
603
+ input_kwargs ):
572
604
"""Helper method for print_table() method
573
605
574
606
Check that the table_data is present and is a list
575
607
Check that table_data rows are of the same length
576
- Check that all print_table() kwargs of type list are of the right length
608
+ Check that all print_table() kwargs of type list are of correct length
577
609
578
610
Args:
579
- table_data(iterable[ Any]]): The whole table data
580
- columns (list[str]): columns
581
- formats (list[str]): formats
582
- input_kwargs (iterable[ Any]]): list of arg lists
611
+ table_data (list[list[ Any]]): The whole table data as 2D list
612
+ columns (list[str]): list of column names
613
+ formats (list[str]): list of format strings for each column
614
+ input_kwargs (list[list[ Any]]): list of additional argument lists
583
615
584
- Return:
585
- True if input lists are OK to proceed to build the table
586
- False if not, with a relevant warning message
616
+ Returns:
617
+ tuple: (bool, str) - (True/False, message) indicating result
618
+
619
+ Examples:
620
+ ```python
621
+ output = pyrevit.output.get_output()
622
+
623
+ # Valid table data
624
+ table_data = [["John", 25, "NYC"], ["Jane", 30, "LA"]]
625
+ columns = ["Name", "Age", "City"]
626
+ formats = ["", "{} years", ""]
627
+ input_kwargs = [["left", "center", "right"],
628
+ ["100px", "80px", "120px"]]
629
+
630
+ is_valid, message = output.table_check_input_lists(
631
+ table_data, columns, formats, input_kwargs)
632
+ # Returns: (True, "Inputs OK")
633
+
634
+ # Invalid - mismatched column count
635
+ table_data = [["John", 25], ["Jane", 30, "LA"]] # Inconsistent
636
+ is_valid, message = output.table_check_input_lists(
637
+ table_data, columns, formats, input_kwargs)
638
+ # Returns: (False, "Not all rows of table_data are of "
639
+ # "equal length")
640
+
641
+ # Invalid - wrong number of columns
642
+ columns = ["Name", "Age"] # Only 2 columns but data has 3
643
+ is_valid, message = output.table_check_input_lists(
644
+ table_data, columns, formats, input_kwargs)
645
+ # Returns: (False, "Column head list length not equal "
646
+ # "to data row")
647
+
648
+ # Invalid - empty table data
649
+ is_valid, message = output.table_check_input_lists(
650
+ [], columns, formats, input_kwargs)
651
+ # Returns: (False, "No table_data list")
652
+ ```
587
653
"""
588
654
589
655
# First check positional and named keyword args
@@ -607,24 +673,24 @@ def table_check_input_lists(self,
607
673
608
674
# Next check **kwargs
609
675
# Loop through the lists and return if not a list or len not equal
610
- for l in input_kwargs :
611
- if not l : # No kwarg is OK beacause they are optional
676
+ for kwarg_list in input_kwargs :
677
+ if not kwarg_list : # No kwarg is OK beacause they are optional
612
678
continue
613
- if not isinstance (l , list ):
614
- return False , "One of the print_table kwargs that should be a list is not a list ({})" .format (l )
615
- if len (l ) != len_data_row :
679
+ if not isinstance (kwarg_list , list ):
680
+ return False , "One of the print_table kwargs that should be a list is not a list ({})" .format (kwarg_list )
681
+ if len (kwarg_list ) != len_data_row :
616
682
return False , "print_table kwarg list length problem (should match {} columns)" .format (len_data_row )
617
683
618
684
return True , "Inputs OK"
619
685
620
686
621
687
def print_table (self ,
622
- table_data ,
623
- columns = None ,
624
- formats = None ,
625
- title = '' ,
626
- last_line_style = '' ,
627
- ** kwargs ):
688
+ table_data ,
689
+ columns = None ,
690
+ formats = None ,
691
+ title = '' ,
692
+ last_line_style = '' ,
693
+ ** kwargs ):
628
694
"""Print provided data in a HTML table in output window.
629
695
The same window can output several tables, each with their own formatting options.
630
696
0 commit comments