| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
import os |
| 23 |
from PyQt5.QtCore import Qt, QThread, QEvent, pyqtSignal, QSize |
| 24 |
from PyQt5.QtGui import QCursor, QPixmap, QFont, QIcon, QPalette |
| 25 |
from PyQt5.QtWidgets import QVBoxLayout, QDialog, QPushButton, QColorDialog,\ |
| 26 |
QMenu, QLabel, QListWidget, QDialogButtonBox, QAbstractItemView |
| 27 |
|
| 28 |
from .. import param |
| 29 |
from .app import app |
| 30 |
|
| 31 |
|
| 32 |
imé." |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
s.") |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
class BusyCursor(object): |
| 58 |
def __enter__(self): |
| 59 |
app.setOverrideCursor(QCursor(Qt.WaitCursor)) |
| 60 |
|
| 61 |
def __exit__(self, type, value, traceback): |
| 62 |
app.restoreOverrideCursor() |
| 63 |
|
| 64 |
|
| 65 |
class MyMiniFrame(QDialog): |
| 66 |
def __init__(self, parent, titre=''): |
| 67 |
QDialog.__init__(self, parent) |
| 68 |
self.setModal(False) |
| 69 |
self.setWindowTitle(titre) |
| 70 |
|
| 71 |
def png_pth(nom): |
| 72 |
"""Adresse complète de l'image `nom`.png du repertoire 'images/'. |
| 73 |
|
| 74 |
Le nom doit être indiqué sans l'extension '.png'.""" |
| 75 |
return os.path.normpath(os.path.join(param.EMPLACEMENT, 'wxgeometrie/images', nom + ".png")) |
| 76 |
|
| 77 |
|
| 78 |
def png(nom): |
| 79 |
"""Charge l'image <nom>.png depuis le repertoire 'images/'. |
| 80 |
|
| 81 |
L'image doit être au format png, et son nom doit indiqué sans l'extension '.png'.""" |
| 82 |
pixmap = QPixmap() |
| 83 |
pixmap.load(png_pth(nom), 'PNG') |
| 84 |
return pixmap |
| 85 |
|
| 86 |
|
| 87 |
class GenericThread(QThread): |
| 88 |
def __init__(self, function, *args, **kwargs): |
| 89 |
QThread.__init__(self) |
| 90 |
self.function = function |
| 91 |
self.args = args |
| 92 |
self.kwargs = kwargs |
| 93 |
|
| 94 |
def __del__(self): |
| 95 |
self.wait() |
| 96 |
|
| 97 |
def run(self): |
| 98 |
self.function(*self.args,**self.kwargs) |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
.""" |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
def shift_down(event): |
| 118 |
return event.modifiers() & Qt.ShiftModifier |
| 119 |
|
| 120 |
def alt_down(event): |
| 121 |
return event.modifiers() & Qt.AltModifier |
| 122 |
|
| 123 |
def ctrl_down(event): |
| 124 |
return event.modifiers() & Qt.ControlModifier |
| 125 |
|
| 126 |
def meta_down(event): |
| 127 |
return event.modifiers() & Qt.MetaModifier |
| 128 |
|
| 129 |
def left_down(event): |
| 130 |
return event.buttons() & Qt.LeftButton |
| 131 |
|
| 132 |
def right_down(event): |
| 133 |
return event.buttons() & Qt.RightButton |
| 134 |
|
| 135 |
def lieu(event_or_widget): |
| 136 |
if isinstance(event_or_widget, QEvent): |
| 137 |
p = event_or_widget.pos() |
| 138 |
else: |
| 139 |
p = event_or_widget.mapFromGlobal(QCursor.pos()) |
| 140 |
return p.x(), p.y() |
| 141 |
|
| 142 |
|
| 143 |
class ColorSelecter(QPushButton): |
| 144 |
"A bouton used to select a color." |
| 145 |
|
| 146 |
colorSelected = pyqtSignal('QColor') |
| 147 |
|
| 148 |
def __init__(self, parent, color=None): |
| 149 |
QPushButton.__init__(self, parent) |
| 150 |
self.parent = parent |
| 151 |
self.setColor(color) |
| 152 |
self.clicked.connect(self.onClick) |
| 153 |
self.setMinimumSize(QSize(25, 25)) |
| 154 |
self.setMaximumSize(QSize(25, 25)) |
| 155 |
|
| 156 |
def onClick(self): |
| 157 |
self.setColor(QColorDialog.getColor(self.color, self, "Choisissez une couleur")) |
| 158 |
|
| 159 |
def setColor(self, color): |
| 160 |
if color is None: |
| 161 |
color = self.parent.palette().color(QPalette.Active, QPalette.Window) |
| 162 |
if color.isValid(): |
| 163 |
" |
| 164 |
self.color = color |
| 165 |
if color is not None: |
| 166 |
self.setStyleSheet("ColorSelecter { border-radius: 4px; \ |
| 167 |
background-color: %s ; border-color:#AAAAAA #AAAAAA #444444 #444444; \ |
| 168 |
border-style:solid; border-width:1px;} \ |
| 169 |
ColorSelecter:disabled {border-color:#AAAAAA #AAAAAA #444444 #444444;} \ |
| 170 |
ColorSelecter:hover { background-color: %s }" |
| 171 |
% (color.name(), color.lighter(125).name())) |
| 172 |
self.colorSelected.emit(color) |
| 173 |
|
| 174 |
|
| 175 |
class PopUpMenu(QMenu): |
| 176 |
"""Un menu avec un titre visible.""" |
| 177 |
|
| 178 |
def __init__(self, title, parent, icon=None): |
| 179 |
QMenu.__init__(self, title, parent) |
| 180 |
if icon is None: |
| 181 |
title = '\u2022 ' + title |
| 182 |
self._title = self.addAction(title) |
| 183 |
else: |
| 184 |
if isinstance(icon, str): |
| 185 |
|
| 186 |
icon = QIcon(png_pth(icon)) |
| 187 |
self._title = self.addAction(icon, title) |
| 188 |
self._title.setEnabled(False) |
| 189 |
self._title.setIconVisibleInMenu(True) |
| 190 |
font = QFont() |
| 191 |
font.setBold(True) |
| 192 |
font.setStyle(QFont.StyleItalic) |
| 193 |
self._title.setFont(font) |
| 194 |
self.addSeparator() |
| 195 |
|
| 196 |
def setTitle(self, title): |
| 197 |
self._title.setText(title) |
| 198 |
QMenu.setTitle(title) |
| 199 |
|
| 200 |
|
| 201 |
class MultipleChoiceDialog(QDialog): |
| 202 |
def __init__(self, parent, title, text, items): |
| 203 |
QDialog.__init__(self, parent) |
| 204 |
self.setWindowTitle(title) |
| 205 |
self.layout = QVBoxLayout() |
| 206 |
label = QLabel(text) |
| 207 |
self.layout.addWidget(label) |
| 208 |
self.listwidget = QListWidget(self) |
| 209 |
self.listwidget.setSelectionMode(QAbstractItemView.ExtendedSelection) |
| 210 |
for item in items: |
| 211 |
self.listwidget.addItem(item) |
| 212 |
self.layout.addWidget(self.listwidget) |
| 213 |
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel) |
| 214 |
buttonBox.accepted.connect(self.accept) |
| 215 |
buttonBox.rejected.connect(self.reject) |
| 216 |
self.layout.addWidget(buttonBox) |
| 217 |
self.setLayout(self.layout) |
| 218 |
|
| 219 |
def selectedItems(self): |
| 220 |
return self.listwidget.selectedItems() |