|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
|
''' python 2.7
-wsy_scripts.tools.texture_map_tool
-common_data.py
-make_files.py
-ui.py
-test.py
'''
### common_data.py
import os
Dir = os.path.dirname(__file__)
ConfigPath = Dir + '/config'
WindowStateDataCfgPath = ConfigPath + '/WindowStateData.json'
### make_files.py
import os from common_data import ConfigPath, WindowStateDataCfgPath
def makefile(path):
with open(path, 'w') as f:
f.write('')
Dir, File = 0, 1
def _createFiles(path, type):
if type == Dir:
if not os.path.exists(path):
os.makedirs(path)
elif type == File:
if not os.path.exists(path):
makefile(path)
def createFiles():
for path in [ConfigPath]:
_createFiles(path, Dir)
for path in [WindowStateDataCfgPath]:
_createFiles(path, File)
### ui.py
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
from common_data import WindowStateDataCfgPath
class MainWindow(QMainWindow):
instance = None
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
# ...
self.initWindowState()
def initWindowState(self):
windowStateData = self.getWindowStateData()
if windowStateData:
self.move(*windowStateData['pos'])
self.resize(*windowStateData['size'])
def getWindowStateData(self):
with open(WindowStateDataCfgPath, 'r') as f:
text = f.read()
return json.loads(text) if text else {}
def closeEvent(self, event):
windowStateData = {}
# base
windowStateData['size'] = (self.width(), self.height())
windowStateData['pos'] = (self.x(), self.y())
# more
# ...
windowStateData = json.dumps(windowStateData, indent = 4)
with open(WindowStateDataCfgPath, 'w') as f:
f.write(windowStateData)
def getMayaWindow():
import shiboken2
import maya.OpenMayaUI as omui
from PySide2.QtWidgets import QMainWindow
mayaPtr = omui.MQtUtil.mainWindow()
mayaWindow = shiboken2.wrapInstance(long(mayaPtr), QMainWindow)
return mayaWindow
def create():
from make_files import createFiles
createFiles()
Mainwindows.instance = MainWindow(parent = getMayaWindow())
Mainwindows.instance.show()
### test.py
import wsy_scripts.tools.texture_map_tool.ui as texture_map_tool_ui
texture_map_tool_ui.create()
|