public_def.py
8.56 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#define the output path and filename
#value moudle out put to out_value.h
#template file out put to template_head.h
#normal data out put to normal.h
import os
import sys
from read_config import *
g_debug = True
g_project_name = ""
g_current_language = "en"
g_current_location = ""
g_kb_type_enum_list = []
#struct key_type.
g_template_keytype_name =["bg","hlbg","balloon_bg",
"balloon_ratio_height",
"balloon_ratio_width",
"text_color1",
"text_color2",
"hltext_color1",
"hltext_color2",
"bltext_color1",
"bltext_color2",
#"kb_width",
#"kb_height",
"main_regx",
"main_regy",
"aux_regx",
"aux_regy",
"text_size1",
"text_size2",
"hltext_size1",
"hltext_size2",
"bltext_size1",
"bltext_size2"]
g_keyboard_attr = ["kb_height","kb_width","skb_bg",
"key_xmargin","key_ymargin","bitmap_cache_flag",
"needshift_flag", "row_num"]
g_key_attr = ["code","key_type","icon","icon_aux","icon_hl","icon_aux_hl","label",
"label_aux","label_balloon","icon_balloon","code_longpress","label_balloon_longpress",
"icon_balloon_longpress","pos_x","pos_y","height","width","popup_skb",'toggle_index']
g_keys_attr = ["codes", "labels"]
#this is template attr map
g_template_attr_map = {}
g_template_key_type_list = []
g_keytype_index_list = []
g_template_keyboard_map = {}
g_current_lang = "en"
#value/struct
#key:file_name
#value:{}
g_value_map = {}
g_popup_map = {}
g_format_map = {}
g_map_keyboard_attribute = {"skb_qwerty":1, "skb_phn":2, "hw":3, "skb_phone":2, "popup":0}
g_key_list = []
g_key_index = []
g_row_set = {}
g_row_set_index_list = []
g_kb_list = []
g_kb_index_list = []
g_toggle_state_id_list = []
g_toggle_state_index_list = []
g_toggle_key_list = []
g_index_counter = 0
g_toggle_index = 0
##lcd_size
g_lcdw = 0
g_lcdh = 0
dpi_120 = [[240],[320,400,432]]
dpi_160 = [[320],[480]]
dpi_240 = [[480],[800,854]]
global g_dpi_size
g_dpi_size = 0
const_dpi = "160"
g_test_buffer = ""
g_language_list = []
#config global var
g_project_root_path = "../../../../"
g_out_put_folder_name = "..//debug//res_out_put//"
g_out_put_file = "virtual_keyboard3_res.h"
g_out_put_file_head = "virtual_keyboard3_define.h"
g_res_xml_path = "\\VKResourece\\xml\\"
g_res_image_path = "\\VKResourece\\"
g_error_out_put = g_out_put_folder_name + "vkv3_error.txt"
g_error_buf = ""
def get_lcd_size():
global g_lcdw
global g_lcdh
if g_lcdw==0 or g_lcdh == 0:
readLcdSize()
return [g_lcdw, g_lcdh]
def get_dip_size():
global g_dpi_size
global g_lcdw
global g_lcdh
if g_lcdw == 0 or g_lcdh == 0:
readLcdSize()
if g_lcdw in dpi_120[0] and g_lcdh in dpi_120[1]:
g_dpi_size = 120
elif g_lcdw in dpi_160[0] and g_lcdh in dpi_160[1]:
g_dpi_size = 160
elif g_lcdw in dpi_240[0] and g_lcdh in dpi_240[1]:
g_dpi_size = 240
return g_dpi_size
#if you want to get curent path, please input lpath = ""
def getPrePath(lpath,pre_num):
import os
cur_path = ""
if lpath == "" or lpath == 0:
cur_path = os.getcwd()
else:
cur_path = lpath
symbo_list = []
for i in xrange(0, len(cur_path)):
if cur_path[i] == '\\':
if cur_path[i+1] == '\\':
i += 1
symbo_list.append(i)
return cur_path[0: symbo_list[-pre_num]]
def format_color(key, value):
color_map = g_value_map["colors"]
value = value.replace("@color/","")
if value in color_map:
return color_map[value]
return None
def format_dim(key, value):
global g_dpi_size
dim_map = g_value_map["dimen"]["dimen"]
v = value.replace("@dimen/", "")
if v not in dim_map:
return None
return dim_map[v]
def format_draw(key, value):
global g_bg_list1
global g_bg_list2
global g_bg_file_map
ret_str = "0"
fname = value.replace("@drawable/","")
if fname not in g_bg_file_map.keys():
#print fname + "\t" + key + "\t" + value
return ret_str
flist = g_bg_file_map[fname]
if len(flist) > 0:
if flist[0] == 1:
ret_str = g_bg_list1[flist[1]]
elif flist[0] == 2:
ret_str = g_bg_list2[flist[1]]
#print ret_str
return ret_str
def format_xml(key, value):
global g_kb_index_list
value = value.replace("@xml/","")
ret = "-1"
is_rotate = 0
if "_rotate" in value:
is_rotate = 1
value = value.replace("_rotate","")
if "xml-zh-CN/" in value:
value = value.replace("xml-zh-CN/","")
value += '_zh_CN'
else:
if g_current_language:
value += '_' + g_current_language
if g_current_location:
value += '_' + g_current_location
if is_rotate:
value += '_rotate'
if value in g_kb_index_list:
ret = str(g_kb_index_list.index(value))
return ret
def GetSp():
global g_dpi_size
if g_dpi_size == 0:
get_dip_size()
return g_dpi_size
def format_value_dim(key):
dim_value = key
l = g_dpi_size
if "sp" in key:
dim_value = dim_value.replace("sp","*")
if g_dpi_size == 0:
l = get_dip_size()
dim_value += str(l)
dim_value += "/"+const_dpi
elif "dip" in key:
dim_value = dim_value.replace("dip", "*160")
dim_value += "/" + const_dpi
return dim_value
#@xml/, mapx: dict,//attribute
def parseTemplateAttribute(xml_template, mapx):
if xml_template.find("@xml") == -1:
return None
ret_dict = {}
temp = xml_template.replace("@xml/", "")
if temp not in g_template_attr_map:
return None
tmap = g_template_attr_map[temp]
ret_map = mapx
for key in tmap:
if key not in mapx:
ret_map[key] = tmap[key]
return ret_map
#config read
def readProjectConfig():
import os
global g_project_root_path
project_config_path = os.path.join(g_project_root_path,"make.ini")
fcontent = open(project_config_path, "r").read()
fcontent = fcontent.split("\n")
custom = ''
project = ''
for content in fcontent:
if 'custom' in content:
temp_cont = content.split()
if temp_cont != '=' and temp_cont != "":
custom = temp_cont[-1]
if 'project' in content:
temp_cont = content.split()[-1]
if temp_cont != '=' and temp_cont != "":
project = temp_cont
if project:
custom += "_" + project
return custom
def readLcdSize():
global g_project_root_path
global g_project_name
project_name = readProjectConfig()
g_project_name = project_name
project_make_file = "make//" + project_name + ".mak"
project_make_file = os.path.join(g_project_root_path, project_make_file)
cur_string = ["",""]
file = open(project_make_file, "r")
lcd_size = ""
l = 0
is_rotate = 0
lines = file.readlines()
for line in lines:
if line.find("MAIN_LCD_SIZE") != -1:
lcd_size = line
break
if lcd_size:
if "#" in lcd_size:
index = lcd_size.find("#")
lcd_size = lcd_size[0:index]
for i in xrange(0, len(lcd_size)):
if lcd_size[i] == 'X' or lcd_size[i] == 'x':
l = 1
if lcd_size[i] in g_num_list:
cur_string[l] += lcd_size[i]
global g_lcdw
global g_lcdh
g_lcdw = int(cur_string[0])
g_lcdh = int(cur_string[1])
def readLanguageConfig():
file_path = os.path.join(g_project_root_path,"build//")
files = os.listdir(file_path)
fpath = ""
for folder in files:
l = os.path.join(file_path, folder)
if os.path.isdir(l):
files1 = os.listdir(l)
if "log" in files1:
fpath = os.path.join(l,"log//MMI_features.log")
break;
lines = open(fpath,'r').readlines()
#for line in lines:
# if (("[D]"in line) == True) and ((("__MMI_LANG_") in line) == True):
# print line
def checkDir():
if not os.path.exists(g_out_put_folder_name):
os.mkdir(g_out_put_folder_name)