###LANGUAGE:Python
###MODE:BLOCK



    def showMacNativeButtons(self):
        ''' 显示原生 macOS 窗口按钮。 '''
        self._isSystemButtonVisible = True
        self.__nsWindow = objc.objc_object(c_void_p=self.winId().__int__()).window()
        self.__nsWindow.setShowsToolbarButton_(True)

        leftButton = self.__nsWindow.standardWindowButton_(Cocoa.NSWindowCloseButton)
        midButton = self.__nsWindow.standardWindowButton_(Cocoa.NSWindowMiniaturizeButton)
        rightButton = self.__nsWindow.standardWindowButton_(Cocoa.NSWindowZoomButton)

        leftButton.setHidden_(False)
        midButton.setHidden_(False)
        rightButton.setHidden_(False)


        # 获取系统标题按钮
        try:
            titlebar = rightButton.superview()
            titlebarHeight = int(titlebar.frame().size.height)

            spacing = midButton.frame().origin.x - leftButton.frame().origin.x
            width = midButton.frame().size.width
            height = midButton.frame().size.height

            viewSize = self.__nsWindow.contentView().frame().size if self.__nsWindow.contentView() else self.__nsWindow.frame().size
            center = QRect(0, 0, 75, QSize(int(viewSize.width), titlebarHeight).height()).center()
            center.setY(titlebarHeight - center.y())

            centerOrigin = Cocoa.NSPoint(center.x() - width // 2, center.y() - height // 2)
            midButton.setFrameOrigin_(centerOrigin)

            leftButton.setFrameOrigin_(Cocoa.NSPoint(centerOrigin.x - spacing, centerOrigin.y))
            rightButton.setFrameOrigin_(Cocoa.NSPoint(centerOrigin.x + spacing, centerOrigin.y))
        except Exception as e:
            print(f"更新系统按钮位置时发生错误: {e}")
            exit(1)

    def drawWin32Buttons(self):
        ''' 绘制 Windows 窗口按钮。 '''
        pass

    def drawX11Buttons(self):
        ''' 绘制 Linux 窗口按钮。 '''
        pass

    def setWindowTitle(self, title):
        super().setWindowTitle(title)

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    window = FramelessMai
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtCore import Qt, QSize, QRect
from PyQt5.QtGui import QIcon, QWindow, QPainter, QColor
from sys import platform
from darkdetect import isDark
if platform == "darwin":
    import objc, Cocoa

class FramelessMainWindow(QMainWindow):
    ''' A Chrome-like frameless window, with native buttons and designable title bar. '''
    def __init__(self, parent=None):
        super().__init__(parent)
        # 透明背景
        self.setAttribute(Qt.WA_TranslucentBackground)

    def paintEvent(self, event):
        ''' Draw the window frame. '''
        self.painter=QPainter(self)
        self.initPainter(self.painter)
        # 画一个圆角矩形
        self.painter.setPen(Qt.NoPen)
        if isDark():
            self.painter.setBrush(QColor(50, 50, 50, 255))
        else:
            self.painter.setBrush(QColor(230, 230, 230, 255))
        self.painter.drawRoundedRect(self.rect(), 10, 10)
        # 画标题栏按钮
        if platform == "darwin":
            self.showMacNativeButtons()
        elif platform == "win32":
            self.drawWin32Buttons()
        else:
            self.drawX11Buttons()
        self.painter.end()
        # 无边框
        #self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
        #Here