<s> """<STR_LIT>""" <EOL> import layouts <EOL> import pyui <EOL> from pyui . desktop import getDesktop , getTheme , getRenderer <EOL> from pyui . base import Base , Panel , Window <EOL> class Label ( Base ) : <EOL> """<STR_LIT>""" <EOL> widgetLabel = "<STR_LIT>" <EOL> LEFT = <NUM_LIT:0> <EOL> RIGHT = <NUM_LIT:1> <EOL> CENTER = <NUM_LIT:2> <EOL> def __init__ ( self , text , color = None , font = None , shadow = <NUM_LIT:0> , align = <NUM_LIT:0> ) : <EOL> Base . __init__ ( self ) <EOL> self . font = font <EOL> self . shadow = shadow <EOL> self . align = align <EOL> if color : <EOL> self . color = color <EOL> else : <EOL> self . color = self . fgColor <EOL> self . setText ( text ) <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> getTheme ( ) . drawLabel ( self . windowRect , self . text , color = self . color , font = self . font , shadow = self . shadow , align = self . align ) <EOL> def setText ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . text = text <EOL> if len ( text ) == <NUM_LIT:0> : <EOL> text = "<STR_LIT:U+0020>" <EOL> ( self . width , self . height ) = getRenderer ( ) . getTextSize ( text ) <EOL> self . setDirty ( ) <EOL> def setColor ( self , color = None ) : <EOL> if color == None : <EOL> self . color = self . fgColor <EOL> else : <EOL> self . color = color <EOL> self . setDirty ( ) <EOL> class Picture ( Base ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename , pieceRect = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) ) : <EOL> Base . __init__ ( self ) <EOL> self . setFilename ( filename ) <EOL> self . tooltipText = self . filename <EOL> self . pieceRect = pieceRect <EOL> def setRotation ( self , irotationDeg ) : <EOL> self . irotationDegrees = irotationDeg <EOL> def draw ( self , renderer ) : <EOL> if self . show and self . filename : <EOL> renderer . drawImage ( self . windowRect , self . filename , self . pieceRect ) <EOL> def setFilename ( self , filename ) : <EOL> self . filename = filename <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def setPiece ( self , x , y , w , h ) : <EOL> self . pieceRect = ( x , y , w , h ) <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> class Button ( Base ) : <EOL> """<STR_LIT>""" <EOL> widgetLabel = "<STR_LIT>" <EOL> IDLE = <NUM_LIT:0> <EOL> ROLLOVER = <NUM_LIT:1> <EOL> DOWN = <NUM_LIT:2> <EOL> canTab = <NUM_LIT:1> <EOL> def __init__ ( self , text , handler = None , font = None , shadow = <NUM_LIT:0> , fgColor = None , bgColor = None , roColor = None ) : <EOL> Base . __init__ ( self ) <EOL> self . handler = handler <EOL> self . font = font <EOL> self . shadow = shadow <EOL> self . fgColor = fgColor <EOL> self . bgColor = bgColor <EOL> self . roColor = roColor <EOL> self . setText ( text ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . KEYDOWN , self . _pyuiKeyDown ) <EOL> self . registerEvent ( pyui . locals . KEYUP , self . _pyuiKeyUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> self . registerEvent ( pyui . locals . CLICKED , self . _pyuiClicked ) <EOL> self . status = Button . IDLE <EOL> self . capture = <NUM_LIT:0> <EOL> self . enabled = <NUM_LIT:1> <EOL> self . tooltipText = text <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> getTheme ( ) . drawButton ( self . windowRect , self . text , self . hasFocus ( ) , self . status , self . enabled , self . font , <EOL> self . shadow , self . fgColor , self . bgColor , self . roColor ) <EOL> def setText ( self , text , dontResize = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . text = text <EOL> if len ( text ) < <NUM_LIT:1> : <EOL> text = "<STR_LIT:U+0020>" <EOL> if not dontResize : <EOL> if self . font : <EOL> font = self . font <EOL> else : <EOL> font = getTheme ( ) . defaultFont <EOL> size = getRenderer ( ) . getTextSize ( "<STR_LIT:U+0020>" + text + "<STR_LIT:U+0020>" , font ) <EOL> self . resize ( size [ <NUM_LIT:0> ] , int ( size [ <NUM_LIT:1> ] * <NUM_LIT> ) ) <EOL> def getText ( self ) : <EOL> return self . text <EOL> def _pyuiClicked ( self , event ) : <EOL> if event . id == self . id and self . handler : <EOL> self . handler ( self ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . capture : <EOL> if self . hit ( event . pos ) : <EOL> if self . status != Button . DOWN : <EOL> self . status = Button . DOWN <EOL> self . setDirty ( ) <EOL> else : <EOL> if self . status == Button . DOWN : <EOL> self . status = Button . ROLLOVER <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if self . hit ( event . pos ) : <EOL> if self . status != Button . ROLLOVER : <EOL> getDesktop ( ) . getTheme ( ) . setButtonCursor ( ) <EOL> self . status = Button . ROLLOVER <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:0> <EOL> else : <EOL> if self . status == Button . ROLLOVER : <EOL> getDesktop ( ) . getTheme ( ) . setArrowCursor ( ) <EOL> self . status = Button . IDLE <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> if not self . enabled : <EOL> return <NUM_LIT:1> <EOL> self . status = Button . DOWN <EOL> self . getFocus ( ) <EOL> self . capture = <NUM_LIT:1> <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if self . capture : <EOL> self . capture = <NUM_LIT:0> <EOL> if self . status == Button . DOWN and self . enabled : <EOL> self . postEvent ( pyui . locals . CLICKED ) <EOL> self . status = Button . IDLE <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiKeyDown ( self , event ) : <EOL> if not self . hasFocus ( ) : <EOL> return <NUM_LIT:0> <EOL> if event . key == pyui . locals . K_SPACE and self . enabled : <EOL> self . status = Button . DOWN <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiKeyUp ( self , event ) : <EOL> if not self . hasFocus ( ) : <EOL> return <NUM_LIT:0> <EOL> if event . key == pyui . locals . K_SPACE and self . enabled : <EOL> self . postEvent ( pyui . locals . CLICKED ) <EOL> self . status = Button . IDLE <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def enable ( self ) : <EOL> self . enabled = <NUM_LIT:1> <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def disable ( self ) : <EOL> self . enabled = <NUM_LIT:0> <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> class ImageButton ( Button ) : <EOL> """<STR_LIT>""" <EOL> widgetLabel = "<STR_LIT>" <EOL> def __init__ ( self , filename , handler , text = "<STR_LIT>" , ghostFilename = "<STR_LIT>" ) : <EOL> Button . __init__ ( self , text , handler ) <EOL> self . filename = filename <EOL> self . ghostFilename = ghostFilename <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> if self . enabled or self . ghostFilename == "<STR_LIT>" : <EOL> getTheme ( ) . drawImageButton ( self . windowRect , self . filename , self . text , self . hasFocus ( ) , self . status ) <EOL> else : <EOL> getTheme ( ) . drawImageButton ( self . windowRect , self . ghostFilename , self . text , self . hasFocus ( ) , self . status ) <EOL> def setFilename ( self , filename ) : <EOL> self . filename = filename <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> class Edit ( Base ) : <EOL> """<STR_LIT>""" <EOL> canTab = <NUM_LIT:1> <EOL> widgetLabel = "<STR_LIT>" <EOL> def __init__ ( self , text , max , handler ) : <EOL> Base . __init__ ( self ) <EOL> self . handler = handler <EOL> self . caretPos = None <EOL> self . selectPos = None <EOL> self . setText ( text ) <EOL> self . dragging = <NUM_LIT:0> <EOL> self . max = max <EOL> self . resize ( self . width , int ( getTheme ( ) . defaultTextHeight * <NUM_LIT> ) ) <EOL> self . registerEvent ( pyui . locals . KEYDOWN , self . _pyuiKeyDown ) <EOL> self . registerEvent ( pyui . locals . CHAR , self . _pyuiChar ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> self . registerEvent ( pyui . locals . CLICKED , self . _pyuiClicked ) <EOL> def draw ( self , renderer ) : <EOL> getTheme ( ) . drawEdit ( self . windowRect , self . text , self . hasFocus ( ) , self . caretPos , self . selectPos ) <EOL> def setText ( self , text ) : <EOL> """<STR_LIT>""" <EOL> if not text : <EOL> self . text = "<STR_LIT>" <EOL> self . caretPos = <NUM_LIT:0> <EOL> self . selectPos = <NUM_LIT:0> <EOL> return <EOL> self . text = text <EOL> self . caretPos = len ( text ) <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> def loseFocus ( self ) : <EOL> Base . loseFocus ( self ) <EOL> self . caretPos = <NUM_LIT:0> <EOL> self . selectPos = <NUM_LIT:0> <EOL> def getFocus ( self ) : <EOL> Base . getFocus ( self ) <EOL> self . selectPos = len ( self . text ) <EOL> self . caretPos = len ( self . text ) <EOL> def findMousePos ( self , pos ) : <EOL> x = pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] <EOL> y = pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] <EOL> l , r = <NUM_LIT:0> , len ( self . text ) <EOL> c = <NUM_LIT:0> <EOL> while l < r : <EOL> c = ( l + r + <NUM_LIT:1> ) / <NUM_LIT:2> <EOL> w = getRenderer ( ) . getTextSize ( self . text [ l : c ] ) [ <NUM_LIT:0> ] <EOL> if x >= w : <EOL> l = c <EOL> x -= w <EOL> else : <EOL> if r == c : <EOL> if x > w / <NUM_LIT:2> : <EOL> l = l + <NUM_LIT:1> <EOL> break <EOL> r = c <EOL> return l <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> self . getFocus ( ) <EOL> self . caretPos = self . findMousePos ( event . pos ) <EOL> self . selectPos = self . caretPos <EOL> self . dragging = <NUM_LIT:1> <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if not self . dragging : <EOL> return <NUM_LIT:0> <EOL> self . caretPos = self . findMousePos ( event . pos ) <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if not self . dragging : <EOL> return <NUM_LIT:0> <EOL> self . caretPos = self . findMousePos ( event . pos ) <EOL> self . dragging = <NUM_LIT:0> <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> def _pyuiClicked ( self , event ) : <EOL> if event . id == self . id : <EOL> ret = <NUM_LIT:0> <EOL> if self . handler : <EOL> ret = self . handler ( self ) <EOL> return ret <EOL> def deleteSelected ( self ) : <EOL> if self . selectPos == self . caretPos : <EOL> return <EOL> if self . caretPos > self . selectPos : <EOL> ( self . caretPos , self . selectPos ) = ( self . selectPos , self . caretPos ) <EOL> self . text = self . text [ : self . caretPos ] + self . text [ self . selectPos : ] <EOL> self . setDirty ( ) <EOL> self . selectPos = self . caretPos <EOL> def _pyuiKeyDown ( self , event ) : <EOL> if not self . hasFocus ( ) : <EOL> return <NUM_LIT:0> <EOL> if event . key == pyui . locals . K_LEFT : <EOL> if self . caretPos > <NUM_LIT:0> : <EOL> self . caretPos -= <NUM_LIT:1> <EOL> if ( event . mods & pyui . locals . MOD_CONTROL ) : <EOL> while self . caretPos > <NUM_LIT:0> and self . text [ self . caretPos - <NUM_LIT:1> ] . isspace ( ) : <EOL> self . caretPos -= <NUM_LIT:1> <EOL> while self . caretPos > <NUM_LIT:0> and not self . text [ self . caretPos - <NUM_LIT:1> ] . isspace ( ) : <EOL> self . caretPos -= <NUM_LIT:1> <EOL> if not ( event . mods & pyui . locals . MOD_SHIFT ) : <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if event . key == pyui . locals . K_RIGHT : <EOL> if self . caretPos < len ( self . text ) : <EOL> self . caretPos += <NUM_LIT:1> <EOL> if ( event . mods & pyui . locals . MOD_CONTROL ) : <EOL> while self . caretPos < len ( self . text ) and not self . text [ self . caretPos ] . isspace ( ) : <EOL> self . caretPos += <NUM_LIT:1> <EOL> while self . caretPos < len ( self . text ) and self . text [ self . caretPos ] . isspace ( ) : <EOL> self . caretPos += <NUM_LIT:1> <EOL> if not ( event . mods & pyui . locals . MOD_SHIFT ) : <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if event . key == pyui . locals . K_HOME : <EOL> self . caretPos = <NUM_LIT:0> <EOL> if not ( event . mods & pyui . locals . MOD_SHIFT ) : <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if event . key == pyui . locals . K_END : <EOL> self . caretPos = len ( self . text ) <EOL> if not ( event . mods & pyui . locals . MOD_SHIFT ) : <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if event . key == pyui . locals . K_BACKSPACE : <EOL> if self . selectPos != self . caretPos : <EOL> self . deleteSelected ( ) <EOL> elif self . caretPos > <NUM_LIT:0> : <EOL> self . text = self . text [ : self . caretPos - <NUM_LIT:1> ] + self . text [ self . caretPos : ] <EOL> self . caretPos -= <NUM_LIT:1> <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if event . key == pyui . locals . K_DELETE : <EOL> if self . selectPos != self . caretPos : <EOL> self . deleteSelected ( ) <EOL> elif self . caretPos < len ( self . text ) : <EOL> self . text = self . text [ : self . caretPos ] + self . text [ self . caretPos + <NUM_LIT:1> : ] <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> if event . key == pyui . locals . K_RETURN : <EOL> self . postEvent ( pyui . locals . CLICKED ) <EOL> return <NUM_LIT:1> <EOL> if event . key >= <NUM_LIT:32> and event . key < <NUM_LIT> : <EOL> self . text = self . text [ : self . caretPos ] + chr ( event . key ) + self . text [ self . caretPos : ] <EOL> self . caretPos += <NUM_LIT:1> <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiChar ( self , event ) : <EOL> if not self . hasFocus ( ) : <EOL> return <NUM_LIT:0> <EOL> if ord ( event . key ) < <NUM_LIT:32> or ord ( event . key ) > <NUM_LIT> : <EOL> return <NUM_LIT:0> <EOL> if self . caretPos != self . selectPos : <EOL> self . deleteSelected ( ) <EOL> if len ( self . text ) > self . max : <EOL> return <NUM_LIT:1> <EOL> self . text = self . text [ : self . caretPos ] + event . key + self . text [ self . caretPos : ] <EOL> self . caretPos += <NUM_LIT:1> <EOL> self . selectPos = self . caretPos <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> class NumberEdit ( Edit ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text , max , handler , allowDecimels ) : <EOL> Edit . __init__ ( self , text , max , handler ) <EOL> self . allowDecimels = allowDecimels <EOL> self . getValue ( ) <EOL> def _pyuiChar ( self , event ) : <EOL> if not self . hasFocus ( ) : <EOL> return <NUM_LIT:0> <EOL> ordValue = ord ( event . key ) <EOL> if ordValue < <NUM_LIT> or ordValue == <NUM_LIT> or ordValue > <NUM_LIT> : <EOL> return <NUM_LIT:0> <EOL> if ordValue == <NUM_LIT> and len ( self . text ) != <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> if ordValue == <NUM_LIT> : <EOL> if self . allowDecimels == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> for char in self . text : <EOL> if char == '<STR_LIT:.>' : <EOL> return <NUM_LIT:0> <EOL> return Edit . _pyuiChar ( self , event ) <EOL> def getValue ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . text == "<STR_LIT>" : <EOL> self . text = "<STR_LIT:0>" <EOL> self . setDirty ( ) <EOL> try : <EOL> if self . allowDecimels : <EOL> return float ( self . text ) <EOL> else : <EOL> return int ( self . text ) <EOL> except ValueError : <EOL> raise '<STR_LIT>' + self . text + '<STR_LIT>' <EOL> return <NUM_LIT:0> <EOL> def setValue ( self , value ) : <EOL> try : <EOL> self . setText ( str ( value ) ) <EOL> except : <EOL> raise '<STR_LIT>' <EOL> class Password ( Edit ) : <EOL> widgetLabel = "<STR_LIT>" <EOL> def draw ( self , renderer ) : <EOL> hidden = len ( self . text ) * "<STR_LIT:*>" <EOL> getTheme ( ) . drawEdit ( self . windowRect , hidden , self . hasFocus ( ) , self . caretPos , self . selectPos ) <EOL> class Scroll ( Base ) : <EOL> """<STR_LIT>""" <EOL> widgetLabel = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . scrollPos = <NUM_LIT:0> <EOL> self . currentItem = <NUM_LIT:0> <EOL> self . status = <NUM_LIT:0> <EOL> self . barSize = <NUM_LIT:1> <EOL> self . barSpace = <NUM_LIT:1> <EOL> self . numItems = <NUM_LIT:1> <EOL> self . numVisible = <NUM_LIT:1> <EOL> self . interval = <NUM_LIT:1> <EOL> Base . __init__ ( self ) <EOL> self . setupBar ( ) <EOL> self . setupPos ( ) <EOL> self . start = <NUM_LIT:0> <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> def setNumItems ( self , numItems , numVisible ) : <EOL> if numItems == <NUM_LIT:0> : <EOL> self . numItems = <NUM_LIT:1> <EOL> else : <EOL> self . numItems = numItems <EOL> self . numVisible = numVisible <EOL> self . setupBar ( ) <EOL> self . setupPos ( ) <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def setupBar ( self ) : <EOL> if self . alignment == '<STR_LIT:v>' : <EOL> self . barSpace = self . height - ( getTheme ( ) . getScrollerSize ( ) * <NUM_LIT:2> + <NUM_LIT:2> ) <EOL> else : <EOL> self . barSpace = self . width - ( getTheme ( ) . getScrollerSize ( ) * <NUM_LIT:2> + <NUM_LIT:2> ) <EOL> if self . barSpace < <NUM_LIT:1> : <EOL> self . barSpace = <NUM_LIT:1> <EOL> if self . numItems < self . numVisible : <EOL> self . barSize = self . barSpace <EOL> else : <EOL> self . barSize = self . barSpace * self . numVisible / self . numItems <EOL> if self . barSize < <NUM_LIT:5> : <EOL> self . barSize = <NUM_LIT:5> <EOL> if self . scrollPos > self . barSpace - self . barSize : <EOL> self . scrollPos = max ( self . barSpace - self . barSize , <NUM_LIT:0> ) <EOL> def setupPos ( self ) : <EOL> self . pos = getTheme ( ) . getScrollerSize ( ) + <NUM_LIT:1> + self . scrollPos <EOL> if self . barSpace == self . barSize : <EOL> item = <NUM_LIT:0> <EOL> else : <EOL> item = ( self . scrollPos / float ( ( self . barSpace - self . barSize ) ) ) * ( self . numItems - self . numVisible ) <EOL> if item >= self . numItems - self . numVisible : <EOL> item = self . numItems - self . numVisible <EOL> if item != self . currentItem : <EOL> e = self . postEvent ( pyui . locals . SCROLLPOS ) <EOL> e . pos = int ( item ) <EOL> self . currentItem = int ( item ) <EOL> def draw ( self , renderer ) : <EOL> if not self . show : <EOL> return <EOL> theme = getTheme ( ) <EOL> theme . drawScrollBack ( self . windowRect ) <EOL> if self . alignment == '<STR_LIT:v>' : <EOL> theme . drawScrollButtonUp ( ( self . windowRect [ <NUM_LIT:0> ] , self . windowRect [ <NUM_LIT:1> ] , self . width , getTheme ( ) . getScrollerSize ( ) ) ) <EOL> theme . drawScrollButtonDown ( ( self . windowRect [ <NUM_LIT:0> ] , self . windowRect [ <NUM_LIT:1> ] + self . height - getTheme ( ) . getScrollerSize ( ) , self . width , getTheme ( ) . getScrollerSize ( ) ) ) <EOL> theme . drawScrollBar ( ( self . windowRect [ <NUM_LIT:0> ] , self . windowRect [ <NUM_LIT:1> ] + self . pos , self . width , self . barSize ) ) <EOL> else : <EOL> theme . drawScrollButtonUp ( ( self . windowRect [ <NUM_LIT:0> ] , self . windowRect [ <NUM_LIT:1> ] , getTheme ( ) . getScrollerSize ( ) , self . height ) ) <EOL> theme . drawScrollButtonDown ( ( self . windowRect [ <NUM_LIT:0> ] + self . width - getTheme ( ) . getScrollerSize ( ) , self . windowRect [ <NUM_LIT:1> ] , getTheme ( ) . getScrollerSize ( ) , self . height ) ) <EOL> theme . drawScrollBar ( ( self . windowRect [ <NUM_LIT:0> ] + self . pos , self . windowRect [ <NUM_LIT:1> ] , self . barSize , self . height ) ) <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> self . status = <NUM_LIT:0> <EOL> return <NUM_LIT:0> <EOL> localpos = ( event . pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] , event . pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] ) <EOL> if self . alignment == '<STR_LIT:v>' : <EOL> p = localpos [ <NUM_LIT:1> ] <EOL> extent = self . height <EOL> else : <EOL> p = localpos [ <NUM_LIT:0> ] <EOL> extent = self . width <EOL> if p < getTheme ( ) . getScrollerSize ( ) : <EOL> if self . currentItem > <NUM_LIT:0> : self . scrollToItem ( self . currentItem - <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> if p > extent - getTheme ( ) . getScrollerSize ( ) : <EOL> if self . currentItem < self . numItems : self . scrollToItem ( self . currentItem + <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> if self . pos < p < self . pos + self . barSize : <EOL> self . status = <NUM_LIT:1> <EOL> self . start = p <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> else : <EOL> self . scrollPos = p - getTheme ( ) . getScrollerSize ( ) - <NUM_LIT:1> - self . barSize / <NUM_LIT:2> <EOL> if self . scrollPos < <NUM_LIT:0> : <EOL> self . scrollPos = <NUM_LIT:0> <EOL> elif self . scrollPos > self . barSpace - self . barSize : <EOL> self . scrollPos = self . barSpace - self . barSize <EOL> self . setupPos ( ) <EOL> self . status = <NUM_LIT:1> <EOL> self . start = p <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> self . status = <NUM_LIT:0> <EOL> return <NUM_LIT:0> <EOL> self . status = <NUM_LIT:0> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . status : <EOL> localpos = ( event . pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] , event . pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] ) <EOL> if self . alignment == '<STR_LIT:v>' : <EOL> p = localpos [ <NUM_LIT:1> ] <EOL> else : <EOL> p = localpos [ <NUM_LIT:0> ] <EOL> diff = p - self . start <EOL> self . scrollPos = self . scrollPos + diff <EOL> if self . scrollPos < <NUM_LIT:0> : <EOL> self . scrollPos = <NUM_LIT:0> <EOL> elif self . scrollPos > self . barSpace - self . barSize : <EOL> self . scrollPos = self . barSpace - self . barSize <EOL> self . start = p <EOL> self . setupPos ( ) <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> def resize ( self , w , h ) : <EOL> Base . resize ( self , w , h ) <EOL> self . setupBar ( ) <EOL> self . setupPos ( ) <EOL> def calcSize ( self ) : <EOL> Base . calcSize ( self ) <EOL> self . setupBar ( ) <EOL> self . setupPos ( ) <EOL> def scrollToItem ( self , itemNum ) : <EOL> if int ( self . currentItem ) != int ( itemNum ) : <EOL> self . scrollPos = ( itemNum / float ( self . numItems ) ) * float ( self . barSpace ) <EOL> if self . scrollPos < <NUM_LIT:0> : <EOL> self . scrollPos = <NUM_LIT:0> <EOL> elif self . scrollPos > self . barSpace - self . barSize : <EOL> self . scrollPos = self . barSpace - self . barSize <EOL> self . setupPos ( ) <EOL> class VScroll ( Scroll ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . alignment = '<STR_LIT:v>' <EOL> Scroll . __init__ ( self ) <EOL> class HScroll ( Scroll ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . alignment = '<STR_LIT:h>' <EOL> Scroll . __init__ ( self ) <EOL> class ListBoxItem : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , data , fg , bg ) : <EOL> self . name = name <EOL> self . data = data <EOL> self . color = fg <EOL> class ListBox ( Base ) : <EOL> """<STR_LIT>""" <EOL> canTab = <NUM_LIT:1> <EOL> widgetLabel = "<STR_LIT>" <EOL> def __init__ ( self , onSelected = None , onDouble = None ) : <EOL> Base . __init__ ( self ) <EOL> self . items = [ ] <EOL> self . numVisible = self . height / getTheme ( ) . defaultTextHeight <EOL> self . numItems = <NUM_LIT:0> <EOL> self . topItem = <NUM_LIT:0> <EOL> self . selected = - <NUM_LIT:1> <EOL> self . vscroll = VScroll ( ) <EOL> self . addChild ( self . vscroll ) <EOL> self . registerEvent ( pyui . locals . SCROLLPOS , self . _pyuiScrollPos ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiLButtonDown ) <EOL> self . registerEvent ( pyui . locals . RMOUSEBUTTONDOWN , self . _pyuiLButtonDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiLButtonUp ) <EOL> self . registerEvent ( pyui . locals . RMOUSEBUTTONUP , self . _pyuiLButtonUp ) <EOL> self . registerEvent ( pyui . locals . LMOUSEDBLCLICK , self . _pyuiDoubleClick ) <EOL> self . registerEvent ( pyui . locals . LIST_SELECTED , self . _pyuiSelectEvent ) <EOL> self . registerEvent ( pyui . locals . LIST_DBLCLICK , self . _pyuiDoubleEvent ) <EOL> self . resize ( <NUM_LIT:100> , <NUM_LIT:100> ) <EOL> self . selectHandler = onSelected <EOL> self . doubleHandler = onDouble <EOL> def clearAllItems ( self ) : <EOL> self . items = [ ] <EOL> self . numVisible = self . height / getTheme ( ) . defaultTextHeight <EOL> self . numItems = <NUM_LIT:0> <EOL> self . topItem = <NUM_LIT:0> <EOL> self . selected = - <NUM_LIT:1> <EOL> def populateList ( self , items ) : <EOL> for item in items : <EOL> self . addItem ( item , None ) <EOL> self . sortByName ( ) <EOL> def addItem ( self , itemText , itemData , color = None ) : <EOL> """<STR_LIT>""" <EOL> if color == None : <EOL> color = self . fgColor <EOL> item = ListBoxItem ( itemText , itemData , color , color ) <EOL> self . items . append ( item ) <EOL> self . numItems = len ( self . items ) <EOL> self . vscroll . setNumItems ( self . numItems , self . numVisible ) <EOL> self . setDirty ( ) <EOL> def removeItem ( self , itemText ) : <EOL> i = <NUM_LIT:0> <EOL> for item in self . items : <EOL> if item . name == itemText : <EOL> if i <= self . selected : <EOL> self . selected -= <NUM_LIT:1> <EOL> self . items . pop ( i ) <EOL> break <EOL> i = i + <NUM_LIT:1> <EOL> self . numItems = len ( self . items ) <EOL> self . vscroll . setNumItems ( self . numItems , self . numVisible ) <EOL> self . setDirty ( ) <EOL> def removeItemByData ( self , itemData ) : <EOL> i = <NUM_LIT:0> <EOL> for item in self . items : <EOL> if item . data == itemData : <EOL> if i <= self . selected : <EOL> self . selected -= <NUM_LIT:1> <EOL> self . items . pop ( i ) <EOL> break <EOL> i = i + <NUM_LIT:1> <EOL> self . numItems = len ( self . items ) <EOL> self . vscroll . setNumItems ( self . numItems , self . numVisible ) <EOL> self . setDirty ( ) <EOL> def getItemByData ( self , itemData ) : <EOL> for item in self . items : <EOL> if item . data == itemData : <EOL> return item <EOL> return None <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> getTheme ( ) . drawListBox ( self . windowRect ) <EOL> i = <NUM_LIT:0> <EOL> for item in self . items : <EOL> if i >= self . topItem and i < self . topItem + self . numVisible : <EOL> if i == self . selected : <EOL> getTheme ( ) . drawListBoxItem ( ( self . windowRect [ <NUM_LIT:0> ] + <NUM_LIT:1> , <EOL> self . windowRect [ <NUM_LIT:1> ] + <NUM_LIT:2> + ( i - self . topItem ) * getTheme ( ) . defaultTextHeight , <EOL> self . width - getTheme ( ) . getScrollerSize ( ) , <EOL> getTheme ( ) . defaultTextHeight - <NUM_LIT:2> ) , <EOL> item . name , <NUM_LIT:1> , item . color ) <EOL> else : <EOL> getTheme ( ) . drawListBoxItem ( ( self . windowRect [ <NUM_LIT:0> ] + <NUM_LIT:1> , <EOL> self . windowRect [ <NUM_LIT:1> ] + <NUM_LIT:2> + ( i - self . topItem ) * getTheme ( ) . defaultTextHeight , <EOL> self . width - getTheme ( ) . getScrollerSize ( ) , <EOL> getTheme ( ) . defaultTextHeight - <NUM_LIT:2> ) , <EOL> item . name , <NUM_LIT:0> , item . color ) <EOL> i = i + <NUM_LIT:1> <EOL> self . vscroll . draw ( renderer ) <EOL> def _pyuiScrollPos ( self , event ) : <EOL> if event . id == self . vscroll . id : <EOL> self . topItem = event . pos <EOL> self . setDirty ( ) <EOL> def _pyuiLButtonDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> item = int ( ( event . pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] ) / getTheme ( ) . defaultTextHeight ) <EOL> self . selected = item + self . topItem <EOL> self . postEvent ( pyui . locals . LIST_SELECTED ) <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:0> <EOL> def _pyuiLButtonUp ( self , event ) : <EOL> return <NUM_LIT:0> <EOL> def _pyuiDoubleClick ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> item = int ( ( event . pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] ) / getTheme ( ) . defaultTextHeight ) <EOL> self . selected = item + self . topItem <EOL> self . postEvent ( pyui . locals . LIST_DBLCLICK ) <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:1> <EOL> def getSelectedItem ( self ) : <EOL> if self . selected > - <NUM_LIT:1> and self . selected < len ( self . items ) : <EOL> return self . items [ self . selected ] <EOL> return None <EOL> def setSelectedItem ( self , name ) : <EOL> i = <NUM_LIT:0> <EOL> for item in self . items : <EOL> if item . name == name : <EOL> self . selected = i <EOL> self . setDirty ( ) <EOL> break <EOL> i = i + <NUM_LIT:1> <EOL> def resize ( self , w , h ) : <EOL> Base . resize ( self , w , h ) <EOL> self . numVisible = int ( self . height / getTheme ( ) . defaultTextHeight ) <EOL> self . vscroll . setNumItems ( self . numItems , self . numVisible ) <EOL> self . vscroll . resize ( getTheme ( ) . getScrollerSize ( ) , h ) <EOL> self . vscroll . moveto ( w - getTheme ( ) . getScrollerSize ( ) , <NUM_LIT:0> ) <EOL> def clearSelection ( self ) : <EOL> self . selected = - <NUM_LIT:1> <EOL> self . setDirty ( ) <EOL> def clear ( self ) : <EOL> self . items = [ ] <EOL> self . numItems = <NUM_LIT:0> <EOL> self . vscroll . setNumItems ( <NUM_LIT:0> , self . numVisible ) <EOL> self . selected = - <NUM_LIT:1> <EOL> self . setDirty ( ) <EOL> def _pyuiSelectEvent ( self , event ) : <EOL> if event . id == self . id : <EOL> if self . selectHandler : <EOL> self . selectHandler ( self . getSelectedItem ( ) ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiDoubleEvent ( self , event ) : <EOL> if event . id == self . id : <EOL> if self . doubleHandler : <EOL> self . doubleHandler ( self . getSelectedItem ( ) ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def sortByName ( self ) : <EOL> self . items . sort ( self . itemCompareByName ) <EOL> self . setDirty ( ) <EOL> def sortByData ( self ) : <EOL> self . items . sort ( self . itemCompareByData ) <EOL> self . setDirty ( ) <EOL> def itemCompareByName ( self , item1 , item2 ) : <EOL> return cmp ( item1 . name , item2 . name ) <EOL> def itemCompareByData ( self , item1 , item2 ) : <EOL> return cmp ( item1 . data , item2 . data ) <EOL> class DropDownBox ( Base ) : <EOL> """<STR_LIT>""" <EOL> BUTTON_WIDTH = <NUM_LIT:10> <EOL> def __init__ ( self , numVisible = <NUM_LIT:10> , onSelected = None ) : <EOL> Base . __init__ ( self ) <EOL> self . numVisible = numVisible <EOL> self . selectionList = ListBox ( self . _pyuiSelectedEvent ) <EOL> self . selectionList . setShow ( <NUM_LIT:0> ) <EOL> self . addChild ( self . selectionList ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . selectHandler = onSelected <EOL> def addItem ( self , itemText , itemData , color = None ) : <EOL> self . selectionList . addItem ( itemText , itemData , color ) <EOL> self . selectionList . selected = len ( self . selectionList . items ) - <NUM_LIT:1> <EOL> def getSelectedItem ( self ) : <EOL> return self . selectionList . getSelectedItem ( ) <EOL> def removeItem ( self , text ) : <EOL> self . selectionList . removeItem ( text ) <EOL> def clearSelection ( self ) : <EOL> self . selectionList . clearSelection ( ) <EOL> def clear ( self ) : <EOL> self . selectionList . clear ( ) <EOL> def draw ( self , renderer ) : <EOL> """<STR_LIT>""" <EOL> if self . selectionList . selected == - <NUM_LIT:1> : <EOL> text = "<STR_LIT>" <EOL> else : <EOL> item = self . selectionList . getSelectedItem ( ) <EOL> if item : <EOL> text = item . name <EOL> else : <EOL> text = "<STR_LIT:None>" <EOL> getTheme ( ) . drawLabel ( ( self . windowRect [ <NUM_LIT:0> ] , self . windowRect [ <NUM_LIT:1> ] , self . width - self . BUTTON_WIDTH , self . height ) , text ) <EOL> getTheme ( ) . drawButton ( ( self . windowRect [ <NUM_LIT:0> ] + self . width - self . BUTTON_WIDTH , self . windowRect [ <NUM_LIT:1> ] , self . BUTTON_WIDTH , self . height ) , "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> if self . selectionList . show : <EOL> self . window . addDrawCallback ( self . selectionList . draw ) <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> if self . selectionList . show : <EOL> self . selectionList . setShow ( <NUM_LIT:0> ) <EOL> return <NUM_LIT:0> <EOL> x = event . pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] <EOL> y = event . pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] <EOL> if x > self . width - self . BUTTON_WIDTH and x < self . width : <EOL> if self . selectionList . show == <NUM_LIT:0> : <EOL> self . positionSelectionList ( ) <EOL> self . selectionList . setShow ( <NUM_LIT:1> ) <EOL> else : <EOL> self . selectionList . setShow ( <NUM_LIT:0> ) <EOL> return <NUM_LIT:1> <EOL> def _pyuiSelectedEvent ( self , item ) : <EOL> self . item = item <EOL> getDesktop ( ) . addCallback ( self . hideMe , <NUM_LIT> ) <EOL> return <NUM_LIT:1> <EOL> def hideMe ( self , interval ) : <EOL> if self . selectHandler : <EOL> self . selectHandler ( self . item ) <EOL> self . selectionList . setShow ( <NUM_LIT:0> ) <EOL> return <NUM_LIT:1> <EOL> def resize ( self , width , height ) : <EOL> Base . resize ( self , width , height ) <EOL> self . positionSelectionList ( ) <EOL> def positionSelectionList ( self ) : <EOL> self . selectionList . resize ( self . width , self . numVisible * getTheme ( ) . defaultTextHeight ) <EOL> self . selectionList . moveto ( <NUM_LIT:0> , self . height ) <EOL> class CheckBox ( Base ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text , onCheck = None ) : <EOL> self . checkState = <NUM_LIT:0> <EOL> self . text = text <EOL> self . _pyuiCheck = onCheck <EOL> Base . __init__ ( self ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> def setCheck ( self , value ) : <EOL> if value : <EOL> self . checkState = <NUM_LIT:1> <EOL> else : <EOL> self . checkState = <NUM_LIT:0> <EOL> if self . _pyuiCheck : <EOL> self . _pyuiCheck ( self . checkState ) <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> if self . checkState : <EOL> self . setCheck ( <NUM_LIT:0> ) <EOL> else : <EOL> self . setCheck ( <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> def draw ( self , renderer ) : <EOL> getTheme ( ) . drawCheckBox ( self . windowRect , self . text , self . checkState ) <EOL> class SliderBar ( Base ) : <EOL> """<STR_LIT>""" <EOL> BARWIDTH = <NUM_LIT:8> <EOL> def __init__ ( self , onSlide , range = <NUM_LIT:1> , initialPos = <NUM_LIT:1> ) : <EOL> self . range = range <EOL> self . position = initialPos <EOL> self . sliding = <NUM_LIT:0> <EOL> self . slidePos = <NUM_LIT:0> <EOL> self . stepInterval = <NUM_LIT:1> <EOL> self . _pyuiSlide = onSlide <EOL> Base . __init__ ( self ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> def resize ( self , w , h ) : <EOL> Base . resize ( self , w , h ) <EOL> self . stepInterval = ( float ( self . width ) - self . BARWIDTH ) / self . range <EOL> def draw ( self , renderer ) : <EOL> getTheme ( ) . drawSliderBar ( self . windowRect , self . range , self . position , self . BARWIDTH ) <EOL> def setValue ( self , newValue ) : <EOL> if newValue < <NUM_LIT:0> or newValue > self . range : <EOL> return <EOL> self . position = newValue <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> if self . sliding : <EOL> return <NUM_LIT:0> <EOL> x = event . pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] <EOL> barpos = self . stepInterval * self . position <EOL> if x > barpos and x < barpos + self . BARWIDTH : <EOL> self . sliding = <NUM_LIT:1> <EOL> self . slidePos = x <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if not self . sliding : <EOL> return <NUM_LIT:0> <EOL> self . sliding = <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if not self . sliding : <EOL> return <NUM_LIT:0> <EOL> x = event . pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] <EOL> diff = x - self . slidePos <EOL> newPosition = ( ( self . position * self . stepInterval ) + diff ) / self . stepInterval <EOL> realdiff = newPosition - self . position <EOL> if abs ( realdiff ) > <NUM_LIT:1> : <EOL> self . position = self . position + int ( realdiff ) <EOL> if self . position < <NUM_LIT:0> : <EOL> self . position = <NUM_LIT:0> <EOL> if self . position >= self . range : <EOL> self . position = self . range <EOL> if self . _pyuiSlide : <EOL> self . _pyuiSlide ( self . position ) <EOL> self . slidePos = self . position * self . stepInterval <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> class TabbedPanel ( Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Panel . __init__ ( self ) <EOL> self . activePanel = None <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . tabPanels = { } <EOL> self . activePanel = None <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . KEYDOWN , self . _pyuiKeyDown ) <EOL> def removePanel ( self , title ) : <EOL> """<STR_LIT>""" <EOL> self . removeChild ( self . tabPanels [ title ] ) <EOL> del self . tabPanels [ title ] <EOL> def addPanel ( self , title , panel = None ) : <EOL> """<STR_LIT>""" <EOL> if not panel : <EOL> panel = Panel ( ) <EOL> self . addChild ( panel ) <EOL> panel . moveto ( <NUM_LIT:0> , getTheme ( ) . getTabsHeight ( ) ) <EOL> panel . resize ( self . width , self . height - getTheme ( ) . getTabsHeight ( ) ) <EOL> panel . calcSize ( ) <EOL> panel . tabTitle = title <EOL> self . tabPanels [ title ] = panel <EOL> if not self . activePanel : <EOL> self . activePanel = panel <EOL> self . setDirty ( ) <EOL> return panel <EOL> def getPanel ( self , number ) : <EOL> return self . children [ number ] <EOL> def resize ( self , w , h ) : <EOL> """<STR_LIT>""" <EOL> Base . resize ( self , w , h ) <EOL> if self . activePanel : <EOL> self . activePanel . resize ( w , h - getTheme ( ) . getTabsHeight ( ) ) <EOL> def pack ( self ) : <EOL> for p in self . children : <EOL> p . pack ( ) <EOL> def draw ( self , renderer ) : <EOL> x = self . windowRect [ <NUM_LIT:0> ] <EOL> h = getTheme ( ) . getTabsHeight ( ) <EOL> for p in self . children : <EOL> rect = getTheme ( ) . drawTabItem ( ( x , self . windowRect [ <NUM_LIT:1> ] + <NUM_LIT:2> , <NUM_LIT:0> , h ) , p . tabTitle , p == self . activePanel ) <EOL> p . tabRect = rect <EOL> x = rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] <EOL> getTheme ( ) . drawTabHeader ( ( x , self . windowRect [ <NUM_LIT:1> ] + <NUM_LIT:2> , self . windowRect [ <NUM_LIT:2> ] - x , h ) ) <EOL> if self . activePanel : <EOL> self . activePanel . draw ( renderer ) <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> x = event . pos [ <NUM_LIT:0> ] <EOL> y = event . pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] <EOL> if <NUM_LIT:0> <= y < getTheme ( ) . getTabsHeight ( ) : <EOL> for p in self . children : <EOL> if p . tabRect [ <NUM_LIT:0> ] <= x < p . tabRect [ <NUM_LIT:0> ] + p . tabRect [ <NUM_LIT:2> ] : <EOL> self . activatePanel ( p ) <EOL> return <NUM_LIT:0> <EOL> self . getFocus ( ) <EOL> return <NUM_LIT:0> <EOL> def activatePanel ( self , p ) : <EOL> if p != self . activePanel : <EOL> for panel in self . children : <EOL> if panel == p : <EOL> panel . setShow ( <NUM_LIT:1> ) <EOL> else : <EOL> panel . setShow ( <NUM_LIT:0> ) <EOL> self . activePanel = p <EOL> if p . width != self . width or p . height != self . height - getTheme ( ) . getTabsHeight ( ) : <EOL> p . resize ( self . width , self . height - getTheme ( ) . getTabsHeight ( ) ) <EOL> self . setDirty ( ) <EOL> p . getFocus ( ) <EOL> def nextPanel ( self ) : <EOL> for i in range ( <NUM_LIT:0> , len ( self . children ) ) : <EOL> if self . children [ i ] == self . activePanel : <EOL> if i == len ( self . children ) - <NUM_LIT:1> : <EOL> print "<STR_LIT>" , <NUM_LIT:0> , self . children [ <NUM_LIT:0> ] <EOL> self . activatePanel ( self . children [ <NUM_LIT:0> ] ) <EOL> break <EOL> else : <EOL> print "<STR_LIT>" , i , self . children [ i + <NUM_LIT:1> ] <EOL> self . activatePanel ( self . children [ i + <NUM_LIT:1> ] ) <EOL> break <EOL> def _pyuiKeyDown ( self , event ) : <EOL> if event . mods & pyui . locals . MOD_CONTROL : <EOL> if event . key == pyui . locals . K_TAB : <EOL> self . nextPanel ( ) <EOL> return <NUM_LIT:1> <EOL> number = event . key - ord ( '<STR_LIT:0>' ) - <NUM_LIT:1> <EOL> if number >= <NUM_LIT:0> and number < <NUM_LIT:10> : <EOL> if number < len ( self . children ) : <EOL> self . activatePanel ( self . children [ number ] ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def handleEvent ( self , event ) : <EOL> if not self . show : <EOL> return <EOL> if not self . children : <EOL> return <NUM_LIT:0> <EOL> if self . activePanel . handleEvent ( event ) : <EOL> return <NUM_LIT:1> <EOL> if self . eventMap . has_key ( event . type ) : <EOL> if self . eventMap [ event . type ] ( event ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def getFocus ( self ) : <EOL> if self . activePanel : <EOL> self . activePanel . getFocus ( ) <EOL> def checkHit ( self , pos ) : <EOL> if pos [ <NUM_LIT:0> ] > self . rect [ <NUM_LIT:0> ] and pos [ <NUM_LIT:0> ] < self . rect [ <NUM_LIT:0> ] + self . rect [ <NUM_LIT:2> ] and pos [ <NUM_LIT:1> ] > self . rect [ <NUM_LIT:1> ] and pos [ <NUM_LIT:1> ] < self . rect [ <NUM_LIT:1> ] + self . rect [ <NUM_LIT:3> ] : <EOL> result = self . activePanel . checkHit ( pos ) <EOL> if result : <EOL> return result <EOL> return self <EOL> else : <EOL> return None <EOL> class SplitterPanel ( Panel ) : <EOL> """<STR_LIT>""" <EOL> VERTICAL = <NUM_LIT:0> <EOL> HORIZONTAL = <NUM_LIT:1> <EOL> PIXELS = <NUM_LIT:0> <EOL> PERCENTAGE = <NUM_LIT:1> <EOL> PADDING = <NUM_LIT:2> <EOL> def __init__ ( self , direction = VERTICAL , method = PERCENTAGE , ratio = <NUM_LIT:50> ) : <EOL> self . direction = direction <EOL> self . method = method <EOL> self . ratio = ratio <EOL> self . splitPos = <NUM_LIT:0> <EOL> if self . method == SplitterPanel . PERCENTAGE : <EOL> self . ratio = float ( ratio ) / <NUM_LIT> <EOL> Panel . __init__ ( self ) <EOL> self . panel1 = Panel ( ) <EOL> self . panel2 = Panel ( ) <EOL> self . addChild ( self . panel1 ) <EOL> self . addChild ( self . panel2 ) <EOL> def setVerticalSplit ( self , x ) : <EOL> self . panel1 . moveto ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . panel1 . resize ( x - self . PADDING , self . height ) <EOL> self . panel2 . moveto ( x + self . PADDING , <NUM_LIT:0> ) <EOL> self . panel2 . resize ( self . width - x - self . PADDING , self . height ) <EOL> self . splitPos = x <EOL> def setHorizontalSplit ( self , y ) : <EOL> self . panel1 . moveto ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . panel1 . resize ( self . width , y - self . PADDING ) <EOL> self . panel2 . moveto ( <NUM_LIT:0> , y + self . PADDING ) <EOL> self . panel2 . resize ( self . width , self . height - y - self . PADDING ) <EOL> self . splitPos = y <EOL> def resize ( self , w , h ) : <EOL> Base . resize ( self , w , h ) <EOL> if self . method == SplitterPanel . PIXELS : <EOL> if self . direction == SplitterPanel . VERTICAL : <EOL> if self . ratio >= <NUM_LIT:0> : <EOL> self . setVerticalSplit ( self . ratio ) <EOL> else : <EOL> self . setVerticalSplit ( self . width + self . ratio ) <EOL> if self . direction == SplitterPanel . HORIZONTAL : <EOL> if self . ratio >= <NUM_LIT:0> : <EOL> self . setHorizontalSplit ( self . ratio ) <EOL> else : <EOL> self . setHorizontalSplit ( self . height + self . ratio ) <EOL> else : <EOL> if self . direction == SplitterPanel . VERTICAL : <EOL> self . setVerticalSplit ( self . width * self . ratio ) <EOL> if self . direction == SplitterPanel . HORIZONTAL : <EOL> self . setHorizontalSplit ( self . height * self . ratio ) <EOL> def draw ( self , renderer ) : <EOL> self . panel1 . draw ( renderer ) <EOL> if self . direction == SplitterPanel . HORIZONTAL : <EOL> getTheme ( ) . drawSplitter ( <EOL> ( self . windowRect [ <NUM_LIT:0> ] , self . windowRect [ <NUM_LIT:1> ] + self . splitPos - self . PADDING , self . width , self . PADDING * <NUM_LIT:2> ) ) <EOL> else : <EOL> getTheme ( ) . drawSplitter ( <EOL> ( self . windowRect [ <NUM_LIT:0> ] + self . splitPos - self . PADDING , self . windowRect [ <NUM_LIT:1> ] , <NUM_LIT:2> * self . PADDING , self . height ) ) <EOL> self . panel2 . draw ( renderer ) <EOL> def pack ( self ) : <EOL> self . panel1 . pack ( ) <EOL> self . panel2 . pack ( ) <EOL> def getFirstPanel ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . panel1 <EOL> def getSecondPanel ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . panel2 <EOL> def replaceFirstPanel ( self , panel ) : <EOL> panel . moveto ( self . panel1 . posX , self . panel1 . posY ) <EOL> for c in self . children : <EOL> if c . id == self . panel1 . id : <EOL> self . children . remove ( c ) <EOL> c . destroy ( ) <EOL> self . addChild ( panel ) <EOL> self . panel1 = panel <EOL> self . resize ( self . width , self . height ) <EOL> def replaceSecondPanel ( self , panel ) : <EOL> panel . moveto ( self . panel2 . posX , self . panel2 . posY ) <EOL> for c in self . children : <EOL> if c . id == self . panel2 . id : <EOL> self . children . remove ( c ) <EOL> c . destroy ( ) <EOL> self . addChild ( panel ) <EOL> self . panel2 = panel <EOL> self . resize ( self . width , self . height ) <EOL> class FormPanel ( Panel ) : <EOL> """<STR_LIT>""" <EOL> fieldTypes = [ <EOL> "<STR_LIT:string>" , <EOL> "<STR_LIT:int>" , <EOL> "<STR_LIT:text>" , <EOL> "<STR_LIT:password>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:list>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:label>" <EOL> ] <EOL> def __init__ ( self , fieldList ) : <EOL> self . fieldList = fieldList <EOL> Panel . __init__ ( self ) <EOL> self . object = None <EOL> num = <NUM_LIT:0> <EOL> span = <NUM_LIT:0> <EOL> for t , n , l , vspan , d in fieldList : <EOL> span = span + vspan <EOL> self . setLayout ( pyui . layouts . TableLayoutManager ( <NUM_LIT:3> , span ) ) <EOL> for fieldType , fieldName , fieldLabel , fieldSpan , fieldData in fieldList : <EOL> newLabel = Label ( fieldLabel ) <EOL> newWidget = self . createFormWidget ( fieldType , fieldData ) <EOL> self . addChild ( newLabel , ( <NUM_LIT:0> , num , <NUM_LIT:1> , fieldSpan ) ) <EOL> self . addChild ( newWidget , ( <NUM_LIT:1> , num , <NUM_LIT:2> , fieldSpan ) ) <EOL> self . __dict__ [ "<STR_LIT>" % fieldName ] = newLabel <EOL> self . __dict__ [ "<STR_LIT>" % fieldName ] = newWidget <EOL> num = num + fieldSpan <EOL> self . pack ( ) <EOL> def populate ( self , object ) : <EOL> """<STR_LIT>""" <EOL> self . object = object <EOL> for fieldType , fieldName , fieldLabel , fieldSpan , fieldDefault in self . fieldList : <EOL> formWidget = self . __dict__ [ "<STR_LIT>" % fieldName ] <EOL> value = object . __dict__ . get ( fieldName , None ) <EOL> self . populateFormWidget ( fieldType , formWidget , value ) <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def process ( self ) : <EOL> """<STR_LIT>""" <EOL> for fieldType , fieldName , fieldLabel , fieldSpan , fieldData in self . fieldList : <EOL> formWidget = self . __dict__ [ "<STR_LIT>" % fieldName ] <EOL> self . processFormWidget ( fieldType , fieldName , formWidget ) <EOL> def createFormWidget ( self , fieldType , fieldData ) : <EOL> """<STR_LIT>""" <EOL> tmp = "<STR_LIT>" % fieldType <EOL> createMethod = getattr ( self , tmp ) <EOL> if not createMethod : <EOL> raise "<STR_LIT>" % tmp <EOL> return createMethod ( fieldData ) <EOL> def populateFormWidget ( self , fieldType , formWidget , value ) : <EOL> tmp = "<STR_LIT>" % fieldType <EOL> populateMethod = getattr ( self , tmp ) <EOL> if not populateMethod : <EOL> raise "<STR_LIT>" % fieldType <EOL> return populateMethod ( formWidget , value ) <EOL> def processFormWidget ( self , fieldType , fieldName , formWidget ) : <EOL> if not self . object : <EOL> raise "<STR_LIT>" <EOL> tmp = "<STR_LIT>" % fieldType <EOL> processMethod = getattr ( self , tmp ) <EOL> if not processMethod : <EOL> raise "<STR_LIT>" % fieldType <EOL> return processMethod ( formWidget , fieldName ) <EOL> def create_string ( self , size ) : <EOL> return Edit ( "<STR_LIT>" , size , self . _pyuiEdit ) <EOL> def create_password ( self , size ) : <EOL> return Password ( "<STR_LIT>" , size , self . _pyuiEdit ) <EOL> def create_int ( self , dummy ) : <EOL> return NumberEdit ( "<STR_LIT>" , <NUM_LIT:12> , self . _pyuiEdit , <NUM_LIT:0> ) <EOL> def create_text ( self , size ) : <EOL> return Edit ( "<STR_LIT>" , size , self . _pyuiEdit ) <EOL> def create_slider ( self , range ) : <EOL> return SliderBar ( self . _pyuiSlide , range ) <EOL> def create_checkbox ( self , title ) : <EOL> return CheckBox ( title , self . _pyuiCheck ) <EOL> def create_list ( self , dummy ) : <EOL> return ListBox ( ) <EOL> def create_dropdownlist ( self , numVisible ) : <EOL> return DropDownBox ( numVisible ) <EOL> def create_label ( self , dummy ) : <EOL> return Label ( "<STR_LIT>" ) <EOL> def populate_string ( self , formWidget , value ) : <EOL> if not value : <EOL> formWidget . setText ( "<STR_LIT:None>" ) <EOL> else : <EOL> formWidget . setText ( "<STR_LIT:%s>" % value ) <EOL> populate_password = populate_string <EOL> populate_int = populate_string <EOL> populate_text = populate_string <EOL> populate_label = populate_string <EOL> def populate_slider ( self , formWidget , value ) : <EOL> formWidget . position = value <EOL> def populate_checkbox ( self , formWidget , value ) : <EOL> formWidget . setCheck ( value ) <EOL> def populate_list ( self , formWidget , items ) : <EOL> formWidget . clear ( ) <EOL> for item in items : <EOL> formWidget . addItem ( repr ( item ) , item ) <EOL> populate_dropdownlist = populate_list <EOL> def process_string ( self , formWidget , fieldName ) : <EOL> setattr ( self . object , fieldName , formWidget . text ) <EOL> process_text = process_string <EOL> process_password = process_string <EOL> def process_label ( self , formWidget , fieldName ) : <EOL> pass <EOL> def process_list ( self , formWidget , fieldName ) : <EOL> pass <EOL> process_dropdownlist = process_list <EOL> def process_slider ( self , formWidget , fieldName ) : <EOL> setattr ( self . object , fieldName , formWidget . position ) <EOL> def process_checkbox ( self , formWidget , fieldName ) : <EOL> setattr ( self . object , fieldName , formWidget . checkState ) <EOL> def process_int ( self , formWidget , fieldName ) : <EOL> setattr ( self . object , fieldName , int ( formWidget . text ) ) <EOL> def _pyuiSlide ( self , value ) : <EOL> pass <EOL> def _pyuiEdit ( self , edit ) : <EOL> return <NUM_LIT:1> <EOL> def _pyuiCheck ( self , value ) : <EOL> pass <EOL> class ViewPanel ( Panel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , world , windowHandle , width , height ) : <EOL> Panel . __init__ ( self ) <EOL> self . viewHandle = getRenderer ( ) . createView ( world ) <EOL> self . world = world <EOL> self . windowHandle = windowHandle <EOL> primView = ( pyui . locals . VIEW , <NUM_LIT:0> , <NUM_LIT:0> , width , height , self . viewHandle ) <EOL> getRenderer ( ) . describeWindow ( windowHandle , [ primView , ] ) <EOL> def destroy ( self ) : <EOL> self . windowHandle = None <EOL> getRenderer ( ) . destroyView ( self . viewHandle ) <EOL> Panel . destroy ( self ) <EOL> def draw ( self , renderer ) : <EOL> renderer . drawView ( self . windowRect , self . viewHandle ) <EOL> def setEffect ( self , effectName ) : <EOL> getRenderer ( ) . setWindowEffect ( self . windowHandle , effectName ) <EOL> class Frame ( Window ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , x , y , w , h , title , topmost = <NUM_LIT:0> ) : <EOL> self . theme = getTheme ( ) <EOL> self . innerWidth = w <EOL> self . innerHeight = h <EOL> self . title = title <EOL> self . panelOffsetLeft = <NUM_LIT:0> <EOL> self . panelOffsetTop = <NUM_LIT:0> <EOL> self . panelOffsetRight = <NUM_LIT:0> <EOL> self . panelOffsetBottom = <NUM_LIT:0> <EOL> Window . __init__ ( self , x , y , w , h , topmost ) <EOL> self . setTitle ( self . title ) <EOL> self . panelOffsetLeft = self . theme . getFrameBorderLeft ( ) <EOL> self . panelOffsetTop = self . theme . getFrameBorderTop ( ) <EOL> self . panelOffsetRight = self . theme . getFrameBorderRight ( ) <EOL> self . panelOffsetBottom = self . theme . getFrameBorderBottom ( ) <EOL> self . _panel . moveto ( self . panelOffsetLeft , self . panelOffsetTop ) <EOL> w += self . panelOffsetLeft + self . panelOffsetRight <EOL> h += self . panelOffsetTop + self . panelOffsetBottom <EOL> self . resize ( w , h ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> self . moving = <NUM_LIT:0> <EOL> self . resizing = <NUM_LIT:0> <EOL> self . startX = <NUM_LIT:0> <EOL> self . startY = <NUM_LIT:0> <EOL> self . resizingCursor = <NUM_LIT:0> <EOL> self . backImage = None <EOL> self . menuBar = None <EOL> def addMenuBar ( self , menuBar ) : <EOL> self . menuBar = menuBar <EOL> def setTitle ( self , title ) : <EOL> self . title = title <EOL> def setBackImage ( self , filename ) : <EOL> self . backImage = filename <EOL> def draw ( self , renderer ) : <EOL> """<STR_LIT>""" <EOL> if not self . show : <EOL> return <EOL> self . hitList = getTheme ( ) . drawFrame ( ( <NUM_LIT:0> , <NUM_LIT:0> , self . width , self . height ) , self . title , self . backImage ) <EOL> Window . draw ( self , renderer ) <EOL> def replacePanel ( self , panel ) : <EOL> Window . replacePanel ( self , panel ) <EOL> self . _panel . moveto ( self . panelOffsetLeft , self . panelOffsetTop ) <EOL> self . _panel . resize ( self . innerWidth , self . innerHeight ) <EOL> def hitFrameRegion ( self , pos ) : <EOL> x = pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] <EOL> y = pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] <EOL> for ( regionId , rect ) in self . hitList : <EOL> if x >= rect [ <NUM_LIT:0> ] and y >= rect [ <NUM_LIT:1> ] and x < rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] and y < rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] : <EOL> return regionId <EOL> else : <EOL> return None <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . moving : <EOL> mouseX = event . pos [ <NUM_LIT:0> ] - self . posX <EOL> mouseY = event . pos [ <NUM_LIT:1> ] - self . posY <EOL> self . move ( mouseX - self . startX , mouseY - self . startY ) <EOL> getRenderer ( ) . moveWindow ( self . handle , self . posX , self . posY ) <EOL> return <NUM_LIT:1> <EOL> if self . resizing : <EOL> mouseX = event . pos [ <NUM_LIT:0> ] - self . posX <EOL> mouseY = event . pos [ <NUM_LIT:1> ] - self . posY <EOL> if mouseX < <NUM_LIT:64> : <EOL> mouseX = <NUM_LIT:64> <EOL> if mouseY < <NUM_LIT:64> : <EOL> mouseY = <NUM_LIT:64> <EOL> self . resize ( self . width + mouseX - self . startX , self . height + mouseY - self . startY ) <EOL> ( self . startX , self . startY ) = ( mouseX , mouseY ) <EOL> return <NUM_LIT:1> <EOL> if event . pos [ <NUM_LIT:0> ] > self . posX + self . innerWidth and event . pos [ <NUM_LIT:1> ] > self . posY + self . innerHeight and not self . resizingCursor : <EOL> self . resizingCursor = <NUM_LIT:1> <EOL> self . theme . setResizeCursor ( ) <EOL> elif self . resizingCursor : <EOL> self . resizingCursor = <NUM_LIT:0> <EOL> self . theme . setArrowCursor ( ) <EOL> if not self . hit ( event . pos ) : <EOL> if self . resizingCursor and not self . resizing : <EOL> self . resizingCursor = <NUM_LIT:0> <EOL> self . theme . setArrowCursor ( ) <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> self . getFocus ( ) <EOL> regionId = self . hitFrameRegion ( event . pos ) <EOL> if regionId == pyui . locals . HIT_FRAME_CLOSE : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> return self . onCloseButton ( ) <EOL> return self . _pyuiCloseButton ( ) <EOL> if regionId == pyui . locals . HIT_FRAME_MOVE : <EOL> self . moving = <NUM_LIT:1> <EOL> self . startX = event . pos [ <NUM_LIT:0> ] - self . posX <EOL> self . startY = event . pos [ <NUM_LIT:1> ] - self . posY <EOL> return <NUM_LIT:1> <EOL> if regionId == pyui . locals . HIT_FRAME_RESIZE_BOTTOM_RIGHT : <EOL> self . resizing = <NUM_LIT:1> <EOL> self . startX = event . pos [ <NUM_LIT:0> ] - self . posX <EOL> self . startY = event . pos [ <NUM_LIT:1> ] - self . posY <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:1> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if self . moving : <EOL> self . moving = <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> if self . resizing : <EOL> self . resizing = <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> if self . resizingCursor : <EOL> self . resizingCursor = <NUM_LIT:0> <EOL> self . theme . setArrowCursor ( ) <EOL> if not self . hit ( event . pos ) : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def resize ( self , w , h ) : <EOL> if w < <NUM_LIT:64> : <EOL> w = <NUM_LIT:64> <EOL> if h < <NUM_LIT:64> : <EOL> h = <NUM_LIT:64> <EOL> Base . resize ( self , w , h ) <EOL> self . innerWidth = w - self . panelOffsetLeft - self . panelOffsetRight <EOL> self . innerHeight = h - self . panelOffsetTop - self . panelOffsetBottom <EOL> self . _panel . moveto ( self . panelOffsetLeft , self . panelOffsetTop ) <EOL> self . _panel . resize ( self . innerWidth , self . innerHeight ) <EOL> def _pyuiCloseButton ( self ) : <EOL> self . destroy ( ) <EOL> return <NUM_LIT:1> <EOL> class MenuItem : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , handler , text , subMenu ) : <EOL> self . handler = handler <EOL> self . text = text <EOL> ( width , height ) = getRenderer ( ) . getTextSize ( text , getTheme ( ) . defaultFont ) <EOL> self . width = width <EOL> self . subMenu = subMenu <EOL> self . icon = None <EOL> self . rect = ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . canActivate = handler or subMenu <EOL> def setIcon ( self , icon ) : <EOL> self . icon = icon <EOL> class Menu ( Window ) : <EOL> """<STR_LIT>""" <EOL> iconWidth = <NUM_LIT:20> <EOL> minWidth = <NUM_LIT:20> <EOL> border = <NUM_LIT:4> <EOL> def __init__ ( self , title ) : <EOL> Window . __init__ ( self , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:100> , topmost = <NUM_LIT:1> ) <EOL> self . menuTitle = title <EOL> self . width = self . minWidth <EOL> self . items = [ ] <EOL> self . active = None <EOL> self . subActive = None <EOL> self . setShow ( <NUM_LIT:0> ) <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> getTheme ( ) . drawMenu ( ( <NUM_LIT:0> , <NUM_LIT:0> , self . width , self . height ) ) <EOL> y = self . border <EOL> for item in self . items : <EOL> rect = getTheme ( ) . drawMenuItem ( ( self . border , y , self . width - self . border * <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> item . text , item == self . active , item . icon ) <EOL> item . rect = ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] , rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:3> ] ) <EOL> y += rect [ <NUM_LIT:3> ] <EOL> def setShow ( self , show ) : <EOL> if show : <EOL> self . getFocus ( ) <EOL> if self . subActive : <EOL> self . subActive . setShow ( <NUM_LIT:0> ) <EOL> self . subActive = None <EOL> self . active = None <EOL> Base . setShow ( self , show ) <EOL> def setActive ( self , item ) : <EOL> if item == self . active : <EOL> return <EOL> if self . subActive : <EOL> self . subActive . setShow ( <NUM_LIT:0> ) <EOL> if item and not item . canActivate : <EOL> self . active = None <EOL> return <EOL> self . active = item <EOL> if item : <EOL> self . subActive = item . subMenu <EOL> if self . subActive : <EOL> self . activateSubmenu ( item ) <EOL> self . setDirty ( ) <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . subActive and self . subActive . _pyuiMouseMotion ( event ) : <EOL> return <NUM_LIT:1> <EOL> item = self . findItem ( event . pos ) <EOL> if item and item != self . active : <EOL> self . setActive ( item ) <EOL> return item != None <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if self . subActive and self . subActive . _pyuiMouseDown ( event ) : <EOL> return <NUM_LIT:1> <EOL> item = self . findItem ( event . pos ) <EOL> if item != self . active : <EOL> self . setActive ( item ) <EOL> return item != None <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if self . subActive and self . subActive . _pyuiMouseUp ( event ) : <EOL> return <NUM_LIT:1> <EOL> item = self . findItem ( event . pos ) <EOL> if item != self . active : <EOL> self . setActive ( item ) <EOL> if not item : <EOL> return <NUM_LIT:0> <EOL> if item . subMenu : <EOL> return <NUM_LIT:1> <EOL> if not item . canActivate : <EOL> return <NUM_LIT:1> <EOL> print "<STR_LIT>" , item . text <EOL> if item . handler : <EOL> item . handler ( item ) <EOL> self . postEvent ( pyui . locals . MENU_EXIT ) <EOL> return <NUM_LIT:1> <EOL> def activateSubmenu ( self , item ) : <EOL> self . subActive = item . subMenu <EOL> ( x , y ) = ( self . posX + item . rect [ <NUM_LIT:2> ] , self . posY + item . rect [ <NUM_LIT:1> ] - self . border ) <EOL> if x + item . subMenu . width > getDesktop ( ) . width : <EOL> x -= self . width + item . subMenu . width <EOL> if x < <NUM_LIT:0> : <EOL> x = getDesktop ( ) . width - item . subMenu . width <EOL> item . subMenu . moveto ( getDesktop ( ) . width - item . subMenu . width , self . posY + item . subMenu . height * getTheme ( ) . defaultTextHeight ) <EOL> if y + item . subMenu . height > getDesktop ( ) . height : <EOL> y = getDesktop ( ) . height - item . subMenu . height <EOL> if y < <NUM_LIT:0> : <EOL> raise "<STR_LIT>" <EOL> item . subMenu . moveto ( x , y ) <EOL> item . subMenu . setShow ( <NUM_LIT:1> ) <EOL> def addItem ( self , title , handler = None , subMenu = None ) : <EOL> """<STR_LIT>""" <EOL> if subMenu : <EOL> title = title + "<STR_LIT>" <EOL> newItem = MenuItem ( handler , title , subMenu ) <EOL> self . items . append ( newItem ) <EOL> h = getTheme ( ) . defaultTextHeight * len ( self . items ) + self . border * <NUM_LIT:2> <EOL> w = self . minWidth <EOL> for item in self . items : <EOL> if item . width > w : <EOL> w = item . width <EOL> self . resize ( w + self . iconWidth * <NUM_LIT:2> + self . border * <NUM_LIT:2> , h ) <EOL> self . setDirty ( ) <EOL> return newItem <EOL> def changeItemTitle ( self , oldTitle , newTitle , newHandler ) : <EOL> for item in self . items : <EOL> if item . text == oldTitle : <EOL> item . text = newTitle <EOL> item . handler = newHandler <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> break <EOL> def findItem ( self , pos ) : <EOL> if not self . hit ( pos ) : <EOL> return None <EOL> x = pos [ <NUM_LIT:0> ] - self . posX <EOL> y = pos [ <NUM_LIT:1> ] - self . posY <EOL> for item in self . items : <EOL> if x >= item . rect [ <NUM_LIT:0> ] and y >= item . rect [ <NUM_LIT:1> ] and x < item . rect [ <NUM_LIT:0> ] + item . rect [ <NUM_LIT:2> ] and y < item . rect [ <NUM_LIT:1> ] + item . rect [ <NUM_LIT:3> ] : <EOL> return item <EOL> return None <EOL> class MenuPopup ( Menu ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Menu . __init__ ( self , "<STR_LIT>" ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . RMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> self . registerEvent ( pyui . locals . MENU_EXIT , self . _pyuiMenuExit ) <EOL> def activate ( self , x , y ) : <EOL> self . moveto ( x , y ) <EOL> self . setShow ( <NUM_LIT:1> ) <EOL> def _pyuiMenuExit ( self , event ) : <EOL> if self . show : <EOL> self . setShow ( <NUM_LIT:0> ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . show : <EOL> return Menu . _pyuiMouseMotion ( self , event ) <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if self . show : <EOL> if Menu . _pyuiMouseDown ( self , event ) : <EOL> return <NUM_LIT:1> <EOL> self . setShow ( <NUM_LIT:0> ) <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if self . show : <EOL> if Menu . _pyuiMouseUp ( self , event ) : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> class MenuBar ( Window ) : <EOL> """<STR_LIT>""" <EOL> border = <NUM_LIT:1> <EOL> def __init__ ( self ) : <EOL> w = getDesktop ( ) . width <EOL> Window . __init__ ( self , <NUM_LIT:0> , <NUM_LIT:0> , w , getTheme ( ) . defaultTextHeight + <NUM_LIT:4> , topmost = <NUM_LIT:1> ) <EOL> self . setShow ( <NUM_LIT:1> ) <EOL> self . menus = [ ] <EOL> self . hitList = [ ] <EOL> self . active = None <EOL> self . highlight = None <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> self . registerEvent ( pyui . locals . MENU_EXIT , self . _pyuiMenuExit ) <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> getTheme ( ) . drawMenuBar ( self . windowRect ) <EOL> h = self . height - <NUM_LIT:2> * self . border <EOL> x = self . border <EOL> self . hitList = [ ] <EOL> for menu in self . menus : <EOL> rect = getTheme ( ) . drawMenuBarItem ( ( x , self . border , <NUM_LIT:0> , h ) , <EOL> menu . menuTitle , menu == self . highlight ) <EOL> menu . moveto ( self . posX + rect [ <NUM_LIT:0> ] - self . border , self . posY + self . height ) <EOL> self . hitList . append ( ( menu , rect ) ) <EOL> x += rect [ <NUM_LIT:2> ] <EOL> def addMenu ( self , menu ) : <EOL> self . menus . append ( menu ) <EOL> def setActiveMenu ( self , menu ) : <EOL> if self . active : <EOL> self . active . setShow ( <NUM_LIT:0> ) <EOL> self . active = menu <EOL> self . highlight = menu <EOL> if ( menu ) : <EOL> menu . setShow ( <NUM_LIT:1> ) <EOL> self . setDirty ( ) <EOL> def _pyuiMenuExit ( self , event ) : <EOL> if self . active : <EOL> self . setActiveMenu ( None ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . active and self . active . _pyuiMouseMotion ( event ) : <EOL> return <NUM_LIT:1> <EOL> menu = self . findMenu ( event . pos ) <EOL> if self . active : <EOL> if menu and menu != self . active : <EOL> self . setActiveMenu ( menu ) <EOL> else : <EOL> if menu != self . highlight : <EOL> self . highlight = menu <EOL> self . setDirty ( ) <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if self . active and self . active . _pyuiMouseDown ( event ) : <EOL> return <NUM_LIT:1> <EOL> menu = self . findMenu ( event . pos ) <EOL> if menu != self . active : <EOL> self . setActiveMenu ( menu ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if self . active and self . active . _pyuiMouseUp ( event ) : <EOL> return <NUM_LIT:1> <EOL> menu = self . findMenu ( event . pos ) <EOL> if self . active and not menu : <EOL> self . setActiveMenu ( None ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def setParent ( self , parent ) : <EOL> Base . setParent ( self , parent ) <EOL> def findMenu ( self , pos ) : <EOL> if not self . hit ( pos ) : <EOL> return None <EOL> x = pos [ <NUM_LIT:0> ] - self . posX <EOL> y = pos [ <NUM_LIT:1> ] - self . posY <EOL> for ( menu , rect ) in self . hitList : <EOL> if x >= rect [ <NUM_LIT:0> ] and y >= rect [ <NUM_LIT:1> ] and x < rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] and y < rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] : <EOL> return menu <EOL> else : <EOL> return None <EOL> def destroy ( self ) : <EOL> for menu in self . menus : <EOL> menu . destroy ( ) <EOL> del menu <EOL> self . menus = None <EOL> self . hitList = None <EOL> Window . destroy ( self ) <EOL> class ViewWindow ( Frame ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , x , y , w , h , world ) : <EOL> Frame . __init__ ( self , x , y , w , h , "<STR_LIT>" ) <EOL> panel = ViewPanel ( world ) <EOL> self . replacePanel ( panel ) <EOL> self . world = world <EOL> class TooltipWindow ( Window ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , x , y , w , h ) : <EOL> Window . __init__ ( self , x , y , w , h , <NUM_LIT:1> ) <EOL> self . setLayout ( pyui . layouts . BorderLayoutManager ( ) ) <EOL> self . text = "<STR_LIT>" <EOL> self . setShow ( <NUM_LIT:0> ) <EOL> def activate ( self , text , rect ) : <EOL> self . text = text <EOL> self . moveto ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] ) <EOL> self . resize ( rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:3> ] ) <EOL> self . setShow ( <NUM_LIT:1> ) <EOL> def draw ( self , renderer ) : <EOL> if self . show : <EOL> getTheme ( ) . drawToolTip ( self . text , self . windowRect ) <EOL> class Desktop3DWindow ( Window ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _panel = Panel ( ) <EOL> Base . __init__ ( self ) <EOL> self . topMost = <NUM_LIT:0> <EOL> self . _panel . moveto ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> Base . addChild ( self , self . _panel ) <EOL> self . _panel . setWindow ( self ) <EOL> getTheme ( ) . setArrowCursor ( ) <EOL> self . drawCommands = [ ] <EOL> self . drawLastCallbacks = [ ] <EOL> self . handle = getRenderer ( ) . getDesktopWindow ( ) <EOL> self . moveto ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . resize ( getDesktop ( ) . width , getDesktop ( ) . height ) <EOL> getDesktop ( ) . windows . insert ( <NUM_LIT:0> , self ) <EOL> def destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _panel = None <EOL> self . handle = <NUM_LIT:0> <EOL> Base . destroy ( self ) <EOL> class AttachedWindow ( Window ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , xoffset , yoffset , width , height , objectHandle , viewHandle , nodeName = None ) : <EOL> Window . __init__ ( self , <NUM_LIT:0> , <NUM_LIT:0> , width , height ) <EOL> controllerHandle = getRenderer ( ) . attachController ( objectHandle , pyui . locals . CONTROLLER_2DWINDOW , nodeName ) <EOL> getRenderer ( ) . setController ( controllerHandle , window = self . handle , offset = ( xoffset , yoffset ) , view = viewHandle ) <EOL> self . viewHandle = viewHandle <EOL> self . objectHandle = objectHandle <EOL> self . controllerHandle = controllerHandle <EOL> self . nodeName = nodeName <EOL> self . xoffset = xoffset <EOL> self . yoffset = yoffset <EOL> def destroy ( self ) : <EOL> getRenderer ( ) . detachController ( self . objectHandle , self . controllerHandle ) <EOL> self . controllerHandle = None <EOL> Window . destroy ( self ) <EOL> class MenuBarWidget ( Base ) : <EOL> """<STR_LIT>""" <EOL> border = <NUM_LIT:1> <EOL> def __init__ ( self ) : <EOL> Base . __init__ ( self ) <EOL> self . resize ( <NUM_LIT:0> , getTheme ( ) . defaultTextHeight + <NUM_LIT:4> ) <EOL> self . setShow ( <NUM_LIT:1> ) <EOL> self . menus = [ ] <EOL> self . hitList = [ ] <EOL> self . active = None <EOL> self . highlight = None <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONDOWN , self . _pyuiMouseDown ) <EOL> self . registerEvent ( pyui . locals . LMOUSEBUTTONUP , self . _pyuiMouseUp ) <EOL> self . registerEvent ( pyui . locals . MOUSEMOVE , self . _pyuiMouseMotion ) <EOL> self . registerEvent ( pyui . locals . MENU_EXIT , self . _pyuiMenuExit ) <EOL> def draw ( self , renderer ) : <EOL> getTheme ( ) . drawMenuBar ( self . windowRect ) <EOL> h = self . height - <NUM_LIT:2> * self . border <EOL> x = self . border + self . windowRect [ <NUM_LIT:0> ] <EOL> y = self . border + self . windowRect [ <NUM_LIT:1> ] <EOL> self . hitList = [ ] <EOL> for menu in self . menus : <EOL> rect = getTheme ( ) . drawMenuBarItem ( ( x , y , <NUM_LIT:0> , h ) , menu . menuTitle , menu == self . highlight ) <EOL> menu . moveto ( self . rect [ <NUM_LIT:0> ] + x - self . windowRect [ <NUM_LIT:0> ] , <EOL> self . rect [ <NUM_LIT:1> ] + self . windowRect [ <NUM_LIT:3> ] ) <EOL> self . hitList . append ( ( menu , rect ) ) <EOL> x += rect [ <NUM_LIT:2> ] <EOL> def addMenu ( self , menu ) : <EOL> self . menus . append ( menu ) <EOL> def setActiveMenu ( self , menu ) : <EOL> if self . active : <EOL> self . active . setShow ( <NUM_LIT:0> ) <EOL> self . active = menu <EOL> self . highlight = menu <EOL> if ( menu ) : <EOL> menu . setShow ( <NUM_LIT:1> ) <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> def _pyuiMenuExit ( self , event ) : <EOL> if self . active : <EOL> self . setActiveMenu ( None ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseMotion ( self , event ) : <EOL> if self . active and self . active . _pyuiMouseMotion ( event ) : <EOL> return <NUM_LIT:1> <EOL> menu = self . findMenu ( event . pos ) <EOL> if self . active : <EOL> if menu and menu != self . active : <EOL> self . setActiveMenu ( menu ) <EOL> else : <EOL> if menu != self . highlight : <EOL> self . highlight = menu <EOL> self . setDirty ( <NUM_LIT:1> ) <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseDown ( self , event ) : <EOL> if self . active and self . active . _pyuiMouseDown ( event ) : <EOL> return <NUM_LIT:1> <EOL> menu = self . findMenu ( event . pos ) <EOL> if menu != self . active : <EOL> self . setActiveMenu ( menu ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def _pyuiMouseUp ( self , event ) : <EOL> if self . active and self . active . _pyuiMouseUp ( event ) : <EOL> return <NUM_LIT:1> <EOL> menu = self . findMenu ( event . pos ) <EOL> if self . active and not menu : <EOL> self . setActiveMenu ( None ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def setParent ( self , parent ) : <EOL> Base . setParent ( self , parent ) <EOL> def findMenu ( self , pos ) : <EOL> if not self . hit ( pos ) : <EOL> return None <EOL> x = pos [ <NUM_LIT:0> ] - self . rect [ <NUM_LIT:0> ] <EOL> y = pos [ <NUM_LIT:1> ] - self . rect [ <NUM_LIT:1> ] + self . windowRect [ <NUM_LIT:1> ] <EOL> for ( menu , rect ) in self . hitList : <EOL> if x >= rect [ <NUM_LIT:0> ] and y >= rect [ <NUM_LIT:1> ] and x < rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] and y < rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] : <EOL> return menu <EOL> else : <EOL> return None <EOL> def destroy ( self ) : <EOL> for menu in self . menus : <EOL> menu . destroy ( ) <EOL> del menu <EOL> self . menus = None <EOL> self . hitList = None <EOL> Base . destroy ( self ) </s>
