Ejemplo n.º 1
0
def getcolormap(**kwargs):
    colors = kwargs.pop('colors', None)
    issingle = False
    if colors is None:
        colors = kwargs.pop('color', None)
        issingle = True
    if not colors is None:
        if issingle or isinstance(colors, str):
            c = getcolor(colors)
            cmap = ColorMap(c)
        else:
            cs = []
            for cc in colors:
                c = getcolor(cc)
                cs.append(c)
            cmap = ColorMap(cs)
    else:
        cmapstr = kwargs.pop('cmap', 'matlab_jet')
        if cmapstr is None:
            cmapstr = 'matlab_jet'
        alpha = kwargs.pop('alpha', None)
        if alpha is None:
            cmap = ColorUtil.getColorMap(cmapstr)
        else:
            alpha = (int)(alpha * 255)
            cmap = ColorUtil.getColorMap(cmapstr, alpha)
    reverse = kwargs.pop('cmapreverse', False)
    if reverse:
        cmap.reverse()
    return cmap
Ejemplo n.º 2
0
def getcolormap(**kwargs):
    colors = kwargs.pop('colors', None)
    issingle = False
    if colors is None:
        colors = kwargs.pop('color', None)
        issingle = True
    if not colors is None:
        if issingle or isinstance(colors, str):
            c = getcolor(colors)
            cmap = ColorMap(c)
        else:
            cs = []
            for cc in colors:
                c = getcolor(cc)
                cs.append(c)
            cmap = ColorMap(cs)
    else:
        cmapstr = kwargs.pop('cmap', 'matlab_jet')
        if cmapstr is None:
            cmapstr = 'matlab_jet'
        fn = cmapstr + '.rgb'
        fn = os.path.join(migl.get_cmap_folder(), fn)
        if not os.path.exists(fn):
            raise IOError('cmap file not exists: %s' % fn)
        alpha = kwargs.pop('alpha', None)
        if alpha is None:
            cmap = ColorUtil.loadColorMap(fn)
        else:
            alpha = (int)(alpha * 255)
            cmap = ColorUtil.loadColorMap(fn, alpha)
    reverse = kwargs.pop('cmapreverse', False)
    if reverse:
        cmap.reverse()
    return cmap
Ejemplo n.º 3
0
def down_pic(url, save_path):
    logging.debug(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                  "正在下载 %s" % url)
    print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "正在下载 %s" % url)
    pic_name = url[str(url).rfind("/") + 1:]
    # logging.error(pic_name)
    pic_full_name = save_path + '/' + pic_name
    try:
        urllib.request.install_opener(opener)
        urllib.request.urlretrieve(url, pic_full_name)
        if download_only_color_images:
            logging.debug(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                          " 判断是否是彩色图片...")
            print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                  " 判断是否是彩色图片...")
            colors = ColorUtil.get_color_structure(pic_full_name)
            if len(colors) < min_colors_count:
                logging.debug(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                              " 非彩色图片,删除该图片...")
                print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
                      " 非彩色图片,删除该图片...")
                os.remove(pic_full_name)
        return "成功"
    except Exception as e:
        logging.error(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " " +
                      str(e))
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " " + str(e))
        logging.error(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " 下载漫画出错")
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " 下载漫画出错")
        return e
Ejemplo n.º 4
0
	def __init__(self):
		super(DotMapLayer, self).__init__(DOTMAP_LAYER)
		global g_DotMap
		g_DotMap = self
		# constants
		self.CITY_SAVE_ID = "CityDataDict"
		self.HIGHLIGHT_CROSS_LAYER = 8
		self.FIRST_CROSS_LAYER = 9
		self.NUM_CROSS_LAYERS = len(ColorUtil.getColorKeys())
		self.DOT_LAYER = PlotLandscapeLayers.PLOT_LANDSCAPE_LAYER_NUMPAD_HELP
		self.NO_DOT_STYLE = PlotStyles.PLOT_STYLE_NONE
		self.MAX_DOT_STYLE = PlotStyles.PLOT_STYLE_WAVES
		self.BFC_OFFSETS = []
		for x in range(-2, 3):
			for y in range(-2, 3):
				if abs(x) != 2 or abs(y) != 2:
					self.BFC_OFFSETS.append((x, y))
		# default options
		self.CROSS_ALPHA = 50.0
		self.DOT_ALPHA = 50.0
		self.HIGHLIGHT_CROSS_ALPHA = 100.0
		self.HIGHLIGHT_DOT_ALPHA = 100.0
		self.DRAW_DOTS = True
		self.DOT_STYLE = PlotStyles.PLOT_STYLE_DOT_TARGET
		self.readOptions()
		# state
		self.highlightedCity = None
Ejemplo n.º 5
0
	def setIndex(self, index, *args):
		if self.isStringList():
			self.setValue(index, *args)
		elif self.isColorList():
			self.setValue(ColorUtil.indexToKey(index), *args)
		else:
			self.setValue(self.values[index], *args)
