from PyQt5.QtCore import QSettings

"""
Explanation: PyQt5 QSettings Note
保存应用窗口大小和位置的例子
```
    def read_settings(self):
        settings = QSettings("Dormouse", "LakeTai")
        pos = settings.value("pos", QPoint(200, 200))
        size = settings.value("size", QSize(400, 400))
        self.resize(size)
        self.move(pos)
def write_settings(self):
    settings = QSettings("Dormouse", "LakeTai")
    settings.setValue("pos", self.pos())
    settings.setValue("size", self.size())

```
End of explanation
"""


myOrganization = 'MyOrg'  # 组织名称
myApplication = 'MyApp'  # 应用名称
settings = QSettings(myOrganization, myApplication)
settings.setValue("editor/wrapMargin", 68)
print (settings.value("editor/wrapMargin"))
print (settings.value("editor/someth"))

# 如果在程序中多处用到 QSettings ，那么可以一次性定义，然后统一使用
from PyQt5.QtCore import QCoreApplication
QCoreApplication.setOrganizationName("MyOrg2nd")
QCoreApplication.setOrganizationDomain("MyOrg2nd.com")
QCoreApplication.setApplicationName("MyApp2nd")
settings_2nd = QSettings()
print (settings.applicationName())
print (settings_2nd.applicationName())
print (settings_2nd.organizationName())

# 测试键是否存在
settings.contains("editor")
settings.contains("editor/wrapMargin")

settings.remove("editor") #删除一个键，键不存在也不会报错
settings.contains("editor/wrapMargin")

settings.clear()  #清空所有键（只是清空自己添加的，系统固有的还在）
settings.allKeys()  #所有键

settings.fileName() #储存位置

settings_ini = QSettings("conf.ini", QSettings.IniFormat) #使用 ini 文件来储存
settings_ini.fileName()

"""
Explanation: 最简单的用法
End of explanation
"""


