| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import sys |
| 9 |
import os |
| 10 |
import string |
| 11 |
|
| 12 |
from PyQt6 import QtWidgets, QtGui, QtCore, uic |
| 13 |
|
| 14 |
from PyQt6.QtWidgets import * |
| 15 |
from PyQt6.QtGui import * |
| 16 |
from PyQt6.QtCore import * |
| 17 |
|
| 18 |
|
| 19 |
def show_msg_dialog(msg): |
| 20 |
QMessageBox.information(None, "Seascope", msg, QMessageBox.StandardButton.Ok) |
| 21 |
|
| 22 |
def show_yes_no(msg): |
| 23 |
ret = QMessageBox.question(None, "Seascope", msg, QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.Yes) |
| 24 |
return ret == QMessageBox.StandardButton.Yes |
| 25 |
|
| 26 |
def show_yes_no_dontask(msg): |
| 27 |
mb = QMessageBox(None) |
| 28 |
mb.setIcon(QMessageBox.Icon.Question) |
| 29 |
mb.setWindowTitle("Seascope") |
| 30 |
mb.setText(msg) |
| 31 |
mb.addButton('Yes', QMessageBox.ButtonRole.YesRole) |
| 32 |
mb.addButton('No', QMessageBox.ButtonRole.NoRole) |
| 33 |
mb.addButton("Yes, Don't ask again", QMessageBox.ButtonRole.YesRole) |
| 34 |
return mb.exec() |
| 35 |
|
| 36 |
def show_proj_close(): |
| 37 |
return show_yes_no("\nClose current project?") |
| 38 |
|
| 39 |
class ProjectOpenDialog(QObject): |
| 40 |
def __init__(self): |
| 41 |
QObject.__init__(self) |
| 42 |
|
| 43 |
self.dlg = uic.loadUi('ui/proj_open.ui') |
| 44 |
self.dlg.pod_open_btn.setIcon(QFileIconProvider().icon(QFileIconProvider.IconType.Folder)) |
| 45 |
|
| 46 |
self.dlg.pod_open_btn.clicked.connect(self.open_btn_cb) |
| 47 |
self.dlg.accepted.connect(self.ok_btn_cb) |
| 48 |
self.dlg.pod_proj_list.itemSelectionChanged.connect(self.proj_list_change_cb) |
| 49 |
|
| 50 |
def proj_list_change_cb(self): |
| 51 |
item = self.dlg.pod_proj_list.selectedItems()[0] |
| 52 |
proj_dir = str(item.text()) |
| 53 |
self.dlg.pod_proj_name.setText(str(proj_dir)) |
| 54 |
self.path = proj_dir |
| 55 |
|
| 56 |
def open_btn_cb(self): |
| 57 |
fdlg = QFileDialog(None, "Choose project directory") |
| 58 |
fdlg.setFileMode(QFileDialog.FileMode.Directory); |
| 59 |
fdlg.setDirectory(self.dlg.pod_proj_name.text()) |
| 60 |
if (fdlg.exec()): |
| 61 |
proj_dir = fdlg.selectedFiles()[0]; |
| 62 |
self.dlg.pod_proj_name.setText(str(proj_dir)) |
| 63 |
|
| 64 |
def ok_btn_cb(self): |
| 65 |
p = str(self.dlg.pod_proj_name.text()).strip() |
| 66 |
if (p == ''): |
| 67 |
self.dlg.setResult(2) |
| 68 |
return |
| 69 |
p = os.path.normpath(p) |
| 70 |
if (not os.path.isabs(p)): |
| 71 |
show_msg_dialog("\nProject path is not absolute") |
| 72 |
self.dlg.setResult(2) |
| 73 |
return |
| 74 |
if (not os.path.isdir(p)): |
| 75 |
show_msg_dialog("\nProject path is not a directory") |
| 76 |
self.dlg.setResult(2) |
| 77 |
return |
| 78 |
self.path = p |
| 79 |
|
| 80 |
def run_dialog(self, path_list): |
| 81 |
self.path = None |
| 82 |
self.dlg.pod_proj_name.setText('') |
| 83 |
self.dlg.pod_proj_list.addItems(path_list) |
| 84 |
while True: |
| 85 |
ret = self.dlg.exec() |
| 86 |
if (ret == QDialog.DialogCode.Accepted or ret == QDialog.DialogCode.Rejected): |
| 87 |
break |
| 88 |
return self.path |
| 89 |
|
| 90 |
|
| 91 |
def show_project_open_dialog(path_list): |
| 92 |
d = ProjectOpenDialog() |
| 93 |
return d.run_dialog(path_list) |
| 94 |
|
| 95 |
class FilePreferencesDialog(QObject): |
| 96 |
def __init__(self, app_style, edit_ext_cmd, ev_font, dontask, innered, ln_nr): |
| 97 |
QObject.__init__(self) |
| 98 |
|
| 99 |
self.dlg = uic.loadUi('ui/preferences.ui') |
| 100 |
self.dlg.prd_style_lw.addItems(list(QStyleFactory.keys())) |
| 101 |
self.dlg.prd_style_lw.itemSelectionChanged.connect(self.style_changed_cb) |
| 102 |
self.dlg.prd_font_app_btn.clicked.connect(self.font_app_btn_cb) |
| 103 |
self.dlg.prd_font_ev_btn.clicked.connect(self.font_ev_btn_cb) |
| 104 |
self.set_btn_text_and_font(self.dlg.prd_font_app_btn, QApplication.font()) |
| 105 |
self.set_btn_text_and_font(self.dlg.prd_font_ev_btn, ev_font) |
| 106 |
self.app_style = app_style |
| 107 |
self.ev_font = ev_font |
| 108 |
self.edit_ext_cmd = edit_ext_cmd |
| 109 |
self.exit_dontask = dontask |
| 110 |
self.inner_editing = innered |
| 111 |
self.show_ln_nr = ln_nr |
| 112 |
if self.exit_dontask: |
| 113 |
self.dlg.prd_opt_ask_chkb.setCheckState(Qt.CheckState.Unchecked) |
| 114 |
else: |
| 115 |
self.dlg.prd_opt_ask_chkb.setCheckState(Qt.CheckState.Checked) |
| 116 |
if self.inner_editing: |
| 117 |
self.dlg.prd_opt_inner_ed.setCheckState(Qt.CheckState.Checked) |
| 118 |
else: |
| 119 |
self.dlg.prd_opt_inner_ed.setCheckState(Qt.CheckState.Unchecked) |
| 120 |
if self.show_ln_nr: |
| 121 |
self.dlg.prd_opt_show_ln_nr.setCheckState(Qt.CheckState.Checked) |
| 122 |
else: |
| 123 |
self.dlg.prd_opt_show_ln_nr.setCheckState(Qt.CheckState.Unchecked) |
| 124 |
if (self.edit_ext_cmd): |
| 125 |
self.dlg.prd_edit_ext_inp.setText(self.edit_ext_cmd) |
| 126 |
|
| 127 |
def set_btn_text_and_font(self, btn, font): |
| 128 |
ftext = font.family() + ' ' + str(font.pointSize()) |
| 129 |
btn.setFont(font) |
| 130 |
btn.setText(ftext) |
| 131 |
|
| 132 |
def style_changed_cb(self): |
| 133 |
item = self.dlg.prd_style_lw.currentItem() |
| 134 |
self.app_style = item.text() |
| 135 |
QApplication.setStyle(self.app_style) |
| 136 |
|
| 137 |
def font_app_btn_cb(self): |
| 138 |
(font, ok) = QFontDialog().getFont(QApplication.font()) |
| 139 |
if (ok): |
| 140 |
self.set_btn_text_and_font(self.dlg.prd_font_app_btn, font) |
| 141 |
|
| 142 |
def font_ev_btn_cb(self): |
| 143 |
(font, ok) = QFontDialog().getFont(self.ev_font) |
| 144 |
if (ok): |
| 145 |
self.set_btn_text_and_font(self.dlg.prd_font_ev_btn, font) |
| 146 |
|
| 147 |
def run_dialog(self): |
| 148 |
ret = self.dlg.exec() |
| 149 |
if (ret == QDialog.DialogCode.Accepted): |
| 150 |
QApplication.setFont(self.dlg.prd_font_app_btn.font()) |
| 151 |
self.ev_font = self.dlg.prd_font_ev_btn.font() |
| 152 |
self.edit_ext_cmd = self.dlg.prd_edit_ext_inp.text() |
| 153 |
self.exit_dontask = self.dlg.prd_opt_ask_chkb.checkState() == Qt.CheckState.Unchecked |
| 154 |
self.inner_editing = self.dlg.prd_opt_inner_ed.checkState() == Qt.CheckState.Checked |
| 155 |
self.show_ln_nr = self.dlg.prd_opt_show_ln_nr.checkState() == Qt.CheckState.Checked |
| 156 |
return (self.app_style, self.dlg.prd_font_app_btn.font().toString(), self.edit_ext_cmd, |
| 157 |
self.ev_font.toString(), self.exit_dontask, self.inner_editing, self.show_ln_nr) |
| 158 |
|
| 159 |
def show_preferences_dialog(app_style, edit_ext_cmd, ev_font, dontask, innered, ln_nr): |
| 160 |
d = FilePreferencesDialog(app_style, edit_ext_cmd, ev_font, dontask, innered, ln_nr) |
| 161 |
return d.run_dialog() |
| 162 |
|
| 163 |
def show_about_dialog(): |
| 164 |
d = uic.loadUi('ui/about.ui') |
| 165 |
p = QApplication.windowIcon().pixmap(128) |
| 166 |
d.ad_logo_lbl.setPixmap(p) |
| 167 |
d.exec() |
| 168 |
|
| 169 |
def show_goto_line_dialog(line, max_line): |
| 170 |
d = uic.loadUi('ui/goto_line.ui') |
| 171 |
d.gl_spinbox.setMaximum(max_line) |
| 172 |
d.gl_hslider.setMaximum(max_line) |
| 173 |
d.gl_spinbox.setValue(line) |
| 174 |
d.gl_spinbox.lineEdit().selectAll() |
| 175 |
d.gl_spinbox.lineEdit().setFocus() |
| 176 |
if (d.exec() == QDialog.DialogCode.Accepted): |
| 177 |
return d.gl_spinbox.value() |
| 178 |
return None |
| 179 |
|
| 180 |
class FindDialog: |
| 181 |
dlg = None |
| 182 |
def __init__(self): |
| 183 |
self.dlg = uic.loadUi('ui/find.ui') |
| 184 |
self.dlg.ft_text_inp.setCompleter(None) |
| 185 |
self.dlg.ft_text_inp.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop) |
| 186 |
self.dlg.ft_text_inp.setFocus() |
| 187 |
|
| 188 |
def run_dlg(self, text): |
| 189 |
if (text == None): |
| 190 |
text = '' |
| 191 |
d = self.dlg |
| 192 |
d.ft_text_inp.lineEdit().setText(text) |
| 193 |
d.ft_text_inp.lineEdit().selectAll() |
| 194 |
d.ft_text_inp.lineEdit().setFocus() |
| 195 |
d.ft_from_cursor.setChecked(True) |
| 196 |
while True: |
| 197 |
ret = d.exec() |
| 198 |
if (ret != QDialog.DialogCode.Accepted): |
| 199 |
return None |
| 200 |
text = d.ft_text_inp.currentText() |
| 201 |
text = str(text).strip() |
| 202 |
if (text != ''): |
| 203 |
break |
| 204 |
opt = { |
| 205 |
'cs' : d.ft_cs.isChecked(), |
| 206 |
're' : d.ft_re.isChecked(), |
| 207 |
'wo' : d.ft_wo.isChecked(), |
| 208 |
'fw' : not d.ft_bw.isChecked(), |
| 209 |
'cursor' : d.ft_from_cursor.isChecked(), |
| 210 |
} |
| 211 |
return (text, opt) |
| 212 |
|
| 213 |
def show_find_dialog(text): |
| 214 |
if (FindDialog.dlg == None): |
| 215 |
FindDialog.dlg = FindDialog() |
| 216 |
return FindDialog.dlg.run_dlg(text) |
| 217 |
|
| 218 |
class FilterDialog: |
| 219 |
def __init__(self, cmd_items, cmd_sel): |
| 220 |
self.dlg = uic.loadUi('ui/filter.ui') |
| 221 |
self.dlg.fd_cmd_inp.addItems(cmd_items) |
| 222 |
self.dlg.fd_cmd_inp.setCurrentIndex(cmd_items.index(cmd_sel)) |
| 223 |
self.dlg.fd_filter_inp.setFocus() |
| 224 |
self.dlg.fd_regex_err_lbl.setVisible(False) |
| 225 |
|
| 226 |
def run_dialog(self): |
| 227 |
while True: |
| 228 |
ret = self.dlg.exec() |
| 229 |
if ret != QDialog.DialogCode.Accepted: |
| 230 |
return None |
| 231 |
is_regex = self.dlg.fd_regex_chkbox.isChecked() |
| 232 |
text = str(self.dlg.fd_filter_inp.text()) |
| 233 |
if is_regex == True: |
| 234 |
try: |
| 235 |
import re |
| 236 |
re.compile(text) |
| 237 |
except: |
| 238 |
e = str(sys.exc_info()[1]) |
| 239 |
lbl = self.dlg.fd_regex_err_lbl |
| 240 |
lbl.setVisible(True) |
| 241 |
lbl.setText("<font color='red'>regex: " + e + '</font>') |
| 242 |
continue |
| 243 |
|
| 244 |
res = [ |
| 245 |
text, |
| 246 |
is_regex, |
| 247 |
self.dlg.fd_negate_chkbox.isChecked(), |
| 248 |
self.dlg.fd_icase_chkbox.isChecked(), |
| 249 |
str(self.dlg.fd_cmd_inp.currentText()) |
| 250 |
] |
| 251 |
return res |
| 252 |
|
| 253 |
def show_filter_dialog(cmd_items, cmd_sel): |
| 254 |
dlg = FilterDialog(cmd_items,cmd_sel) |
| 255 |
return dlg.run_dialog() |