@@ -27,14 +27,17 @@ def __init__(self, parent):
27
27
self .button_box .button (QtWidgets .QDialogButtonBox .Cancel ).setText (lng ['Editor' ]['ContentTableWindow' ]['btnCancel' ])
28
28
29
29
def open_exec (self , text : str = None ):
30
- if text is not None :
31
- self .line_edit .setText (text )
32
- ret = self .exec_ ()
33
- if ret == 1 :
34
- print ('name = ' , self .line_edit .text ())
35
- return self .line_edit .text ()
36
- else :
37
- return None
30
+ try :
31
+ if text is not None :
32
+ self .line_edit .setText (text )
33
+ ret = self .exec_ ()
34
+ if ret == 1 :
35
+ print ('name = ' , self .line_edit .text ())
36
+ return self .line_edit .text ()
37
+ else :
38
+ return None
39
+ except Exception :
40
+ traceback .print_exc ()
38
41
39
42
40
43
class ContentTableWindow (QDialog ):
@@ -73,52 +76,55 @@ def __init__(self, parent, folder: str):
73
76
self .files = []
74
77
75
78
def open_exec (self , text : str = None , url : str = None ):
76
- self .list_content .clear ()
77
- self .addindex_combobox .clear ()
78
-
79
- self .files = common .files .list_directory_tree (self .folder , 'html|xhtml' )
80
- files = common .files .list_directory (self .folder , 'html|xhtml' )
81
- self .addindex_combobox .addItem ("" )
82
-
83
- print (self .files )
84
- for file in files :
85
- self .addindex_combobox .addItem (file .replace (self .folder , "" ))
86
-
87
- li = common .files .list_directory (self .folder , "opf" )
88
- data = ''
89
- with open (li [0 ]) as myfile :
90
- data = myfile .read ()
91
- toc_type , chapters = parse_content_table (
92
- data ,
93
- li [0 ].replace (self .folder , '' ).replace (li [0 ][li [0 ].rindex (os .sep ) + 1 :], '' ).replace (os .sep , '/' ),
94
- self .folder
95
- )
96
- for chapter in chapters :
97
- try :
98
- item = QtWidgets .QListWidgetItem ()
99
- item .setText (chapter ['name' ] + " (" + chapter ['src' ] + ")" )
100
- item .setData (97 , chapter ['name' ])
101
- item .setData (98 , chapter ['src' ])
102
-
103
- self .list_content .addItem (item )
104
- except Exception :
105
- traceback .print_exc ()
106
-
107
- ret = self .exec_ ()
108
-
109
- content_table = []
110
- max = self .list_content .count ()
111
- i = 0
112
- while i < max :
113
- child = self .list_content .item (i )
114
- content_table .append ({'name' : child .data (97 ), 'url' : child .data (98 ).replace ("\\ " , "/" )})
115
- i += 1
116
-
117
- print (content_table )
118
- if ret == 1 :
119
- return content_table
120
- else :
121
- return None
79
+ try :
80
+ self .list_content .clear ()
81
+ self .addindex_combobox .clear ()
82
+
83
+ self .files = common .files .list_directory_tree (self .folder , 'html|xhtml' )
84
+ files = common .files .list_directory (self .folder , 'html|xhtml' )
85
+ self .addindex_combobox .addItem ("" )
86
+
87
+ print (self .files )
88
+ for file in files :
89
+ self .addindex_combobox .addItem (file .replace (self .folder , "" ))
90
+
91
+ li = common .files .list_directory (self .folder , "opf" )
92
+ data = ''
93
+ with open (li [0 ]) as myfile :
94
+ data = myfile .read ()
95
+ toc_type , chapters = parse_content_table (
96
+ data ,
97
+ li [0 ].replace (self .folder , '' ).replace (li [0 ][li [0 ].rindex (os .sep ) + 1 :], '' ).replace (os .sep , '/' ),
98
+ self .folder
99
+ )
100
+ for chapter in chapters :
101
+ try :
102
+ item = QtWidgets .QListWidgetItem ()
103
+ item .setText (chapter ['name' ] + " (" + chapter ['src' ] + ")" )
104
+ item .setData (97 , chapter ['name' ])
105
+ item .setData (98 , chapter ['src' ])
106
+
107
+ self .list_content .addItem (item )
108
+ except Exception :
109
+ traceback .print_exc ()
110
+
111
+ ret = self .exec_ ()
112
+
113
+ content_table = []
114
+ max = self .list_content .count ()
115
+ i = 0
116
+ while i < max :
117
+ child = self .list_content .item (i )
118
+ content_table .append ({'name' : child .data (97 ), 'url' : child .data (98 ).replace ("\\ " , "/" )})
119
+ i += 1
120
+
121
+ print (content_table )
122
+ if ret == 1 :
123
+ return content_table
124
+ else :
125
+ return None
126
+ except Exception :
127
+ traceback .print_exc ()
122
128
123
129
def new_index (self ):
124
130
# self.addindex_line_edit = QLineEdit()
0 commit comments