当前位置: 首页>>代码示例>>Python>>正文


Python Canvas.draw_on_canvas方法代码示例

本文整理汇总了Python中canvas.Canvas.draw_on_canvas方法的典型用法代码示例。如果您正苦于以下问题:Python Canvas.draw_on_canvas方法的具体用法?Python Canvas.draw_on_canvas怎么用?Python Canvas.draw_on_canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在canvas.Canvas的用法示例。


在下文中一共展示了Canvas.draw_on_canvas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw_on_canvas [as 别名]
class Clock:
    def __init__(self, matrixobject, positioninmatrix, clockdefinition, clock1224):
        logging.info('Creating new Clock instance')
        self.__Matrix = matrixobject
        self.__MatrixPosition = positioninmatrix
        self.__ClockDefinition = clockdefinition
        self.__Clock24h = clock1224

        self.__ClockCanvas = Canvas(clockdefinition['Size'])
        self.__ImageChanged = True

        self.__CurrentHour = -1
        self.__CurrentMinute = -1
        self.__CurrentSecond = -1
        self.__CurrentDay = -1
        self.__CurrentMonth = -1
        self.__CurrentDoW = -1

    # -------------------------------------------------------------------------
    # update_time_canvas
    # Update the time every second. The time can be 12h or 24h
    # -------------------------------------------------------------------------
    def update_time_canvas(self):
        while True:
            delay = 1.0
            if 'Time' in self.__ClockDefinition:
                if self.__ClockDefinition['Time'] != {}:
                    self.draw_time()
                    delay = 1.0 - float(time.time() % 1)
            time.sleep(delay)

    # -------------------------------------------------------------------------
    # update_date_canvas
    # Updates the date every day
    # -------------------------------------------------------------------------
    def update_date_canvas(self):
        while True:
            todaysdate = datetime.today()
            datedow = todaysdate.weekday()
            datemonth = todaysdate.month
            dateday = todaysdate.day

            if 'DoW' in self.__ClockDefinition:
                if self.__ClockDefinition['DoW'] != {}:
                    if self.__CurrentDoW != datedow:
                        self.__CurrentDoW = datedow
                        self.__ImageChanged = True
                        self.__ClockCanvas.draw_on_canvas(self.__ClockDefinition['DoW'], self.__CurrentDoW)

            if 'Day' in self.__ClockDefinition:
                if self.__ClockDefinition['Day'] != {}:
                    if self.__CurrentDay != dateday:
                        self.__CurrentDay = dateday
                        self.__ImageChanged = True
                        self.draw_day()

            if 'Month' in self.__ClockDefinition:
                if self.__ClockDefinition['Month'] != {}:
                    if self.__CurrentMonth != datemonth:
                        self.__CurrentMonth = datemonth
                        self.__ImageChanged = True
                        self.__ClockCanvas.draw_on_canvas(self.__ClockDefinition['Month'], self.__CurrentMonth)

            if self.__ClockDefinition['AutoDraw']:
                self.draw_on_matrix_canvas()

            # Calculate the number of seconds until midnight and wait for then
            secondstomidnight = (datetime.now().replace(hour=0, minute=0, second=0,
                                                        microsecond=0) + timedelta(days=1)) - datetime.now()
            time.sleep(secondstomidnight.total_seconds())

    # ----------------------------------------------------------------------------------
    # draw_clock_digit
    # Draw an individual clock digit at the pre-defined position (x, y) tuple
    # ----------------------------------------------------------------------------------
    def draw_clock_digit(self, position, digit):
        self.__ClockCanvas.draw_on_canvas(
            (position[0], position[1], self.__ClockDefinition['Time'][2], self.__ClockDefinition['Time'][3]),
            digit)

    # -------------------------------------------------------------------------
    # add_image_width
    # Increase x by a defined width
    # -------------------------------------------------------------------------
    def add_image_width(self, x, imagedef):
        return x + imagedef[2] - imagedef[0] + 1

    # ----------------------------------------------------------------------------------
    # draw_day
    # Update the day (date), consisting of a one or two digit number
    # ----------------------------------------------------------------------------------
    def draw_day(self):
        x = self.__ClockDefinition['Day'][0]
        y = self.__ClockDefinition['Day'][1]
        image = self.__ClockDefinition['Day'][2]
        imagedefinition = self.__ClockDefinition['Day'][3]

        # 10's digit
        if self.__CurrentDay >= 10.0:
            tensdigit = str(abs(int(self.__CurrentDay)))[0]
