| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,17 +15,17 @@ | |||
| 15 | 15 | import os.path as osp | |
| 16 | 16 | import re | |
| 17 | 17 | ||
| 18 | + import matplotlib | ||
| 19 | + from matplotlib import cm, markers, colors as mcolors | ||
| 18 | 20 | import matplotlib.backends.qt_editor.formlayout as formlayout | |
| 19 | 21 | from matplotlib.backends.qt_compat import QtGui | |
| 20 | - from matplotlib import cm, markers | ||
| 21 | - from matplotlib.colors import colorConverter, rgb2hex | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | 24 | def get_icon(name): | |
| 25 | - import matplotlib | ||
| 26 | 25 | basedir = osp.join(matplotlib.rcParams['datapath'], 'images') | |
| 27 | 26 | return QtGui.QIcon(osp.join(basedir, name)) | |
| 28 | 27 | ||
| 28 | + | ||
| 29 | 29 | LINESTYLES = {'-': 'Solid', | |
| 30 | 30 | '--': 'Dashed', | |
| 31 | 31 | '-.': 'DashDot', | |
@@ -112,17 +112,17 @@ def prepare_data(d, init): | |||
| 112 | 112 | curvelabels = sorted(linedict, key=cmp_key) | |
| 113 | 113 | for label in curvelabels: | |
| 114 | 114 | line = linedict[label] | |
| 115 | - color = rgb2hex(colorConverter.to_rgb(line.get_color())) | ||
| 116 | - ec = rgb2hex(colorConverter.to_rgb(line.get_markeredgecolor())) | ||
| 117 | - fc = rgb2hex(colorConverter.to_rgb(line.get_markerfacecolor())) | ||
| 115 | + color = mcolors.to_hex(line.get_color(), line.get_alpha()) | ||
| 116 | + ec = mcolors.to_hex(line.get_markeredgecolor()) | ||
| 117 | + fc = mcolors.to_hex(line.get_markerfacecolor()) | ||
| 118 | 118 | curvedata = [ | |
| 119 | 119 | ('Label', label), | |
| 120 | 120 | sep, | |
| 121 | 121 | (None, '<b>Line</b>'), | |
| 122 | 122 | ('Line Style', prepare_data(LINESTYLES, line.get_linestyle())), | |
| 123 | 123 | ('Draw Style', prepare_data(DRAWSTYLES, line.get_drawstyle())), | |
| 124 | 124 | ('Width', line.get_linewidth()), | |
| 125 | - ('Color', color), | ||
| 125 | + ('Color (RGBA)', color), | ||
| 126 | 126 | sep, | |
| 127 | 127 | (None, '<b>Marker</b>'), | |
| 128 | 128 | ('Style', prepare_data(MARKERS, line.get_marker())), | |
@@ -200,7 +200,8 @@ def apply_callback(data): | |||
| 200 | 200 | line.set_linestyle(linestyle) | |
| 201 | 201 | line.set_drawstyle(drawstyle) | |
| 202 | 202 | line.set_linewidth(linewidth) | |
| 203 | - line.set_color(color) | ||
| 203 | + rgba = mcolors.to_rgba(color) | ||
| 204 | + line.set_color(rgba) | ||
| 204 | 205 | if marker is not 'none': | |
| 205 | 206 | line.set_marker(marker) | |
| 206 | 207 | line.set_markersize(markersize) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ | |||
| 51 | 51 | import datetime | |
| 52 | 52 | import warnings | |
| 53 | 53 | ||
| 54 | - from matplotlib.colors import colorConverter, is_color_like, rgb2hex | ||
| 54 | + from matplotlib import colors as mcolors | ||
| 55 | 55 | from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore | |
| 56 | 56 | from matplotlib.externals import six | |
| 57 | 57 | ||
@@ -77,7 +77,8 @@ def __init__(self, parent=None): | |||
| 77 | 77 | ||
| 78 | 78 | def choose_color(self): | |
| 79 | 79 | color = QtWidgets.QColorDialog.getColor( | |
| 80 | - self._color, self.parentWidget(), '') | ||
| 80 | + self._color, self.parentWidget(), "", | ||
| 81 | + QtWidgets.QColorDialog.ShowAlphaChannel) | ||
| 81 | 82 | if color.isValid(): | |
| 82 | 83 | self.set_color(color) | |
| 83 | 84 | ||
@@ -96,30 +97,25 @@ def set_color(self, color): | |||
| 96 | 97 | color = QtCore.Property(QtGui.QColor, get_color, set_color) | |
| 97 | 98 | ||
| 98 | 99 | ||
| 99 | - def col2hex(color): | ||
| 100 | - """Convert matplotlib color to hex before passing to Qt""" | ||
| 101 | - return rgb2hex(colorConverter.to_rgb(color)) | ||
| 102 | - | ||
| 103 | - | ||
| 104 | 100 | def to_qcolor(color): | |
| 105 | 101 | """Create a QColor from a matplotlib color""" | |
| 106 | 102 | qcolor = QtGui.QColor() | |
| 107 | - color = str(color) | ||
| 108 | 103 | try: | |
| 109 | - color = col2hex(color) | ||
| 104 | + rgba = mcolors.to_rgba(color) | ||
| 110 | 105 | except ValueError: | |
| 111 | 106 | warnings.warn('Ignoring invalid color %r' % color) | |
| 112 | 107 | return qcolor # return invalid QColor | |
| 113 | - qcolor.setNamedColor(color) # set using hex color | ||
| 114 | - return qcolor # return valid QColor | ||
| 108 | + qcolor.setRgbF(*rgba) | ||
| 109 | + return qcolor | ||
| 115 | 110 | ||
| 116 | 111 | ||
| 117 | 112 | class ColorLayout(QtWidgets.QHBoxLayout): | |
| 118 | 113 | """Color-specialized QLineEdit layout""" | |
| 119 | 114 | def __init__(self, color, parent=None): | |
| 120 | 115 | QtWidgets.QHBoxLayout.__init__(self) | |
| 121 | 116 | assert isinstance(color, QtGui.QColor) | |
| 122 | - self.lineedit = QtWidgets.QLineEdit(color.name(), parent) | ||
| 117 | + self.lineedit = QtWidgets.QLineEdit( | ||
| 118 | + mcolors.to_hex(color.getRgbF()), parent) | ||
| 123 | 119 | self.lineedit.editingFinished.connect(self.update_color) | |
| 124 | 120 | self.addWidget(self.lineedit) | |
| 125 | 121 | self.colorbtn = ColorButton(parent) | |
@@ -133,7 +129,7 @@ def update_color(self): | |||
| 133 | 129 | self.colorbtn.color = qcolor # defaults to black if not qcolor.isValid() | |
| 134 | 130 | ||
| 135 | 131 | def update_text(self, color): | |
| 136 | - self.lineedit.setText(color.name()) | ||
| 132 | + self.lineedit.setText(mcolors.to_hex(color.getRgbF())) | ||
| 137 | 133 | ||
| 138 | 134 | def text(self): | |
| 139 | 135 | return self.lineedit.text() | |
@@ -259,7 +255,8 @@ def setup(self): | |||
| 259 | 255 | continue | |
| 260 | 256 | elif tuple_to_qfont(value) is not None: | |
| 261 | 257 | field = FontLayout(value, self) | |
| 262 | - elif label.lower() not in BLACKLIST and is_color_like(value): | ||
| 258 | + elif (label.lower() not in BLACKLIST | ||
| 259 | + and mcolors.is_color_like(value)): | ||
| 263 | 260 | field = ColorLayout(to_qcolor(value), self) | |
| 264 | 261 | elif isinstance(value, six.string_types): | |
| 265 | 262 | field = QtWidgets.QLineEdit(value, self) | |
@@ -322,7 +319,8 @@ def get(self): | |||
| 322 | 319 | continue | |
| 323 | 320 | elif tuple_to_qfont(value) is not None: | |
| 324 | 321 | value = field.get_font() | |
| 325 | - elif isinstance(value, six.string_types) or is_color_like(value): | ||
| 322 | + elif (isinstance(value, six.string_types) | ||
| 323 | + or mcolors.is_color_like(value)): | ||
| 326 | 324 | value = six.text_type(field.text()) | |
| 327 | 325 | elif isinstance(value, (list, tuple)): | |
| 328 | 326 | index = int(field.currentIndex()) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments