# popupmenu class Provides a popup menu.
Inherits
object widget
Description
This widget can be used to display a popup menu.Technically, a popup menu consists of a list of menu items. You add items with insertItem(). An item is either a string or a widget. In addition, items can have an optional icon drawn on the very left side.
Functions
`$insertItem(<text or widget>,[icon id])`
Inserts menu items into a popup menu with optional icon and return the popup identifier.
`$insertWidget(<widget>)`
Inserts widget items int a popup menu and return the popup identifier. The widget is treats as a separator; this means that the item is not selectable and you can, for example, simply insert a label if you need a popup menu with a title.
`$insertHandle(<popupmenu object>,[icon])`
Inserts a submenu with optional icon into the popup menu.
`$exec([widget,x,y])`
If called without paramaters show the popup menu at the current pointer position. With the optional parameters show the popup menu at the coordinate x,y widget parameter relative
`$removeItem(<popup id>)`
Removes the menu item that has the identifier id.
`$removeItemAt(<index>)`
Removes the menu item at position index.
`$insertSeparator(<index>)`
Inserts a separator at position index. If the index is negative the separator becomes the last menu item.
`$activatedEvent()`
This function is called when a menu item and return the the item id. The default implementation emits the $activated() signal.
`$highligthtedEvent()`
This function is called when a menu item is highlighted and return the item id. The default implementation emits the $highlighted() signal.
Signals
`$activated()`
This signal is emitted by the default implementation of [classfnc]activatedEvent[/classfnc]().
`$highlighted()`
This signal is emitted by the default implementation of [classfnc]highlightedEvent[/classfnc](). |-EXAMPLE POPUP MENU-| |--Start: # First of all we create an array wich will be used to create random colors. %Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F) class (ws,widget) { #In the constructor we create everything that belong to the single widget. constructor { #Geometry of the widget and setting-up of layout $$->$setGeometry(%X,%Y,100,100) $$->%lay=$new(layout,$$) #Here we generate a cicle to create our labels inside the widget. %i=0 while (%i<10) { $$->%label=$new(label,$$) $$->%label->$settext("Another class by N\&G") #We set our foreground's coulor using the hex arrey in random way. %color=%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)] $$->%label->$setforegroundcolor(%color) $$->%label->$setautoresize(1) #We add the label to the widget's layout. $$->%lay->$addwidget($$->%label,%i,0) %i++; } #We make the popupmenu relative to this widget: this is merely demonstrative. #because it creates 25 identical popups. $$->%Popupmenu=$new(popupmenu,$$) #we create the label widget wich will be used as popup's title $$->%Popuptitle=$new(label) $$->%Popuptitle->$settext(<B><U>"Windows Options"</B></U>) $$->%Popuptitle->$setAlignment(Center) #and we add it. %A=$$->%Popuptitle $$->%Popupmenu->$insertwidget(%A) #Here we keep the various IDs in the arrays %Tile[%I]=$$->%Popupmenu->$insertItem("Tile",118) %Cascade[%I]=$$->%Popupmenu->$insertItem("Cascade",115) $$->%Popupmenu->$insertSeparator(3) %Closeactw[%I]=$$->%Popupmenu->$insertItem("Close Active Window",08) %Closeallw[%I]=$$->%Popupmenu->$insertItem("Close All Window",58) $$->$show() privateimpl($$->%Popupmenu,activatedEvent) { %id=$0 %i = 0 #with this cicle we control wich of the items has been called comparing the id given back by the event with our arrays created before; while (%i<20) { if (%id == %Tile[%i]) return %Workspace->$tile() if (%id == %Cascade[%i]) return %Workspace->$cascade() if (%id == %Closeactw[%i]) return %Workspace->$closeactivewindow() if (%id == %Closeallw[%i]) return %Workspace->$closeallwindows() %i ++ } } } #we activate the popup pushing the right mouse button on the widget mousepressevent { if ($0 == 1) $$->%Popupmenu->$exec() } } %Workspace=$new(workspace) %Workspace->$resize(640,480) %I=0 %Cicle=1 while (%I<20) { %X=$rand(500) %Y=$rand(480) %Widget=$new(ws,%Workspace) %I++ } #Let's show! %Workspace->$show |--End.

Index, Object Classes

KVIrc 3.2.0 Documentation
Generated by root at Tue Dec 4 07:16:18 2007