#.........这里部分代码省略.........
开发者ID:GeekyTim,项目名称:PiClock,代码行数:103,代码来源:clock.py

示例2: __init__

# 需要导入模块: from canvas import Canvas [as 别名]
# 或者: from canvas.Canvas import draw_on_canvas [as 别名]

#.........这里部分代码省略.........
                        self.draw_rainsnow_icon('SnowIcon')
                        self.__ImageChanged = True
                        self.__RainSnowIcon = 'snow'

                    if self.__CurrentWeatherSnow != current_weather['snow']:
                        self.__CurrentWeatherSnow = current_weather['snow']
                        self.draw_snowfall()
                    self.__ImageChanged = True

                # Booo! Rain
                else:
                    self.__CurrentWeatherSnow = -1.0
                    if self.__RainSnowIcon != 'rain':
                        self.draw_rainsnow_icon('RainIcon')
                        self.__ImageChanged = True
                        self.__RainSnowIcon = 'rain'

                    if self.__CurrentWeatherRain != current_weather['rain']:
                        self.__CurrentWeatherRain = current_weather['rain']
                        self.draw_rainfall()
                        self.__ImageChanged = True

            # Weather Time Indicator (indicator of the 3 hours the forcast covers)
            if self.__WeatherDefinition['WeatherTime'] != ():
                if self.__CurrentWeatherTime != current_weather['WeatherTime']:
                    self.__CurrentWeatherTime = current_weather['WeatherTime']
                    self.draw_weather_time()
                    self.__ImageChanged = True

    # -------------------------------------------------------------------------
    # draw_rainsnow_icon
    # -------------------------------------------------------------------------
    def draw_rainsnow_icon(self, whichicon):
        self.__WeatherCanvas.draw_on_canvas(self.__WeatherDefinition['RainSnowIcon'], whichicon)

    # -------------------------------------------------------------------------
    # draw_windspeed_icon
    # -------------------------------------------------------------------------
    def draw_windspeed_icon(self):
        self.__WeatherCanvas.draw_on_canvas(self.__WeatherDefinition['WindSpeedIcon'], 'Icon')

    # -------------------------------------------------------------------------
    # draw_windspeed
    # -------------------------------------------------------------------------
    def draw_windspeed(self):
        self.__WeatherCanvas.draw_on_canvas(self.__WeatherDefinition['WindSpeed'], 'blank')
        self.__WeatherCanvas.draw_on_canvas(self.__WeatherDefinition['WindSpeed'], self.__CurrentWeatherWind)

    # -------------------------------------------------------------------------
    # draw_rainfall
    # -------------------------------------------------------------------------
    def draw_rainfall(self):
        whattodraw = 'rain' + str(self.__CurrentWeatherRain)
        self.__WeatherCanvas.draw_on_canvas(self.__WeatherDefinition['RainSnow'], whattodraw)

    # -------------------------------------------------------------------------
    # draw_snowfall
    # -------------------------------------------------------------------------
    def draw_snowfall(self):
        whattodraw = 'snow' + str(self.__CurrentWeatherSnow)
        self.__WeatherCanvas.draw_on_canvas(self.__WeatherDefinition['RainSnow'], whattodraw)

    # -------------------------------------------------------------------------
    # draw_weather_icon
    # -------------------------------------------------------------------------
    def draw_weather_icon(self):
开发者ID:GeekyTim,项目名称:PiClock,代码行数:70,代码来源:weather.py


注:本文中的canvas.Canvas.draw_on_canvas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。