-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal_env.py
More file actions
149 lines (112 loc) · 3.41 KB
/
global_env.py
File metadata and controls
149 lines (112 loc) · 3.41 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# -*- coding: utf-8 -*-
import os
import pickle
recent_file = None
recent_file_name = None
recent_file_dir = None
danmu_data = None
data_saved = True
keep_data = {}
row_count = 20
recent_page = 1
recent_row = 0
def get_value(key, defValue=None):
""" 获得一个全局变量,不存在则返回默认值 """
try:
str1 = 'global ' + key
exec(str1)
val = eval(key)
return val
except KeyError:
return defValue
def get_file_dir():
return recent_file_dir
def get_danmu_text(num, defValue=None):
try:
name_text_node = danmu_data[num].childNodes[0]
return name_text_node.data
except IndexError:
return defValue
def has_danmu_text(num):
try:
danmu_data[num].childNodes[0]
return True
except IndexError:
return False
def get_recent_page_and_row():
if recent_file is None:
return None, None
else:
return recent_page, recent_row
def edit_recent_page_and_row(page, row):
global recent_page, recent_row, pageinfoLabel
if recent_file is None:
recent_page = 1
recent_row = 0
else:
recent_page = page
recent_row = row
num = int(len(danmu_data) / row_count) + 1
pageinfoLabel.setText("%d/%d" % (page, num))
def set_tableWidget_text_and_index(i, text, index):
global tableWidget
item = tableWidget.item(i, 0)
item.setText(text)
tableWidget.verticalHeaderItem(i).setText(str(index))
item.setCheckFlag(get_danmu_whether_del(index))
item.index = index
def keep_data_init():
global keep_data, danmu_data, recent_file_name
keep_data = keep_data
damu_len = len(danmu_data)
keep_data = {
'user_setting': {
'file_name': recent_file_name,
'row_count': 20,
'recent_row': 0
},
'danmu_whether_del': dict.fromkeys(range(damu_len), False)
}
def keep_data_store():
global keep_data, recent_file_name, recent_file_dir, data_saved
(filename, extension) = os.path.splitext(recent_file_name)
filename = filename + '.dmke'
file_path = os.path.join(recent_file_dir, filename)
get_user_setting()['row_count'] = row_count
get_user_setting()['recent_row'] = recent_row
with open(file_path, 'wb') as f:
pickle.dump(keep_data, f)
data_saved = True
def keep_data_read():
global keep_data, recent_file_name, recent_file_dir,row_count,recent_row
(filename, extension) = os.path.splitext(recent_file_name)
filename = filename + '.dmke'
file_path = os.path.join(recent_file_dir, filename)
try:
with open(file_path, 'rb') as f:
read_data = pickle.load(f)
except FileNotFoundError:
row_count = 20
recent_row = 0
return False
if read_data['user_setting']['file_name'] != recent_file_name:
row_count = 20
recent_row = 0
return False
keep_data = read_data
del read_data
row_count = get_user_setting()['row_count']
recent_row = get_user_setting()['recent_row']
return True
def edit_danmu_whether_del(index, flag):
global keep_data, data_saved
keep_data['danmu_whether_del'][index] = flag
data_saved = False
def get_danmu_whether_del(index):
global keep_data
try:
return keep_data['danmu_whether_del'][index]
except KeyError:
return False
def get_user_setting():
return keep_data['user_setting']