Ejemplo n.º 6
0
	def setIndex(self, index, *args):
		if self.isStringList():
			self.setValue(index, *args)
		elif self.isColorList():
			self.setValue(ColorUtil.indexToKey(index), *args)
		else:
			self.setValue(self.values[index], *args)
Ejemplo n.º 7
0
	def drawDot(self, city, alpha):
		"""
		Draws the dot for a single city.
		"""
		if self.DRAW_DOTS:
			x, y = city.point
			color = ColorUtil.indexToKey(city.color)
			CyEngine().addColoredPlotAlt(x, y, self.DOT_STYLE, self.DOT_LAYER, color, alpha)
Ejemplo n.º 8
0
	def getIndex(self, *args):
		value = self.getRealValue(*args)
		if self.isStringList():
			return value
		elif self.isColorList():
			return ColorUtil.keyToIndex(value)
		else:
			return self.findClosestIndex(value)
Ejemplo n.º 9
0
def colorText(text, color):
	"""Applies the color (string or int) to text and returns the resulting string."""
	if text is not None and color is not None:
		if isinstance(color, types.StringTypes):
			color = ColorUtil.keyToType(color)
		if color >= 0:
			return localText.changeTextColor(text, color)
	return text
Ejemplo n.º 10
0
	def getIndex(self, *args):
		value = self.getRealValue(*args)
		if self.isStringList():
			return value
		elif self.isColorList():
			return ColorUtil.keyToIndex(value)
		else:
			return self.findClosestIndex(value)
Ejemplo n.º 11
0
	def getDisplayValues(self):
		if self.isStringList():
			if (not self.translated):
				self.translate()
		elif self.isColorList():
			return ColorUtil.getColorDisplayNames()
		else:
			self.buildDisplayValues()
		return self.displayValues
Ejemplo n.º 12
0
	def drawCross(self, city, alpha):
		"""
		Draws the cross for a single city.
		"""
		x, y = city.point
		color = ColorUtil.indexToKey(city.color)
		layer = city.layer
		for dx, dy in self.BFC_OFFSETS:
			CyEngine().fillAreaBorderPlotAlt(x + dx, y + dy, layer, color, alpha)
Ejemplo n.º 13
0
	def getColor(self, *args):
		"""Returns the value as a color type (int) if this is a color or string option,
		the actual value if an int, or -1 otherwise.
		"""
		if self.isColor() or self.isString():
			return ColorUtil.keyToType(self.getValue(*args))
		elif self.isInt():
			return self.getValue(*args)
		return -1
Ejemplo n.º 14
0
	def getColor(self, *args):
		"""Returns the value as a color type (int) if this is a color or string option,
		the actual value if an int, or -1 otherwise.
		"""
		if self.isColor() or self.isString():
			return ColorUtil.keyToType(self.getValue(*args))
		elif self.isInt():
			return self.getValue(*args)
		return -1
Ejemplo n.º 15
0
	def getDisplayValues(self):
		if self.isStringList():
			if not self.translated:
				self.translate()
		elif self.isColorList():
			return ColorUtil.getColorDisplayNames()
		else:
			self.buildDisplayValues()
		return self.displayValues
def colorText(text, color):
    """
	Applies the color (string or int) to text and returns the resulting string.
	"""
    if text is not None and color is not None:
        if isinstance(color, types.StringTypes):
            color = ColorUtil.keyToType(color)
        if color >= 0:
            return localText.changeTextColor(text, color)
    return text
Ejemplo n.º 17
0
    def setRGB(self, r, g, b):
        # To prevent value oscillation               
        if (round(r), round(g), round(b)) == (round(self.__rCache), round(self.__gCache), round(self.__bCache)):
            return
              
        self.__r = r
        self.__g = g
        self.__b = b

        (self.__h, self.__s, self.__v) = ColorUtil.rgb2hsv(self.__r, self.__g, self.__b)
        (self.__hCache, self.__sCache, self.__vCache) = (self.__h, self.__s, self.__v)
        
        self.notifyObservers()
Ejemplo n.º 18
0
    def setHSV(self, h, s, v):
        # To prevent value oscillation 
        if (round(h), round(s), round(v)) == (round(self.__hCache), round(self.__sCache), round(self.__vCache)):
            return
           
        self.__h = h
        self.__s = s
        self.__v = v

        (self.__r, self.__g, self.__b) = ColorUtil.hsv2rgb(self.__h, self.__s, self.__v)
        (self.__rCache, self.__gCache, self.__bCache) = (self.__r, self.__g, self.__b)
        
        self.notifyObservers()
