| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import sys |
| 9 |
sys.dont_write_bytecode = True |
| 10 |
|
| 11 |
import os |
| 12 |
import string |
| 13 |
|
| 14 |
try: |
| 15 |
from PyQt6 import QtWidgets, QtGui, QtCore |
| 16 |
except ImportError: |
| 17 |
print('Error: PyQt6 package not found\nError: required packages: PyQt6 and python3-pyqt6.qsci\nError: program aborted.') |
| 18 |
sys.exit(-1) |
| 19 |
|
| 20 |
try: |
| 21 |
from PyQt6.QtWidgets import * |
| 22 |
from PyQt6.QtGui import * |
| 23 |
from PyQt6.QtCore import * |
| 24 |
from PyQt6 import uic |
| 25 |
from view import EdView, EdViewRW, ResView, FileView, CallView, ClassGraphView, FileFuncGraphView |
| 26 |
from view import DebugView, CodemarkView, CodeContextView |
| 27 |
from view import ProjectUi |
| 28 |
import backend |
| 29 |
import DialogManager |
| 30 |
import view |
| 31 |
except ImportError as e: |
| 32 |
print(str(e)) |
| 33 |
print("Error: failed to import supporting packages.\nError: program aborted.") |
| 34 |
sys.exit(-1) |
| 35 |
|
| 36 |
def msg_box(msg): |
| 37 |
QMessageBox.warning(None, "Seascope", msg, QMessageBox.StandardButton.Ok) |
| 38 |
|
| 39 |
class BackendChooserDialog(QDialog): |
| 40 |
def __init__(self): |
| 41 |
QDialog.__init__(self) |
| 42 |
self.ui = uic.loadUi('ui/proj_new.ui', self) |
| 43 |
self.backend_lw.currentRowChanged.connect(self.currentRowChanged_cb) |
| 44 |
|
| 45 |
self.backend = backend |
| 46 |
|
| 47 |
def currentRowChanged_cb(self, row): |
| 48 |
if row == -1: |
| 49 |
return |
| 50 |
bname = str(self.backend_lw.currentItem().text()) |
| 51 |
desc = '' |
| 52 |
for b in self.backend.plugin_list(): |
| 53 |
if b.name() == bname: |
| 54 |
desc = b.description() |
| 55 |
self.descr_te.setText(desc) |
| 56 |
|
| 57 |
def run_dialog(self): |
| 58 |
blist = self.backend.plugin_list() |
| 59 |
if len(blist) == 0: |
| 60 |
msg_box('No backends are available/usable') |
| 61 |
return None |
| 62 |
bi = [ b.name() for b in blist ] |
| 63 |
self.backend_lw.addItems(bi) |
| 64 |
self.backend_lw.setCurrentRow(0) |
| 65 |
if self.exec() == QDialog.DialogCode.Accepted: |
| 66 |
bname = str(self.backend_lw.currentItem().text()) |
| 67 |
return bname |
| 68 |
return None |
| 69 |
|
| 70 |
class QueryUiHelper: |
| 71 |
def __init__(self): |
| 72 |
self.edit_book = None |
| 73 |
self.res_book = None |
| 74 |
self.call_view = None |
| 75 |
self.class_graph_view = None |
| 76 |
self.file_func_graph_view = None |
| 77 |
self.dbg_view = None |
| 78 |
self.file_view = None |
| 79 |
|
| 80 |
def editor_current_file(self): |
| 81 |
(f, l) = self.edit_book.get_current_file_line() |
| 82 |
return f |
| 83 |
|
| 84 |
def editor_current_word(self): |
| 85 |
return self.edit_book.get_current_word() |
| 86 |
|
| 87 |
def result_page_new(self, name, sig_res): |
| 88 |
if sig_res == None: |
| 89 |
return |
| 90 |
page = self.res_book.create_result_page(name) |
| 91 |
|
| 92 |
sig_res[0].connect(page.add_result) |
| 93 |
|
| 94 |
self.dbg_view.connect_to_sig(sig_res[1]) |
| 95 |
|
| 96 |
def file_view_update(self, flist): |
| 97 |
self.file_view.add_files(flist) |
| 98 |
|
| 99 |
def _quick_def_result(self, req, res): |
| 100 |
count = len(res) |
| 101 |
if count > 1: |
| 102 |
page = self.res_book.create_result_page_single() |
| 103 |
page.add_result(req, res) |
| 104 |
|
| 105 |
dlg = QDialog() |
| 106 |
dlg.setWindowTitle('Quick Definition: ' + req) |
| 107 |
vlay = QVBoxLayout(dlg) |
| 108 |
vlay.addWidget(page) |
| 109 |
|
| 110 |
page.sig_show_file_line.connect(self.edit_book.show_file_line) |
| 111 |
page.activated.connect(dlg.accept) |
| 112 |
page.setMinimumWidth(800) |
| 113 |
page.setMinimumHeight(100) |
| 114 |
|
| 115 |
dlg.exec() |
| 116 |
return |
| 117 |
|
| 118 |
if (count == 1): |
| 119 |
filename = res[0][1] |
| 120 |
try: |
| 121 |
line = int(res[0][2]) |
| 122 |
except: |
| 123 |
return |
| 124 |
self.edit_book.show_file_line(filename, line) |
| 125 |
|
| 126 |
def quick_def_page_new(self, sig_res): |
| 127 |
if sig_res == None: |
| 128 |
return |
| 129 |
sig_res[0].connect(self._quick_def_result) |
| 130 |
self.dbg_view.connect_to_sig(sig_res[1]) |
| 131 |
|
| 132 |
def call_view_page_new(self, req, query_func, ctree_query_args, opt): |
| 133 |
hint_file = self.editor_current_file() |
| 134 |
self.call_view.create_page(req, query_func, ctree_query_args, opt, hint_file) |
| 135 |
|
| 136 |
def class_graph_view_page_new(self, req, dname, prj_type, query_func, clgraph_query_args, opt): |
| 137 |
self.class_graph_view.create_page(req, dname, prj_type, query_func, clgraph_query_args, opt) |
| 138 |
|
| 139 |
def file_func_graph_view_page_new(self, req, dname, proj_dir, query_func, ffgraph_query_args, opt): |
| 140 |
self.file_func_graph_view.create_page(req, dname, proj_dir, query_func, ffgraph_query_args, opt) |
| 141 |
|
| 142 |
|
| 143 |
class QueryDialogUi(QDialog): |
| 144 |
def __init__(self, title, feat): |
| 145 |
QDialog.__init__(self) |
| 146 |
|
| 147 |
self.feat = feat |
| 148 |
self.ui = uic.loadUi('ui/query.ui', self) |
| 149 |
self.qd_sym_inp.setCompleter(None) |
| 150 |
self.qd_sym_inp.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) |
| 151 |
|
| 152 |
self.setWindowTitle(title) |
| 153 |
self.qd_cmd_inp.addItems(self.feat.cmd_qstrlist) |
| 154 |
|
| 155 |
def run_dialog(self, cmd_str, req): |
| 156 |
qstr = self.feat.cmd_str2qstr[cmd_str] |
| 157 |
inx = self.qd_cmd_inp.findText(qstr) |
| 158 |
self.qd_cmd_inp.setCurrentIndex(inx) |
| 159 |
if req == None: |
| 160 |
req = '' |
| 161 |
self.qd_sym_inp.setFocus() |
| 162 |
self.qd_sym_inp.setEditText(req) |
| 163 |
self.qd_sym_inp.lineEdit().selectAll() |
| 164 |
self.qd_substr_chkbox.setChecked(False) |
| 165 |
self.qd_icase_chkbox.setChecked(False) |
| 166 |
|
| 167 |
self.show() |
| 168 |
if self.exec() == QDialog.DialogCode.Accepted: |
| 169 |
req = str(self.qd_sym_inp.currentText()) |
| 170 |
cmd = str(self.qd_cmd_inp.currentText()) |
| 171 |
cmd_str = self.feat.cmd_qstr2str[cmd] |
| 172 |
|
| 173 |
in_opt = { |
| 174 |
'substring' : self.qd_substr_chkbox.isChecked(), |
| 175 |
'ignorecase' : self.qd_icase_chkbox.isChecked(), |
| 176 |
} |
| 177 |
res = self.feat.query_dlg_cb(req, cmd_str, in_opt) |
| 178 |
return res |
| 179 |
return None |
| 180 |
|
| 181 |
def show_dlg(self, cmd_str, req): |
| 182 |
return self.run_dialog(cmd_str, req) |
| 183 |
|
| 184 |
class QueryUi(QObject): |
| 185 |
def __init__(self, h): |
| 186 |
QObject.__init__(self) |
| 187 |
self.qui_h = h |
| 188 |
self.backend = backend |
| 189 |
self.backend_menu = None |
| 190 |
self.prj_actions = [] |
| 191 |
|
| 192 |
self.feat = None |
| 193 |
self.qry_ui = None |
| 194 |
|
| 195 |
def set_backend_menu(self, menu): |
| 196 |
self.backend_menu = menu |
| 197 |
self.backend_menu.triggered.connect(self.menu_cb) |
| 198 |
|
| 199 |
def setup(self): |
| 200 |
self.prepare_menu() |
| 201 |
for act in self.prj_actions: |
| 202 |
act.setEnabled(True) |
| 203 |
|
| 204 |
self.feat = self.backend.proj_feature() |
| 205 |
t = backend.proj_type().title() + ' Query' |
| 206 |
self.qry_ui = QueryDialogUi(t, self.feat) |
| 207 |
|
| 208 |
self.query_file_list() |
| 209 |
|
| 210 |
def reset(self): |
| 211 |
self.backend_menu.clear() |
| 212 |
self.backend_menu.setTitle('') |
| 213 |
for act in self.prj_actions: |
| 214 |
act.setEnabled(False) |
| 215 |
|
| 216 |
self.feat = None |
| 217 |
self.qry_ui = None |
| 218 |
|
| 219 |
def editor_current_file(self): |
| 220 |
return self.qui_h.editor_current_file() |
| 221 |
|
| 222 |
def editor_current_word(self): |
| 223 |
return self.qui_h.editor_current_word() |
| 224 |
|
| 225 |
def prepare_menu(self): |
| 226 |
td = { |
| 227 |
'idutils' : '&Idutils', |
| 228 |
'gtags' : 'G&tags', |
| 229 |
'cscope' : '&Cscope', |
| 230 |
} |
| 231 |
t = td[self.backend.proj_type()] |
| 232 |
menu = self.backend_menu |
| 233 |
menu.setTitle(t) |
| 234 |
feat = self.backend.proj_feature() |
| 235 |
for c in feat.menu_cmd_list: |
| 236 |
if c[0] == '---': |
| 237 |
menu.addSeparator() |
| 238 |
continue |
| 239 |
if c[2] == None: |
| 240 |
if c[0] == 'UPD': |
| 241 |
func = self.rebuild_cb |
| 242 |
act = menu.addAction(c[1], func) |
| 243 |
act.cmd_str = None |
| 244 |
else: |
| 245 |
act = menu.addAction(c[1]) |
| 246 |
act.setShortcut(c[2]) |
| 247 |
act.cmd_str = c[0] |
| 248 |
|
| 249 |
def menu_cb(self, act): |
| 250 |
if act.cmd_str != None: |
| 251 |
self.query_cb(act.cmd_str) |
| 252 |
|
| 253 |
def query_cb(self, cmd_str): |
| 254 |
if not backend.proj_conf(): |
| 255 |
return |
| 256 |
if not backend.proj_is_ready(): |
| 257 |
show_msg_dialog('\nProject has no source files') |
| 258 |
return |
| 259 |
|
| 260 |
if cmd_str == 'CLGRAPHD': |
| 261 |
f = self.editor_current_file() |
| 262 |
if f: |
| 263 |
d = os.path.dirname(f) |
| 264 |
self.query_class_graph_dir(d) |
| 265 |
return |
| 266 |
if cmd_str == 'FFGRAPH': |
| 267 |
f = self.editor_current_file() |
| 268 |
if f: |
| 269 |
self.query_file_func_graph(f) |
| 270 |
return |
| 271 |
|
| 272 |
req = self.editor_current_word() |
| 273 |
if (req != None): |
| 274 |
req = str(req).strip() |
| 275 |
opt = None |
| 276 |
if cmd_str not in [ 'QDEF' ]: |
| 277 |
val = self.qry_ui.show_dlg(cmd_str, req) |
| 278 |
if val == None: |
| 279 |
return |
| 280 |
(cmd_str, req, opt) = val |
| 281 |
if (req == None or req == ''): |
| 282 |
return |
| 283 |
|
| 284 |
if cmd_str == 'QDEF': |
| 285 |
self.query_qdef(req, opt) |
| 286 |
elif cmd_str == 'CTREE': |
| 287 |
self.query_ctree(req, opt) |
| 288 |
elif cmd_str == 'CLGRAPH': |
| 289 |
self.query_class_graph(req, opt) |
| 290 |
else: |
| 291 |
self.do_query(cmd_str, req, opt) |
| 292 |
|
| 293 |
def do_proj_query(self, rquery): |
| 294 |
print('do_proj_query', rquery) |
| 295 |
sig_res = self.backend.proj_query(rquery) |
| 296 |
return sig_res |
| 297 |
|
| 298 |
def query_ctree(self, req, opt): |
| 299 |
self.qui_h.call_view_page_new(req, self.do_proj_query, self.feat.ctree_query_args, opt) |
| 300 |
|
| 301 |
def query_class_graph(self, req, opt): |
| 302 |
prj_type = self.backend.proj_type() |
| 303 |
prj_dir = self.backend.proj_dir() |
| 304 |
self.qui_h.class_graph_view_page_new(req, prj_dir, prj_type, self.do_proj_query, self.feat.clgraph_query_args, opt) |
| 305 |
|
| 306 |
def query_class_graph_dir(self, dname): |
| 307 |
opt = [] |
| 308 |
self.qui_h.class_graph_view_page_new('', dname, None, self.do_proj_query, self.feat.clgraph_query_args, opt) |
| 309 |
|
| 310 |
def query_file_func_graph(self, fname): |
| 311 |
opt = [] |
| 312 |
self.qui_h.file_func_graph_view_page_new('', fname, '', self.do_proj_query, self.feat.ffgraph_query_args, opt) |
| 313 |
|
| 314 |
def _prepare_rquery(self, cmd_str, req, opt): |
| 315 |
rquery = {} |
| 316 |
rquery['cmd'] = cmd_str |
| 317 |
rquery['req'] = req |
| 318 |
rquery['opt'] = opt |
| 319 |
|
| 320 |
rquery['hint_file'] = self.editor_current_file() |
| 321 |
return rquery |
| 322 |
|
| 323 |
def query_qdef(self, req, opt): |
| 324 |
rquery = {} |
| 325 |
rquery = self._prepare_rquery('DEF', req, opt) |
| 326 |
sig_res = self.do_proj_query(rquery) |
| 327 |
self.qui_h.quick_def_page_new(sig_res) |
| 328 |
|
| 329 |
def do_query(self, cmd_str, req, opt): |
| 330 |
|
| 331 |
name = cmd_str + ' ' + req |
| 332 |
rquery = self._prepare_rquery(cmd_str, req, opt) |
| 333 |
sig_res = self.do_proj_query(rquery) |
| 334 |
self.qui_h.result_page_new(name, sig_res) |
| 335 |
|
| 336 |
def do_rebuild(self): |
| 337 |
sig_rebuild = self.backend.proj_rebuild() |
| 338 |
if not sig_rebuild: |
| 339 |
return |
| 340 |
dlg = QProgressDialog() |
| 341 |
dlg.setWindowTitle('Seascope rebuild') |
| 342 |
dlg.setLabelText('Rebuilding database...') |
| 343 |
dlg.setCancelButton(None) |
| 344 |
dlg.setMinimum(0) |
| 345 |
dlg.setMaximum(0) |
| 346 |
sig_rebuild.connect(dlg.accept) |
| 347 |
while dlg.exec() != QDialog.DialogCode.Accepted: |
| 348 |
pass |
| 349 |
self.query_file_list() |
| 350 |
|
| 351 |
|
| 352 |
def rebuild_cb(self): |
| 353 |
self.do_rebuild() |
| 354 |
|
| 355 |
def query_file_list(self): |
| 356 |
sig_res = self.backend.proj_query_fl() |
| 357 |
if sig_res == None: |
| 358 |
return |
| 359 |
if isinstance(sig_res , list): |
| 360 |
fl = sig_res |
| 361 |
self.qui_h.file_view_update(fl) |
| 362 |
return |
| 363 |
sig_res.connect(self.qui_h.file_view_update) |
| 364 |
|
| 365 |
class SeascopeApp(QMainWindow): |
| 366 |
|
| 367 |
def file_preferences_cb(self): |
| 368 |
ev_font = QFont() |
| 369 |
ev_font.fromString(self.edit_book.ev_font) |
| 370 |
res = DialogManager.show_preferences_dialog(self.app_style, self.edit_ext_cmd, ev_font, self.exit_dont_ask, self.inner_editing, self.eb_is_show_line) |
| 371 |
(self.app_style, self.app_font, self.edit_ext_cmd, self.ev_font, self.exit_dont_ask, self.inner_editing_conf, self.eb_is_show_line) = res |
| 372 |
if self.edit_ext_cmd != None: |
| 373 |
self.edit_ext_cmd = str(self.edit_ext_cmd).strip() |
| 374 |
if (self.edit_ext_cmd == None or self.edit_ext_cmd == ''): |
| 375 |
self.edit_ext_cmd = 'x-terminal-emulator -e vim %F +%L' |
| 376 |
self.edit_book.change_ev_font(self.ev_font) |
| 377 |
self.code_ctx_view.change_ev_font(self.ev_font) |
| 378 |
self.edit_book.show_line_number_pref(self.eb_is_show_line) |
| 379 |
self.app_write_config() |
| 380 |
|
| 381 |
def file_close_cb(self): |
| 382 |
self.edit_book.close_current_page() |
| 383 |
def closeEvent(self, ev): |
| 384 |
if not self.exit_dont_ask and backend.proj_is_open(): |
| 385 |
ret = DialogManager.show_yes_no_dontask('Close project and quit?') |
| 386 |
if ret == 1: |
| 387 |
ev.ignore() |
| 388 |
return |
| 389 |
if ret == 2: |
| 390 |
self.exit_dont_ask = True |
| 391 |
|
| 392 |
|
| 393 |
if self.inner_editing: |
| 394 |
self.edit_book.close_all_cb() |
| 395 |
|
| 396 |
self.app_write_config() |
| 397 |
if backend.proj_is_open(): |
| 398 |
self.app_gui_state_save(backend.proj_dir()) |
| 399 |
ev.accept() |
| 400 |
def file_restart_cb(self): |
| 401 |
if not DialogManager.show_yes_no('Restart ?'): |
| 402 |
return |
| 403 |
hint = self.edit_book.get_file_line_list() |
| 404 |
if backend.proj_is_open(): |
| 405 |
self.proj_close_cb() |
| 406 |
QApplication.quit() |
| 407 |
os.environ['SEASCOPE_RESTART_HINT'] = '%s' % str(hint) |
| 408 |
QProcess.startDetached(sys.executable, QApplication.arguments(), self.seascope_start_dir); |
| 409 |
def file_restarted_cb(self): |
| 410 |
try: |
| 411 |
hint = os.environ['SEASCOPE_RESTART_HINT'] |
| 412 |
|
| 413 |
fll = eval(hint) |
| 414 |
for fl in fll: |
| 415 |
try: |
| 416 |
(f, l) = fl.rsplit(':', 1) |
| 417 |
l = int(l) |
| 418 |
self.edit_book.show_file_line(f, l, hist=False) |
| 419 |
except Exception as e: |
| 420 |
print(e) |
| 421 |
except: |
| 422 |
pass |
| 423 |
|
| 424 |
def codemark_add(self, f, l): |
| 425 |
self.cm_mgr.append(f, l) |
| 426 |
self.edit_book.codemark_add(f, l - 1) |
| 427 |
actionText = f + " : " + str(l) |
| 428 |
act = QAction(actionText, self) |
| 429 |
self.cm_actionGroup.addAction(act) |
| 430 |
self.m_cm.addAction(act) |
| 431 |
|
| 432 |
def codemark_delete(self, f, l): |
| 433 |
self.cm_mgr.delete(f, l) |
| 434 |
self.edit_book.codemark_del(f, l - 1) |
| 435 |
actionText = f + " : " + str(l) |
| 436 |
actions = self.cm_actionGroup.actions() |
| 437 |
for act in actions: |
| 438 |
if actionText == act.text(): |
| 439 |
self.cm_actionGroup.removeAction(act) |
| 440 |
|
| 441 |
def codemark_toggle_cb(self): |
| 442 |
(f, l) = self.edit_book.get_current_file_line() |
| 443 |
if self.cm_mgr.check(f, l) == 0: |
| 444 |
self.codemark_add(f, l) |
| 445 |
else: |
| 446 |
self.codemark_delete(f, l) |
| 447 |
|
| 448 |
def codemark_del_file_cb(self, filename): |
| 449 |
if filename == '': |
| 450 |
return |
| 451 |
for f, l in reversed(self.cm_mgr.codemarks()): |
| 452 |
if f == filename: |
| 453 |
self.codemark_delete(f, l) |
| 454 |
|
| 455 |
def codemark_del_all_cb(self): |
| 456 |
if not self.cm_mgr.count(): |
| 457 |
return |
| 458 |
if not DialogManager.show_yes_no('Delete all codemarks ?'): |
| 459 |
return |
| 460 |
for f, l in reversed(self.cm_mgr.codemarks()): |
| 461 |
self.codemark_delete(f, l) |
| 462 |
|
| 463 |
def codemark_go(self, action): |
| 464 |
for f, l in self.cm_mgr.codemarks(): |
| 465 |
actionText = f + " : " + str(l) |
| 466 |
if action.text() == actionText: |
| 467 |
self.edit_book.show_file_line(f, l) |
| 468 |
def go_prev_res_cb(self): |
| 469 |
self.res_book.go_next_res(-1) |
| 470 |
def go_next_res_cb(self): |
| 471 |
self.res_book.go_next_res(+1) |
| 472 |
def go_prev_pos_cb(self): |
| 473 |
self.res_book.go_next_history(-1) |
| 474 |
def go_next_pos_cb(self): |
| 475 |
self.res_book.go_next_history(+1) |
| 476 |
def go_pos_history_cb(self): |
| 477 |
self.res_book.show_history() |
| 478 |
def go_search_file_list_cb(self): |
| 479 |
self.file_view.search_file_cb() |
| 480 |
def go_search_ctags_cb(self): |
| 481 |
self.edit_book.focus_search_ctags() |
| 482 |
|
| 483 |
def help_about_cb(self): |
| 484 |
DialogManager.show_about_dialog() |
| 485 |
|
| 486 |
def external_editor_cb(self): |
| 487 |
self.edit_book.open_in_external_editor(self.edit_ext_cmd) |
| 488 |
|
| 489 |
def show_dbg_dialog(self): |
| 490 |
DebugView.show_dbg_dialog(self) |
| 491 |
|
| 492 |
def create_mbar(self): |
| 493 |
menubar = self.menuBar() |
| 494 |
|
| 495 |
m_file = menubar.addMenu('&File') |
| 496 |
m_file.addAction('&Preferences', self.file_preferences_cb) |
| 497 |
m_file.addAction('&Debug', 'Ctrl+D', self.show_dbg_dialog) |
| 498 |
m_file.addSeparator() |
| 499 |
if self.inner_editing: |
| 500 |
m_file.addAction('&Save', self.edit_book.save_current_page, 'Ctrl+S') |
| 501 |
m_file.addAction('&Close', 'Ctrl+W', self.file_close_cb) |
| 502 |
m_file.addSeparator() |
| 503 |
m_file.addAction('&Restart', 'Ctrl+R', self.file_restart_cb) |
| 504 |
m_file.addAction('&Quit', 'Ctrl+Q', self.close) |
| 505 |
|
| 506 |
m_edit = menubar.addMenu('&Edit') |
| 507 |
|
| 508 |
if self.inner_editing: |
| 509 |
m_edit.addAction('Undo', 'Ctrl+Z', self.edit_book.undo_edit_cb) |
| 510 |
m_edit.addAction('Rebo', 'Ctrl+Y', self.edit_book.redo_edit_cb) |
| 511 |
m_edit.addSeparator() |
| 512 |
m_edit.addAction('Copy', 'Ctrl+C', self.edit_book.copy_edit_cb) |
| 513 |
if self.inner_editing: |
| 514 |
m_edit.addAction('Paste', 'Ctrl+V', self.edit_book.paste_edit_cb) |
| 515 |
m_edit.addAction('Cut', 'Ctrl+X', self.edit_book.cut_edit_cb) |
| 516 |
m_edit.addSeparator() |
| 517 |
|
| 518 |
m_edit.addAction('&Find...', 'Ctrl+F', self.edit_book.find_cb) |
| 519 |
m_edit.addAction('Find &Next', 'F3', self.edit_book.find_next_cb) |
| 520 |
m_edit.addAction('Find &Previous', 'Shift+F3', self.edit_book.find_prev_cb) |
| 521 |
|
| 522 |
m_edit.addSeparator() |
| 523 |
self.edit_book.m_show_line_num = m_edit.addAction('Show line number', 'F11', self.edit_book.show_line_number_cb) |
| 524 |
self.edit_book.m_show_line_num.setCheckable(True) |
| 525 |
self.edit_book.m_show_line_num.setChecked(True) |
| 526 |
self.show_toolbar = m_edit.addAction('Show toolbar', 'F4', self.show_toolbar_cb) |
| 527 |
self.show_toolbar.setCheckable(True) |
| 528 |
|
| 529 |
m_edit.addSeparator() |
| 530 |
self.edit_book.m_show_folds = m_edit.addAction('Show folds', self.edit_book.show_folds_cb) |
| 531 |
self.edit_book.m_show_folds.setCheckable(True) |
| 532 |
self.toggle_folds = m_edit.addAction('Toggle folds', self.edit_book.toggle_folds_cb) |
| 533 |
|
| 534 |
m_edit.addSeparator() |
| 535 |
m_edit.addAction('Refresh file', 'F5', self.edit_book.refresh_file_cb) |
| 536 |
m_edit.addAction('Matching brace', 'Ctrl+6', self.edit_book.matching_brace_cb) |
| 537 |
m_edit.addAction('Goto line', 'Ctrl+G', self.edit_book.goto_line_cb) |
| 538 |
m_edit.addAction('External editor', 'Ctrl+E', self.external_editor_cb); |
| 539 |
|
| 540 |
m_prj = menubar.addMenu('&Project') |
| 541 |
m_prj.addAction('&New Project', self.proj_new_cb) |
| 542 |
m_prj.addAction('&Open Project', self.proj_open_cb) |
| 543 |
m_prj.addSeparator() |
| 544 |
|
| 545 |
act = m_prj.addAction('&Settings', self.proj_settings_cb) |
| 546 |
act.setDisabled(True) |
| 547 |
self.qui.prj_actions.append(act) |
| 548 |
act = m_prj.addAction('&Close Project', self.proj_close_cb) |
| 549 |
act.setDisabled(True) |
| 550 |
self.qui.prj_actions.append(act) |
| 551 |
|
| 552 |
self.backend_menu = menubar.addMenu('') |
| 553 |
|
| 554 |
self.m_cm = menubar.addMenu('&Codemark') |
| 555 |
self.m_cm.addAction('Toggle codemark', 'Ctrl+B', self.codemark_toggle_cb) |
| 556 |
self.m_cm.addAction('Delete all codemarks', '', self.codemark_del_all_cb) |
| 557 |
self.m_cm.addSeparator() |
| 558 |
self.m_cm.addAction('Previous bookmark', 'Alt+PgUp', self.edit_book.bookmark_prev_cb) |
| 559 |
self.m_cm.addAction('Next bookmark', 'Alt+PgDown', self.edit_book.bookmark_next_cb) |
| 560 |
self.m_cm.addSeparator() |
| 561 |
self.cm_actionGroup = QActionGroup(self, triggered=self.codemark_go) |
| 562 |
|
| 563 |
m_go = menubar.addMenu('&Go') |
| 564 |
m_go.addAction('Previous Result', 'Alt+Up', self.go_prev_res_cb) |
| 565 |
m_go.addAction('Next Result', 'Alt+Down', self.go_next_res_cb) |
| 566 |
m_go.addSeparator() |
| 567 |
m_go.addAction('Previous Position', 'Alt+Left', self.go_prev_pos_cb) |
| 568 |
m_go.addAction('Next Position', 'Alt+Right', self.go_next_pos_cb) |
| 569 |
m_go.addAction('Position History', 'Ctrl+H', self.go_pos_history_cb) |
| 570 |
m_go.addSeparator() |
| 571 |
m_go.addAction('Search file list', 'Ctrl+Shift+O', self.go_search_file_list_cb) |
| 572 |
m_go.addAction('Search ctags', 'Ctrl+Shift+T', self.go_search_ctags_cb) |
| 573 |
|
| 574 |
m_help = menubar.addMenu('&Help') |
| 575 |
m_help.addAction('About Seascope', self.help_about_cb) |
| 576 |
m_help.addAction('About Qt', QApplication.aboutQt) |
| 577 |
|
| 578 |
def create_toolbar(self): |
| 579 |
self.toolbar = self.addToolBar('Toolbar') |
| 580 |
self.toolbar.setIconSize(QSize(16,16)) |
| 581 |
self.toolbar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly) |
| 582 |
|
| 583 |
si = QApplication.style().standardIcon |
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_TitleBarCloseButton), 'Quit', self.close) |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
if self.inner_editing: |
| 592 |
self.toolbar.addSeparator() |
| 593 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_DialogSaveButton), 'Save', self.edit_book.save_current_page) |
| 594 |
self.toolbar.addSeparator() |
| 595 |
self.toolbar.addAction(QIcon('icons/undo.png'), 'Undo', self.edit_book.undo_edit_cb) |
| 596 |
self.toolbar.addAction(QIcon('icons/redo.png'), 'Redo', self.edit_book.redo_edit_cb) |
| 597 |
self.toolbar.addSeparator() |
| 598 |
self.toolbar.addAction(QIcon('icons/cut.png'), 'Cut', self.edit_book.cut_edit_cb) |
| 599 |
self.toolbar.addAction(QIcon('icons/copy.png'), 'Copy', self.edit_book.copy_edit_cb) |
| 600 |
self.toolbar.addAction(QIcon('icons/paste.png'), 'Paste', self.edit_book.paste_edit_cb) |
| 601 |
self.toolbar.addSeparator() |
| 602 |
self.toolbar.addAction(QIcon('icons/find-replace.png'), 'Find & Replace', self.edit_book.find_cb) |
| 603 |
|
| 604 |
|
| 605 |
self.toolbar.addSeparator() |
| 606 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_FileDialogContentsView), 'Find', self.edit_book.find_cb) |
| 607 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_ArrowDown), 'Find Next', self.edit_book.find_next_cb) |
| 608 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_ArrowUp), 'Find Previous', self.edit_book.find_prev_cb) |
| 609 |
self.toolbar.addSeparator() |
| 610 |
|
| 611 |
self.toolbar.addAction(QIcon('icons/go-jump.png'), 'Go to line', self.edit_book.goto_line_cb) |
| 612 |
self.toolbar.addSeparator() |
| 613 |
|
| 614 |
|
| 615 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_FileDialogListView), 'Search ctags', self.go_search_ctags_cb) |
| 616 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_FileDialogDetailedView), 'Search file list', self.go_search_file_list_cb) |
| 617 |
self.toolbar.addSeparator() |
| 618 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_MediaSeekBackward), 'Previous Result', self.go_prev_res_cb) |
| 619 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_MediaSeekForward), 'Next Result', self.go_next_res_cb) |
| 620 |
self.toolbar.addSeparator() |
| 621 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_MediaSkipBackward), 'Previous Position', self.go_prev_pos_cb) |
| 622 |
self.toolbar.addAction(si(QStyle.StandardPixmap.SP_MediaSkipForward), 'Next Position', self.go_next_pos_cb) |
| 623 |
self.toolbar.addSeparator() |
| 624 |
self.code_ctx_view_act = self.toolbar.addAction(QIcon('icons/codeview.png'), 'Code Quick View', self.code_ctx_view_act_cb) |
| 625 |
self.code_ctx_view_act.setCheckable(True) |
| 626 |
self.code_ctx_view_act.setChecked(self.is_show_code_ctx_view) |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
def app_get_config_file(self): |
| 631 |
config_file = '~/.seascoperc' |
| 632 |
return os.path.expanduser(config_file) |
| 633 |
|
| 634 |
def app_read_config(self): |
| 635 |
self.recent_projects = [] |
| 636 |
self.app_style = None |
| 637 |
self.app_font = None |
| 638 |
self.ev_font = None |
| 639 |
self.exit_dont_ask = False |
| 640 |
self.inner_editing_conf = False |
| 641 |
self.inner_editing = False |
| 642 |
self.is_show_toolbar = False |
| 643 |
self.is_show_code_ctx_view = False |
| 644 |
self.edit_ext_cmd = 'x-terminal-emulator -e vim %F +%L' |
| 645 |
self.eb_is_show_line = False |
| 646 |
|
| 647 |
path = self.app_get_config_file() |
| 648 |
if (not os.path.exists(path)): |
| 649 |
return |
| 650 |
cf = open(path, 'r') |
| 651 |
for line in cf: |
| 652 |
line = line.split('=', 1) |
| 653 |
key = line[0].strip() |
| 654 |
if (key == 'recent_projects'): |
| 655 |
for path in line[1].split(','): |
| 656 |
path=path.strip() |
| 657 |
if (os.path.isdir(path)): |
| 658 |
self.recent_projects.append(path) |
| 659 |
if (key == 'app_style'): |
| 660 |
self.app_style = line[1].split('\n')[0] |
| 661 |
if (key == 'app_font'): |
| 662 |
self.app_font = line[1].split('\n')[0] |
| 663 |
if (key == 'edit_font'): |
| 664 |
self.ev_font = line[1].split('\n')[0] |
| 665 |
if (key == 'edit_show_line_num'): |
| 666 |
if ('true' == line[1].split('\n')[0]): |
| 667 |
self.eb_is_show_line = True |
| 668 |
if (key == 'show_toolbar'): |
| 669 |
if ('true' == line[1].split('\n')[0]): |
| 670 |
self.is_show_toolbar = True |
| 671 |
else: |
| 672 |
self.is_show_toolbar = False |
| 673 |
if (key == 'edit_ext_cmd'): |
| 674 |
self.edit_ext_cmd = line[1] |
| 675 |
if (key == 'exit_dont_ask'): |
| 676 |
if ('true' == line[1].split('\n')[0]): |
| 677 |
self.exit_dont_ask = True |
| 678 |
if (key == 'inner_editing'): |
| 679 |
if ('true' == line[1].split('\n')[0]): |
| 680 |
self.inner_editing_conf = True |
| 681 |
else: |
| 682 |
self.inner_editing_conf = False |
| 683 |
if os.getenv("SEASCOPE_EDIT"): |
| 684 |
self.inner_editing = True |
| 685 |
else: |
| 686 |
self.inner_editing = self.inner_editing_conf |
| 687 |
cf.close() |
| 688 |
|
| 689 |
def app_write_config(self): |
| 690 |
cf = open(self.app_get_config_file(), 'w') |
| 691 |
cf.write('recent_projects' + '=' + ','.join(self.recent_projects)+ '\n') |
| 692 |
if (self.app_style): |
| 693 |
cf.write('app_style' + '=' + self.app_style + '\n') |
| 694 |
if (self.app_font): |
| 695 |
cf.write('app_font' + '=' + self.app_font + '\n') |
| 696 |
if (self.ev_font): |
| 697 |
cf.write('edit_font' + '=' + self.ev_font + '\n') |
| 698 |
if (self.inner_editing_conf): |
| 699 |
cf.write('inner_editing' + '=' + 'true' + '\n') |
| 700 |
else: |
| 701 |
cf.write('inner_editing' + '=' + 'false' + '\n') |
| 702 |
if (self.eb_is_show_line): |
| 703 |
cf.write('edit_show_line_num' + '=' + 'true' + '\n') |
| 704 |
if (self.is_show_toolbar): |
| 705 |
cf.write('show_toolbar' + '=' + 'true' + '\n') |
| 706 |
if (self.exit_dont_ask): |
| 707 |
cf.write('exit_dont_ask' + '=' + 'true' + '\n') |
| 708 |
if (self.edit_ext_cmd): |
| 709 |
cf.write('edit_ext_cmd' + '=' + self.edit_ext_cmd + '\n') |
| 710 |
cf.close() |
| 711 |
|
| 712 |
def app_gui_state_file(self): |
| 713 |
return os.path.expanduser('~/.seascopeguirc') |
| 714 |
|
| 715 |
def app_gui_state_read(self): |
| 716 |
f = self.app_gui_state_file() |
| 717 |
data = None |
| 718 |
try: |
| 719 |
if os.path.exists(f): |
| 720 |
with open(f, 'rb') as fp: |
| 721 |
import json |
| 722 |
data = json.load(fp) |
| 723 |
except Exception as e: |
| 724 |
print('app_gui_state_read:', e) |
| 725 |
return data |
| 726 |
|
| 727 |
def app_gui_state_write(self, data): |
| 728 |
f = self.app_gui_state_file() |
| 729 |
try: |
| 730 |
import io |
| 731 |
import json |
| 732 |
sp = io.StringIO() |
| 733 |
json.dump(data, sp) |
| 734 |
with open(f, 'wb') as fp: |
| 735 |
fp.write(sp.getvalue().encode()) |
| 736 |
except Exception as e: |
| 737 |
print('app_gui_state_write:', e) |
| 738 |
|
| 739 |
def app_gui_get_geometry(self): |
| 740 |
rect = self.geometry() |
| 741 |
return (rect.x(), rect.y(), rect.width(), rect.height()) |
| 742 |
|
| 743 |
def app_gui_set_geometry(self, geometry): |
| 744 |
x = geometry[0] |
| 745 |
y = geometry[1] |
| 746 |
w = geometry[2] |
| 747 |
h = geometry[3] |
| 748 |
self.setGeometry(x, y, w, h) |
| 749 |
|
| 750 |
def app_gui_state_save(self, proj_path): |
| 751 |
pd = {} |
| 752 |
pd ['file_line_list'] = self.edit_book.get_file_line_list() |
| 753 |
pd ['dir_view_list'] = self.file_view.get_dir_view_list() |
| 754 |
pd ['geometry'] = self.app_gui_get_geometry() |
| 755 |
|
| 756 |
try: |
| 757 |
data = self.app_gui_state_read() |
| 758 |
if data == None: |
| 759 |
data = {} |
| 760 |
if 'proj_gui_state' not in data: |
| 761 |
data['proj_gui_state'] = {} |
| 762 |
data['proj_gui_state'][proj_path] = pd |
| 763 |
self.app_gui_state_write(data) |
| 764 |
except Exception as e: |
| 765 |
print('app_gui_state_save:', e) |
| 766 |
|
| 767 |
def app_gui_state_restore(self, proj_path): |
| 768 |
try: |
| 769 |
data = self.app_gui_state_read() |
| 770 |
if data == None: |
| 771 |
return |
| 772 |
pgs = data.pop('proj_gui_state', {}) |
| 773 |
pd = pgs.pop(proj_path, {}) |
| 774 |
for fl in pd.pop('file_line_list', []): |
| 775 |
try: |
| 776 |
(f, l) = fl.rsplit(':', 1) |
| 777 |
l = int(l) |
| 778 |
if os.path.isabs(f) and f.startswith(proj_path) and os.path.isfile(f): |
| 779 |
self.edit_book.show_file_line(f, l, hist=False) |
| 780 |
except: |
| 781 |
pass |
| 782 |
for d in pd.pop('dir_view_list', []): |
| 783 |
if os.path.isabs(d) and f.startswith(proj_path) and os.path.isdir(d): |
| 784 |
self.file_view.open_dir_view(d) |
| 785 |
try: |
| 786 |
self.app_gui_set_geometry(pd ['geometry']) |
| 787 |
except Exception as e: |
| 788 |
print('Geometry configuration not restored') |
| 789 |
|
| 790 |
except Exception as e: |
| 791 |
print('app_gui_state_restore:', e) |
| 792 |
|
| 793 |
def update_recent_projects(self, path): |
| 794 |
if (path == None or path == ""): |
| 795 |
return |
| 796 |
new_list = [path] |
| 797 |
for ele in self.recent_projects: |
| 798 |
if ele != path: |
| 799 |
new_list.append(ele) |
| 800 |
self.recent_projects = new_list |
| 801 |
self.app_write_config() |
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
def proj_new_or_open(self): |
| 806 |
self.qui.setup() |
| 807 |
|
| 808 |
self.editor_tab_changed_cb(None) |
| 809 |
proj_path = backend.proj_dir() |
| 810 |
self.update_recent_projects(proj_path) |
| 811 |
self.app_gui_state_restore(proj_path) |
| 812 |
|
| 813 |
def proj_new_cb(self): |
| 814 |
if backend.proj_is_open(): |
| 815 |
if not DialogManager.show_proj_close(): |
| 816 |
return |
| 817 |
self.proj_close_cb() |
| 818 |
|
| 819 |
dlg = BackendChooserDialog() |
| 820 |
bname = dlg.run_dialog() |
| 821 |
if bname == None: |
| 822 |
return |
| 823 |
|
| 824 |
proj_args = ProjectUi.show_settings_ui(bname, None) |
| 825 |
if not proj_args: |
| 826 |
return |
| 827 |
|
| 828 |
if not backend.proj_new(bname, proj_args): |
| 829 |
return |
| 830 |
|
| 831 |
self.qui.do_rebuild() |
| 832 |
self.proj_new_or_open() |
| 833 |
|
| 834 |
def proj_open(self, proj_path): |
| 835 |
bl = backend.plugin_guess(proj_path) |
| 836 |
if len(bl) == 0: |
| 837 |
msg = "Project '%s': No backend is interested" % proj_path |
| 838 |
msg_box(msg) |
| 839 |
return |
| 840 |
proj_type = bl[0] |
| 841 |
if len(bl) > 1: |
| 842 |
msg = "Project '%s': Many backends interested" % proj_path |
| 843 |
for b in bl: |
| 844 |
msg += '\n\t' + b |
| 845 |
msg += '\n\nGoing ahead with: ' + proj_type |
| 846 |
msg_box(msg) |
| 847 |
print("Project '%s': using '%s' backend" % (proj_path, proj_type)) |
| 848 |
|
| 849 |
rc = backend.proj_open(proj_path, proj_type) |
| 850 |
if not rc: |
| 851 |
print('proj_open', proj_path, 'failed') |
| 852 |
return |
| 853 |
|
| 854 |
self.proj_new_or_open() |
| 855 |
|
| 856 |
def proj_open_cb(self): |
| 857 |
proj_path = DialogManager.show_project_open_dialog(self.recent_projects) |
| 858 |
if proj_path != None: |
| 859 |
if backend.proj_is_open(): |
| 860 |
self.proj_close_cb() |
| 861 |
|
| 862 |
self.proj_open(proj_path) |
| 863 |
|
| 864 |
def proj_close_cb(self): |
| 865 |
proj_path = backend.proj_dir() |
| 866 |
self.update_recent_projects(proj_path) |
| 867 |
self.app_gui_state_save(proj_path) |
| 868 |
self.setWindowTitle("Seascope") |
| 869 |
|
| 870 |
backend.proj_close() |
| 871 |
self.qui.reset() |
| 872 |
|
| 873 |
if self.inner_editing: |
| 874 |
self.edit_book.close_all_cb() |
| 875 |
else: |
| 876 |
self.edit_book.clear() |
| 877 |
|
| 878 |
self.res_book.clear() |
| 879 |
self.file_view.clear() |
| 880 |
self.cm_mgr.clear() |
| 881 |
self.code_ctx_view.clear() |
| 882 |
|
| 883 |
def proj_settings_cb(self): |
| 884 |
proj_args = backend.proj_settings_get() |
| 885 |
proj_args = ProjectUi.show_settings_ui(backend.proj_type(), proj_args) |
| 886 |
if proj_args: |
| 887 |
backend.proj_settings_update(proj_args) |
| 888 |
|
| 889 |
def editor_tab_changed_cb(self, fname): |
| 890 |
|
| 891 |
prj_dir = backend.proj_dir() |
| 892 |
if prj_dir: |
| 893 |
parent = prj_dir |
| 894 |
home_dir = os.path.expanduser('~') |
| 895 |
for i in range(2): |
| 896 |
parent = os.path.dirname(parent) |
| 897 |
if parent == home_dir: |
| 898 |
break |
| 899 |
title = os.path.relpath(prj_dir, parent) |
| 900 |
if not prj_dir: |
| 901 |
title = 'Seascope' |
| 902 |
if fname and fname != '': |
| 903 |
fname = str(fname) |
| 904 |
|
| 905 |
|
| 906 |
title = title + ' - ' + fname |
| 907 |
else: |
| 908 |
fname = 'Seascope' |
| 909 |
title = title + ' - ' + fname |
| 910 |
self.setWindowTitle(title) |
| 911 |
|
| 912 |
def show_file_line(self, filename, line): |
| 913 |
self.edit_book.show_file_line(filename, line) |
| 914 |
|
| 915 |
def show_toolbar_cb(self): |
| 916 |
self.is_show_toolbar = self.show_toolbar.isChecked() |
| 917 |
if self.is_show_toolbar: |
| 918 |
self.create_toolbar() |
| 919 |
else: |
| 920 |
self.removeToolBar(self.toolbar) |
| 921 |
|
| 922 |
def code_ctx_view_act_cb(self): |
| 923 |
self.is_show_code_ctx_view = self.code_ctx_view_act.isChecked() |
| 924 |
if self.is_show_code_ctx_view: |
| 925 |
self.code_ctx_view.show() |
| 926 |
else: |
| 927 |
self.code_ctx_view.hide() |
| 928 |
|
| 929 |
def connect_signals(self): |
| 930 |
self.edit_book.sig_history_update.connect(self.res_book.history_update) |
| 931 |
self.edit_book.sig_tab_changed.connect(self.editor_tab_changed_cb) |
| 932 |
self.res_book.sig_show_file_line.connect(self.edit_book.show_file_line) |
| 933 |
self.file_view.sig_show_file.connect(self.edit_book.show_file) |
| 934 |
self.edit_book.sig_open_dir_view.connect(self.file_view.open_dir_view) |
| 935 |
self.edit_book.sig_file_closed.connect(self.codemark_del_file_cb) |
| 936 |
self.edit_book.sig_editor_text_selected.connect(self.editor_text_selected) |
| 937 |
self.code_ctx_view.sig_codecontext_showfile.connect(self.code_context_showfile_cb) |
| 938 |
|
| 939 |
def editor_text_selected(self, text): |
| 940 |
if self.is_show_code_ctx_view: |
| 941 |
if not self.code_ctx_view.set_cur_query(text): |
| 942 |
return |
| 943 |
rquery = {} |
| 944 |
rquery['cmd'] = 'DEF' |
| 945 |
rquery['req'] = str(text) |
| 946 |
rquery['opt'] = None |
| 947 |
sig_res = backend.prj.qry.query(rquery) |
| 948 |
sig_res[0].connect(self.code_ctx_view_query_res_cb) |
| 949 |
|
| 950 |
def code_ctx_view_query_res_cb(self, sym, res): |
| 951 |
self.code_ctx_view.showResult(sym, res) |
| 952 |
|
| 953 |
def code_context_showfile_cb(self, filename, line): |
| 954 |
self.show_file_line(filename, line) |
| 955 |
|
| 956 |
def setup_widget_tree(self): |
| 957 |
self.hsp = QSplitter(); |
| 958 |
self.hsp.addWidget(self.edit_book) |
| 959 |
self.hsp.addWidget(self.file_view) |
| 960 |
self.hsp.setSizes([700, 1]) |
| 961 |
|
| 962 |
self.vsp = QSplitter(); |
| 963 |
self.vsp.setOrientation(Qt.Orientation.Vertical) |
| 964 |
self.vsp.addWidget(self.hsp) |
| 965 |
self.vsp.addWidget(self.res_book) |
| 966 |
self.hsp_res = QSplitter(); |
| 967 |
self.hsp_res.addWidget(self.res_book) |
| 968 |
self.hsp_res.addWidget(self.code_ctx_view) |
| 969 |
self.vsp.addWidget(self.hsp_res) |
| 970 |
|
| 971 |
self.hsp_res.setSizes([200, 1]) |
| 972 |
self.vsp.setSizes([1, 60]) |
| 973 |
|
| 974 |
self.setCentralWidget(self.vsp) |
| 975 |
self.setWindowTitle('Seascope') |
| 976 |
self.setGeometry(300, 100, 800, 600) |
| 977 |
|
| 978 |
|
| 979 |
QApplication.setWindowIcon(QIcon('icons/seascope.svg')) |
| 980 |
|
| 981 |
|
| 982 |
self.edit_book.is_show_line = self.eb_is_show_line |
| 983 |
self.edit_book.m_show_line_num.setChecked(self.edit_book.is_show_line) |
| 984 |
if (self.ev_font): |
| 985 |
self.edit_book.ev_font = self.ev_font |
| 986 |
self.code_ctx_view.ev_font = self.ev_font |
| 987 |
self.show_toolbar.setChecked(self.is_show_toolbar) |
| 988 |
|
| 989 |
def create_widgets(self): |
| 990 |
self.qui_h = QueryUiHelper() |
| 991 |
self.qui = QueryUi(self.qui_h) |
| 992 |
|
| 993 |
if self.inner_editing: |
| 994 |
self.edit_book = EdViewRW.EditorBookRW() |
| 995 |
else: |
| 996 |
self.edit_book = EdView.EditorBook() |
| 997 |
|
| 998 |
self.res_book = ResView.ResultManager() |
| 999 |
self.file_view = FileView.FileTree() |
| 1000 |
self.cm_mgr = CodemarkView.CodemarkManager() |
| 1001 |
self.code_ctx_view = CodeContextView.CodeContextViewManager() |
| 1002 |
self.code_ctx_view.hide() |
| 1003 |
|
| 1004 |
self.sbar = self.statusBar() |
| 1005 |
self.create_mbar() |
| 1006 |
|
| 1007 |
if self.is_show_toolbar: |
| 1008 |
self.create_toolbar() |
| 1009 |
|
| 1010 |
def setup_widget_hints(self): |
| 1011 |
if self.inner_editing: |
| 1012 |
EdViewRW.EditorView.ev_popup = self.backend_menu |
| 1013 |
else: |
| 1014 |
EdView.EditorView.ev_popup = self.backend_menu |
| 1015 |
|
| 1016 |
CallView.CallTreeWindow.parent = self |
| 1017 |
ClassGraphView.ClassGraphWindow.parent = self |
| 1018 |
FileFuncGraphView.FileFuncGraphWindow.parent = self |
| 1019 |
|
| 1020 |
self.qui.set_backend_menu(self.backend_menu) |
| 1021 |
self.qui_h.edit_book = self.edit_book |
| 1022 |
self.qui_h.res_book = self.res_book |
| 1023 |
self.qui_h.call_view = CallView |
| 1024 |
self.qui_h.class_graph_view = ClassGraphView |
| 1025 |
self.qui_h.file_func_graph_view = FileFuncGraphView |
| 1026 |
self.qui_h.dbg_view = DebugView |
| 1027 |
self.qui_h.file_view = self.file_view |
| 1028 |
|
| 1029 |
def setup_style_and_font(self): |
| 1030 |
if self.app_style: |
| 1031 |
QApplication.setStyle(self.app_style) |
| 1032 |
if self.app_font: |
| 1033 |
font = QFont() |
| 1034 |
font.fromString(self.app_font) |
| 1035 |
QApplication.setFont(font) |
| 1036 |
|
| 1037 |
def __init__(self, parent=None, app_start_dir=None): |
| 1038 |
QMainWindow.__init__(self) |
| 1039 |
self.seascope_start_dir = app_start_dir |
| 1040 |
|
| 1041 |
self.app_read_config() |
| 1042 |
|
| 1043 |
self.create_widgets() |
| 1044 |
self.setup_widget_hints() |
| 1045 |
self.connect_signals() |
| 1046 |
self.setup_widget_tree() |
| 1047 |
self.setup_style_and_font() |
| 1048 |
|
| 1049 |
prj_path = None |
| 1050 |
args = QApplication.arguments() |
| 1051 |
if len(args) == 2: |
| 1052 |
prj_path = str(args[1]) |
| 1053 |
if not os.path.isabs(prj_path): |
| 1054 |
dname = self.seascope_start_dir |
| 1055 |
prj_path = os.path.join(dname, prj_path) |
| 1056 |
|
| 1057 |
if not prj_path or os.getenv('SEASCOPE_RESTART_HINT'): |
| 1058 |
if len(self.recent_projects): |
| 1059 |
prj_path = self.recent_projects[0] |
| 1060 |
if prj_path: |
| 1061 |
self.proj_open(prj_path) |
| 1062 |
|
| 1063 |
|
| 1064 |
self.file_restarted_cb() |
| 1065 |
|
| 1066 |
if __name__ == "__main__": |
| 1067 |
|
| 1068 |
|
| 1069 |
pyqt_required_version = 0x40500 |
| 1070 |
if not QtCore.PYQT_VERSION >= pyqt_required_version: |
| 1071 |
print('Needs pyqt version > 4.5') |
| 1072 |
sys.exit(-1) |
| 1073 |
|
| 1074 |
|
| 1075 |
app_start_dir = os.getcwd() |
| 1076 |
app_dir = os.path.dirname(os.path.realpath(__file__)) |
| 1077 |
os.chdir(app_dir) |
| 1078 |
|
| 1079 |
|
| 1080 |
backend.load_plugins() |
| 1081 |
view.load_plugins() |
| 1082 |
|
| 1083 |
|
| 1084 |
app = QApplication(sys.argv) |
| 1085 |
ma = SeascopeApp(app_start_dir=app_start_dir) |
| 1086 |
ma.show() |
| 1087 |
ret = app.exec() |
| 1088 |
sys.exit(ret) |