<s> from . qt . QtCore import * <EOL> from . qt . QtGui import * <EOL> from . ftitlebar import FTitleBar <EOL> from . fstatusbar import FStatusBar <EOL> class FMainWindow ( QMainWindow ) : <EOL> sizeChanged = Signal ( ) <EOL> def __init__ ( self ) : <EOL> super ( FMainWindow , self ) . __init__ ( ) <EOL> self . _initFlags ( ) <EOL> self . _initWindowFlags ( ) <EOL> self . _initMainWindow ( ) <EOL> self . _initTitleBar ( ) <EOL> self . _initTitlebarConnect ( ) <EOL> self . _initToolbars ( ) <EOL> self . _initStatusbar ( ) <EOL> self . _initSystemTray ( ) <EOL> self . setAttribute ( Qt . WA_Hover ) <EOL> self . installEventFilter ( self ) <EOL> self . isSideClicked = False <EOL> self . isCusorLeftSide = False <EOL> self . isCusorRightSide = False <EOL> self . isCusorDownSide = False <EOL> def _initFlags ( self ) : <EOL> self . _framelessflag = True <EOL> self . _customTitlebarFlag = True <EOL> self . _menubarFlag = False <EOL> self . _maximizedflag = False <EOL> self . _lockflag = False <EOL> self . _pinflag = False <EOL> self . _modeflag = False <EOL> desktopWidth = QDesktopWidget ( ) . availableGeometry ( ) . width ( ) <EOL> desktopHeight = QDesktopWidget ( ) . availableGeometry ( ) . height ( ) <EOL> self . default_size = QSize ( desktopWidth * <NUM_LIT> , desktopHeight * <NUM_LIT> ) <EOL> self . phone_size = QSize ( <NUM_LIT> , desktopHeight * <NUM_LIT> ) <EOL> self . oldPosition = QPoint ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def _initWindowFlags ( self , flag = True ) : <EOL> framelessflag = flag <EOL> if framelessflag : <EOL> self . setWindowFlags ( <EOL> Qt . FramelessWindowHint ) <EOL> self . _framelessflag = framelessflag <EOL> def _initMainWindow ( self ) : <EOL> self . showNormal ( ) <EOL> self . moveCenter ( ) <EOL> self . oldPosition = self . pos ( ) <EOL> self . setAttribute ( Qt . WA_DeleteOnClose ) <EOL> self . layout ( ) . setContentsMargins ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def _initSystemTray ( self ) : <EOL> self . systemTray = QSystemTrayIcon ( self ) <EOL> self . systemTray . activated . connect ( self . onSystemTrayIconClicked ) <EOL> def onSystemTrayIconClicked ( self , reason ) : <EOL> if reason == QSystemTrayIcon . Unknown : <EOL> pass <EOL> elif reason == QSystemTrayIcon . Context : <EOL> pass <EOL> elif reason == QSystemTrayIcon . DoubleClick : <EOL> pass <EOL> elif reason == QSystemTrayIcon . Trigger : <EOL> self . setVisible ( not self . isVisible ( ) ) <EOL> elif reason == QSystemTrayIcon . MiddleClick : <EOL> pass <EOL> else : <EOL> pass <EOL> def setSystemTrayMenu ( self , menu ) : <EOL> if isinstance ( menu , QMenu ) and hasattr ( self , '<STR_LIT>' ) and self . systemTray : <EOL> self . systemTray . setContextMenu ( menu ) <EOL> def setCentralWidget ( self , widget ) : <EOL> centralWidget = QFrame ( self ) <EOL> mainlayout = QVBoxLayout ( ) <EOL> mainlayout . addWidget ( self . titleBar ( ) ) <EOL> mainlayout . addWidget ( widget ) <EOL> mainlayout . setContentsMargins ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> mainlayout . setSpacing ( <NUM_LIT:0> ) <EOL> centralWidget . setLayout ( mainlayout ) <EOL> super ( FMainWindow , self ) . setCentralWidget ( centralWidget ) <EOL> def _initTitleBar ( self , flag = True ) : <EOL> self . _customTitlebarFlag = flag <EOL> if self . _customTitlebarFlag : <EOL> self . _titleBar = FTitleBar ( ) <EOL> def _initTitlebarConnect ( self ) : <EOL> if self . isFtitleBarExisted ( ) : <EOL> self . _titleBar . locked . connect ( self . setLocked ) <EOL> self . _titleBar . modeed . connect ( self . setDesktopMode ) <EOL> self . _titleBar . pined . connect ( self . setPined ) <EOL> self . _titleBar . minimized . connect ( self . showMinimized ) <EOL> self . _titleBar . maximized . connect ( self . swithMaxNormal ) <EOL> def isFtitleBarExisted ( self ) : <EOL> if self . _customTitlebarFlag : <EOL> if isinstance ( self . _titleBar , FTitleBar ) : <EOL> return True <EOL> return False <EOL> def titleBar ( self ) : <EOL> if self . isFtitleBarExisted ( ) : <EOL> return self . _titleBar <EOL> def _initToolbars ( self ) : <EOL> pass <EOL> def _initStatusbar ( self ) : <EOL> statusbar = FStatusBar ( self ) <EOL> self . setStatusBar ( statusbar ) <EOL> def setWindowIcon ( self , icon ) : <EOL> if not isinstance ( icon , QIcon ) : <EOL> qicon = QIcon ( icon ) <EOL> else : <EOL> qicon = icon <EOL> super ( FMainWindow , self ) . setWindowIcon ( qicon ) <EOL> if self . isFtitleBarExisted ( ) : <EOL> self . _titleBar . setLogo ( qicon ) <EOL> self . systemTray . setIcon ( qicon ) <EOL> self . systemTray . show ( ) <EOL> def setWindowTitle ( self , title ) : <EOL> super ( FMainWindow , self ) . setWindowTitle ( title ) <EOL> if self . isFtitleBarExisted ( ) : <EOL> self . _titleBar . setTitle ( title ) <EOL> def setDesktopMode ( self , flag ) : <EOL> self . _modeflag = flag <EOL> if flag : <EOL> self . resize ( self . phone_size . width ( ) , self . height ( ) ) <EOL> else : <EOL> self . resize ( self . default_size ) <EOL> def isDesktopMode ( self ) : <EOL> return self . _modeflag <EOL> def setPined ( self , flag ) : <EOL> self . _pinflag = flag <EOL> if flag : <EOL> self . setWindowFlags ( self . windowFlags ( ) | Qt . WindowStaysOnTopHint ) <EOL> else : <EOL> self . setWindowFlags ( <EOL> self . windowFlags ( ) & ( ~ Qt . WindowStaysOnTopHint ) ) <EOL> self . show ( ) <EOL> def isPined ( self ) : <EOL> return self . _pinflag <EOL> def setLocked ( self , flag ) : <EOL> self . _lockflag = flag <EOL> def isLocked ( self ) : <EOL> return self . _lockflag <EOL> def moveCenter ( self ) : <EOL> qr = self . frameGeometry ( ) <EOL> cp = QDesktopWidget ( ) . availableGeometry ( ) . center ( ) <EOL> qr . moveCenter ( cp ) <EOL> self . move ( qr . topLeft ( ) ) <EOL> def swithMaxNormal ( self , flag ) : <EOL> self . _maximizedflag = flag <EOL> if self . _maximizedflag : <EOL> self . showMaximized ( ) <EOL> else : <EOL> self . showNormal ( ) <EOL> def showMaximized ( self ) : <EOL> self . resize ( QDesktopWidget ( ) . availableGeometry ( ) . size ( ) ) <EOL> self . moveCenter ( ) <EOL> def showNormal ( self ) : <EOL> self . resize ( self . default_size ) <EOL> self . move ( self . oldPosition ) <EOL> def isMaximized ( self ) : <EOL> return self . _maximizedflag <EOL> def resizeEvent ( self , event ) : <EOL> super ( FMainWindow , self ) . resizeEvent ( event ) <EOL> self . default_size = event . oldSize ( ) <EOL> self . sizeChanged . emit ( ) <EOL> def mousePressEvent ( self , event ) : <EOL> self . setFocus ( ) <EOL> if event . button ( ) == Qt . LeftButton : <EOL> self . dragPosition = event . globalPos ( ) - self . frameGeometry ( ) . topLeft ( ) <EOL> event . accept ( ) <EOL> self . xPos = self . x ( ) <EOL> self . yPos = self . y ( ) <EOL> self . rdragx = event . x ( ) <EOL> self . rdragy = event . y ( ) <EOL> self . currentWidth = self . width ( ) <EOL> self . currentHeight = self . height ( ) <EOL> self . isSideClicked = True <EOL> def mouseReleaseEvent ( self , event ) : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> del self . dragPosition <EOL> self . isSideClicked = False <EOL> self . setCursor ( Qt . ArrowCursor ) <EOL> def mouseMoveEvent ( self , event ) : <EOL> self . oldPosition = self . pos ( ) <EOL> if self . isSideClicked and self . isCusorRightSide : <EOL> w = max ( self . minimumWidth ( ) , <EOL> self . currentWidth + event . x ( ) - self . rdragx ) <EOL> h = self . currentHeight <EOL> self . resize ( w , h ) <EOL> elif self . isSideClicked and self . isCusorDownSide : <EOL> w = self . currentWidth <EOL> h = max ( self . minimumHeight ( ) , <EOL> self . currentHeight + event . y ( ) - self . rdragy ) <EOL> self . resize ( w , h ) <EOL> else : <EOL> if self . isMaximized ( ) : <EOL> event . ignore ( ) <EOL> else : <EOL> if not self . isLocked ( ) : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> if event . buttons ( ) == Qt . LeftButton : <EOL> self . move ( <EOL> event . globalPos ( ) - self . dragPosition ) <EOL> event . accept ( ) <EOL> def eventFilter ( self , obj , event ) : <EOL> if event . type ( ) == QEvent . HoverMove : <EOL> if self . width ( ) - event . pos ( ) . x ( ) < <NUM_LIT:5> : <EOL> self . setCursor ( Qt . SizeHorCursor ) <EOL> self . isCusorRightSide = True <EOL> elif self . height ( ) - event . pos ( ) . y ( ) < <NUM_LIT:5> : <EOL> self . setCursor ( Qt . SizeVerCursor ) <EOL> self . isCusorDownSide = True <EOL> elif not self . isSideClicked : <EOL> self . setCursor ( Qt . ArrowCursor ) <EOL> self . isCusorLeftSide = False <EOL> self . isCusorRightSide = False <EOL> self . isCusorDownSide = False <EOL> return True <EOL> return super ( FMainWindow , self ) . eventFilter ( obj , event ) </s>