Ejemplo n.º 19
0
 def ensureValidDropdownIndex(self, optionName, index):
     option = self.getOption(optionName)
     if option is None:
         return index, False
     if index < 0 or index >= len(option.getDisplayValues()):
         index = option.getDefault()
         if "COLOR" in str(index):
             index = ColorUtil.keyToIndex(index)
         if index < 0 or index >= len(option.getDisplayValues()):
             return index, False
         else:  # Store the repaired index in the option object
             option.setIndex(index)
     return index, True
Ejemplo n.º 20
0
def makecolors(n, cmap='matlab_jet', reverse=False, alpha=None):
    '''
    Make colors.
    
    :param n: (*int*) Colors number.
    :param cmap: (*string*) Color map name. Default is ``matlab_jet``.
    :param reverse: (*boolean*) Reverse the colors or not. Default is ``False``.
    :param alpha: (*float*) Alpha value (0 - 1) of the colors. Defaul is ``None``.

    :returns: (*list*) Created colors.
    '''
    if isinstance(n, list):
        cols = getcolors(n, alpha)
    else:
        ocmap = ColorUtil.getColorMap(cmap)
        if reverse:
            ocmap.reverse()
        if alpha is None:
            cols = ocmap.getColorList(n)    
        else:
            alpha = (int)(alpha * 255)
            cols = ocmap.getColorList(n, alpha)
    return list(cols)
Ejemplo n.º 21
0
	def __init__(self, screenID):
		self.screenID = screenID
		self.SCREEN_NAME = "DotMapOverlayScreen"
		#---------------------------------------------------------------------------
		# Panel IDS
		#---------------------------------------------------------------------------
		self.PREFIX = "DotMapOverlay"
		self.COLOR_PANEL_ID = self.PREFIX + "ColorPanel"
		#---------------------------------------------------------------------------
		# Main Panel Coordinates
		#---------------------------------------------------------------------------
		self.PANEL_MARGIN = 15
		self.TITLE_HEIGHT = 16
		self.TEXT_HEIGHT = 16
		self.TEXT_SPACING = 5
		self.PANEL_SPACING = 5
		self.Z_TEXT = -0.3
		self.Z_CONTROL = -0.3
		#---------------------------------------------------------------------------
		# Color Values
		#---------------------------------------------------------------------------
		self.COLOR_KEYS = ColorUtil.getColorKeys()
		self.COLOR_TEXT = ColorUtil.getColorDisplayNames()
		#---------------------------------------------------------------------------
		# Color Panel Widgets
		#---------------------------------------------------------------------------
		self.COLOR_WIDGET_PREFIX = self.COLOR_PANEL_ID + "Widget"
		self.COLOR_WIDGET_IDS = []
		#---------------------------------------------------------------------------
		# Color Panel Coordinates
		#---------------------------------------------------------------------------
		self.COLOR_PANEL_HEADER_H = 15
		self.COLOR_PANEL_X = 10
		self.COLOR_PANEL_Y = 75 + self.PANEL_MARGIN * 2 + self.TITLE_HEIGHT * 2 + 2 * self.TEXT_HEIGHT + 3 * self.TEXT_SPACING + self.PANEL_SPACING
		self.COLOR_PANEL_TEXT_X = self.COLOR_PANEL_X + self.PANEL_MARGIN
		self.COLOR_PANEL_TEXT_Y = self.COLOR_PANEL_Y + self.PANEL_MARGIN
		self.COLOR_PANEL_W = 0
		self.COLOR_PANEL_H = len(self.COLOR_KEYS) * (self.TEXT_HEIGHT + self.TEXT_SPACING) + self.PANEL_MARGIN * 2
		#-------------------------------------------------------------------------------
		# Constants
		#-------------------------------------------------------------------------------
		self.HIGHLIGHT_CROSS_LAYER = 8
		self.FIRST_CROSS_LAYER = 9
		self.NUM_CROSS_LAYERS = len(self.COLOR_KEYS)
		self.PLOT_LAYER = PlotLandscapeLayers.PLOT_LANDSCAPE_LAYER_NUMPAD_HELP
		self.DOT_STYLE = PlotStyles.PLOT_STYLE_DOT_TARGET
		self.NO_DOT_STYLE = PlotStyles.PLOT_STYLE_NONE
		self.BFC_OFFSETS = []
		for x in range(-2, 3):
			for y in range(-2, 3):
				if abs(x) != 2 or abs(y) != 2:
					self.BFC_OFFSETS.append((x, y))
		#---------------------------------------------------------------------------
		# State variables
		#---------------------------------------------------------------------------
		self.currentColor = 0
		self.bLeftMouseDown = False
		self.bRightMouseDown = False
		self.bInitPos = False
		self.currentLayer = self.FIRST_CROSS_LAYER
		self.currentPoint = None
		#-------------------------------------------------------------------------------
		# Widget Input Mapping
		#-------------------------------------------------------------------------------
		self.inputMap = {
			self.COLOR_WIDGET_PREFIX : self.onColorButton,
		}