def _get_marker_styles() -> Sequence[str]: first_four = ( ".", "x", # triangle_up, "^", # pentagon "p") assert all(m in lineMarkers.keys() for m in first_four) return (*first_four, *(m for m in lineMarkers if m not in first_four))
def __init__(self, line, fig): gtk.Dialog.__init__(self, 'Line Properties') self.fig = fig self.line = line table = gtk.Table(3,2) table.show() table.set_row_spacings(4) table.set_col_spacings(4) table.set_homogeneous(True) self.vbox.pack_start(table, gtk.TRUE, gtk.TRUE) row = 0 label = gtk.Label('linewidth') label.show() entry = gtk.Entry() entry.show() entry.set_text(str(line.get_linewidth())) self.entryLineWidth = entry table.attach(label, 0, 1, row, row+1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(entry, 1, 2, row, row+1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 self.rgbLine = colorConverter.to_rgb(self.line.get_color()) def set_color(button): rgb = get_color(self.rgbLine) if rgb is not None: self.rgbLine = rgb label = gtk.Label('color') label.show() button = gtk.Button(stock=gtk.STOCK_SELECT_COLOR) button.show() button.connect('clicked', set_color) table.attach(label, 0, 1, row, row+1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(button, 1, 2, row, row+1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 ## line styles label = gtk.Label('linestyle') label.show() thisStyle = line.get_linestyle() styles = [thisStyle] for key in lineStyles.keys(): if key == thisStyle: continue styles.append(key) self.menuLineStyle, self.menuLineStyleItemd = make_option_menu(styles) table.attach(label, 0, 1, row, row+1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(self.menuLineStyle, 1, 2, row, row+1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 ## marker label = gtk.Label('marker') label.show() keys = lineMarkers.keys() keys.append('None') marker = line.get_marker() if marker is None: marker = 'None' styles = [marker] for key in keys: if key == marker: continue styles.append(key) self.menuMarker, self.menuMarkerItemd = make_option_menu(styles) table.attach(label, 0, 1, row, row+1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(self.menuMarker, 1, 2, row, row+1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button(gtk.STOCK_APPLY, gtk.RESPONSE_APPLY) self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
def __init__(self, line, fig): gtk.Dialog.__init__(self, 'Line Properties') self.fig = fig self.line = line table = gtk.Table(3, 2) table.show() table.set_row_spacings(4) table.set_col_spacings(4) table.set_homogeneous(True) self.vbox.pack_start(table, gtk.TRUE, gtk.TRUE) row = 0 label = gtk.Label('linewidth') label.show() entry = gtk.Entry() entry.show() entry.set_text(str(line.get_linewidth())) self.entryLineWidth = entry table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(entry, 1, 2, row, row + 1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 self.rgbLine = colorConverter.to_rgb(self.line.get_color()) def set_color(button): rgb = get_color(self.rgbLine) if rgb is not None: self.rgbLine = rgb label = gtk.Label('color') label.show() button = gtk.Button(stock=gtk.STOCK_SELECT_COLOR) button.show() button.connect('clicked', set_color) table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(button, 1, 2, row, row + 1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 ## line styles label = gtk.Label('linestyle') label.show() thisStyle = line.get_linestyle() styles = [thisStyle] for key in lineStyles.keys(): if key == thisStyle: continue styles.append(key) self.menuLineStyle, self.menuLineStyleItemd = make_option_menu(styles) table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(self.menuLineStyle, 1, 2, row, row + 1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 ## marker label = gtk.Label('marker') label.show() keys = lineMarkers.keys() keys.append('None') marker = line.get_marker() if marker is None: marker = 'None' styles = [marker] for key in keys: if key == marker: continue styles.append(key) self.menuMarker, self.menuMarkerItemd = make_option_menu(styles) table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FALSE, yoptions=gtk.FALSE) table.attach(self.menuMarker, 1, 2, row, row + 1, xoptions=gtk.TRUE, yoptions=gtk.FALSE) row += 1 self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button(gtk.STOCK_APPLY, gtk.RESPONSE_APPLY) self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
from ..commonlib.util import ensure_dir, remove_str_end # TODO: add more styles if necessary # Solid, dashed with dots, dotted LINE_STYLES: Sequence[str] = ["-", "-.", ":"] assert all(l in lineStyles.keys() for l in LINE_STYLES) _MARKER_STYLES: Sequence[str] = [ ".", "x", # triangle_up, "^", # pentagon "p", ] assert all(m in lineMarkers.keys() for m in _MARKER_STYLES) def zip_with_marker_styles(s: Sequence[T]) -> Iterable[Tuple[T, str]]: return zip_shorten_former(s, _MARKER_STYLES) Color = Tuple[float, float, float, float] def get_colors(n: int) -> Sequence[Color]: cmap = get_cmap("rainbow") return [cmap(i) for i in _linspace(0.1, 0.9, n)] def _linspace(lo: float, hi: float, n: int) -> Sequence[float]: