Provide right click option to hwtk component table cell

Jouher_20929
Jouher_20929 Altair Community Member
edited October 2020 in Community Q&A

how to provide  options to hwtk component table cell while right clicking a cell? 

@tinh Please help

Answers

  • tinh
    tinh Altair Community Member
    edited January 2019

    From HM14, a menu is attached to table cell as default, but to show it, use option -cellmenucommand

    You have to provide a tcl proc (not menu name)

    Purpose of that proc is to customize the cell menu (already created as default, you don't need to create it)

    That proc accepts %M as argument to refer cell menu name, then you can use it to add or remove menu commands suitable with each cell type

     

    Example

    hwtk::table .myTable -cellmenucommand {p_PrepareMenu %M %C}

    .myTable columncreate name -text name

    .myTable columncreate id -text id

    .myTable rowinsert end row1 -values {name comp1 id 1001}

    .myTable rowinsert end row2 -values {name comp2 id 3000}

     

    proc p_PrepareMenu {mnu column} {

       $mnu delete 0 end

       switch -- $column {

             name {

                  $mnu add command -label Rename

             }

             id {

                  $mnu add command -label Renumber

             }

        }

    }

     

     

     

     

     

     

    As I see, when creating hwtk table, option -menu will attach a menu with event 'right click' on header of column 0

     

     

    When creating a column, option -headermenu will attach a menu with event 'right click' on header of that column.

     

     

     

     

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited January 2019

    Hi Tin,

     

    I am getting error on '$mnu delete 0 end'

     

    image.png.81eb99559c3057c3d06ad81923c9b516.png

     

     

     

     

    and I am getting error on

     $mnu add command -label Rename

     

     

    image.png.b79bf45cb8c24333e4e2237f0a34ea67.png

     

     

     

    @tinh Pls help

     

     

  • tinh
    tinh Altair Community Member
    edited January 2019

    It is hwtk menu

    Refer to hwtk gui to see its method

  • tinh
    tinh Altair Community Member
    edited January 2019

    Because it's a hwtk menu, sub commands 'delete' and 'add' are changed to methods 'clear' and 'item'

    proc p_PrepareMenu {mnu column} {

       $mnu clear

       switch -- $column {

             name {

                  $mnu item Rename -caption Rename -command {puts 'write a proc to rename comp'}

             }

             id {

                  $mnu item Renumber -caption Renumber -command {puts 'write a proc to renumber comp'}

             }

        }

    }