Beispiel #1
0
    def _draw_label(self, *t):
        self._labelIG.clear()
        if not self.label and not self.label_icon:
            return

        theta = self.start_angle + (self.label_angle_ratio *
                                    (self.end_angle - self.start_angle))
        c = cos(radians(theta))
        s = sin(radians(theta))
        r = self.r
        r1 = r * self.label_radius_ratio
        if self.label_icon:
            label = CoreImage(self.label_icon)
            t = label.texture
            iconSize = max(t.size)
            scale = r * self.label_icon_scale / float(iconSize)
            tw, th = t.size
            tw *= scale
            th *= scale
        else:
            label = Label(text=self.label,
                          markup=True,
                          bold=True,
                          font_size=self.label_font_size)
            label.refresh()
            t = label.texture
            tw, th = t.size
        self._labelIG.add(
            Rectangle(pos=(self.centerx + r1 * s - tw / 2,
                           self.centery + r1 * c - th / 2),
                      size=(tw, th),
                      texture=t))
    def update_texture(self, *args):
        tex = CoreImage('img/noise_texture.png').texture
        tex.wrap = 'repeat'
        tex.uvsize = self.width / tex.width, self.height / tex.height

        self.canvas.before.clear()
        with self.canvas.before:
            if self.noise_color:
                Color(rgba=self.noise_color)
            Rectangle(pos=self.pos, size=self.size, texture=tex)
Beispiel #3
0
 def buildImage(self, sourceData):
     imageBytesObj = decode(sourceData['image'])
     imageBytesObj.seek(0)
     img = CoreImage(imageBytesObj, ext='jpg')
     new_img = Image()
     new_img.texture = img.texture
     return new_img
Beispiel #4
0
 def buildImage(self):
     imageBytesObj = decode(self.dataSource)
     imageBytesObj.seek(0)
     img = CoreImage(imageBytesObj, ext='jpg')
     new_img = Image()
     new_img.texture = img.texture
     self.add_widget(new_img)
Beispiel #5
0
 def load_image(self, image: BytesIO, ext: str):
     self.image_bytes = image
     self.image_ext = ext
     self.image_bytes.seek(0)
     coreimage = CoreImage(self.image_bytes, ext=self.image_ext)
     self.texture = coreimage.texture
     self.stop_loading()
 def _update_preview(self, img):
     data = BytesIO()
     img.save(data, format='png')
     data.seek(0)  # yes you actually need this
     im = CoreImage(BytesIO(data.read()), ext='png')
     self.image.texture = None
     self.image.texture = im.texture
 def reset(self, *args):
     data = BytesIO()
     self.orig_thumbnail.save(data, format='png')
     data.seek(0)  # yes you actually need this
     im = CoreImage(BytesIO(data.read()), ext='png')
     self.image.texture = None
     self.image.texture = im.texture
     self.reset_values()
 def _update_image(self, img, snippet):
     from io import BytesIO
     from kivy.uix.image import CoreImage
     data = BytesIO()
     snippet.save(data, format='png')
     data.seek(0)  # yes you actually need this
     im = CoreImage(BytesIO(data.read()), ext='png')
     img.texture = None
     img.texture = im.texture
 def add_user_in_list(self, ui_list, user, action_name, action):
     avatar_bytes = self.storage.get_user_avatar(user)
     avatar_texture = None
     if avatar_bytes:
         avatar_texture = CoreImage(io.BytesIO(avatar_bytes),
                                    ext='png').texture
     wid = UserBox(user, avatar_texture)
     wid.start_chat_link(self.storage.start_chat)
     wid.set_action(action_name, action)
     ui_list.add_widget(wid)
     self.update_list_height(ui_list)
Beispiel #10
0
def GetTextureFromBuffer(buffer, avecBord=False):
    # Version avec PIL
    # pyImg = GetPyImageFromStr(buffer)
    # if avecBord == True :
    #     pyImg = GetBorderPyImage(pyImg)
    # texture = TextureFromPyImage(pyImg)
    # return texture

    # Version sans PIL
    data = six.BytesIO(buffer)
    texture = CoreImage(data, ext="png").texture
    return texture
Beispiel #11
0
    def _draw_image(self, image=None):
        image = image if image else self.pil_image
        if not image:
            return

        texture = None
        with BytesIO() as output:
            image.save(output, format="PNG")
            output.seek(0)
            texture = CoreImage(output, ext="png").texture
        if not texture:
            return

        self.image.source = ""
        self.image.texture = texture
        self.image.reload()
Beispiel #12
0
    def __init__(self):
        super(MainGrid, self).__init__()

        encodedimg = decode(SourceData.objects[50].image)
        im = PILImage.fromarray(encodedimg)
        #im.show()
        imgIO = io.BytesIO()
        im.save(imgIO, format='JPEG')
        imgIO.seek(0)

        img = CoreImage(imgIO, ext='jpg')

        #new_img = KImage(source="sakimi-chan-rinoa-portrait-tutorial-rinoa.jpg")
        new_img = Image()
        new_img.texture = img.texture
        #new_img.reload()

        self.image_wid.texture = img.texture
        labels = [
            "Sitting Slouched", "Sitting Straight", "Slide left or right",
            "Standing Slouched", "Standing Straight"
        ]

        self.add_widget(Label(text="Test"))

        layout = GridLayout(cols=len(labels),
                            pos_hint={
                                'center_x': .5,
                                'center_y': .5
                            })
        for i in range(len(labels)):
            label = Label(font_size=15,
                          size_hint_x=None,
                          width=10,
                          text=labels[i])
            label.bind(size_hint_min_x=label.setter('width'))
            scroll = ScrollView(size_hint=(None, None),
                                size=(100, 100),
                                pos_hint={
                                    'center_x': .5,
                                    'center_y': .5
                                })
            scroll.add_widget(label)
            layout.add_widget(scroll)

        self.add_widget(layout)
Beispiel #13
0
        def _draw_userpic(image):
            """
            Accept PIL image presentation and convert it by size,
            draw in userpic area.
            """
            image = image.resize((70, 70), PILImage.BILINEAR)
            if not image:
                return

            texture = None
            with BytesIO() as output:
                image.save(output, format="PNG")
                output.seek(0)
                texture = CoreImage(output, ext="png").texture
            if not texture:
                return

            self.userpic.source = ""
            self.userpic.texture = texture
            self.userpic.reload()
            if profile is None:
                return
Beispiel #14
0
    def update(self, *args):
        """
        Updates text for current weather condition, current temp, high temp, low temp and the weather picture.
        :param args: Args given by Kivy
        :return: None
        """
        if (datetime.datetime.now() -
                self.last_update_time).total_seconds() >= 1800:
            self.update_weather_location_woeid()
            self.weather = self.update_weather()

            self.weather_text.text = self.weather["weather_state_name"]

            self.image.texture = CoreImage(self.update_weather_image(
                self.weather["weather_state_abbr"]),
                                           ext="png").texture
            self.last_update_time = datetime.datetime.now()

        if self.config_handler.get_setting(CONFIG_USE_FAHRENHEIT_KEY):
            self.current_text.text = (
                "Current: " +
                ("%.2f" % celcius_to_fahrenheit(self.weather["the_temp"])) +
                " °F")
            self.low_text.text = (
                "High: " +
                ("%.2f" % celcius_to_fahrenheit(self.weather["max_temp"])) +
                " °F")
            self.high_text.text = (
                "Low: " +
                ("%.2f" % celcius_to_fahrenheit(self.weather["min_temp"])) +
                " °F")
        else:
            self.current_text.text = ("Current: " +
                                      ("%.2f" % self.weather["the_temp"]) +
                                      " °C")
            self.low_text.text = "High: " + ("%.2f" %
                                             self.weather["max_temp"]) + " °C"
            self.high_text.text = "Low: " + ("%.2f" %
                                             self.weather["min_temp"]) + " °C"
    def update_image(self):
        d = self.image.norm_image_size[0] / self.image.texture.size[0]
        st_x, st_y = self.start_point_x, self.start_point_y
        en_x, en_y = self.end_point_x, self.end_point_y
        w, h = self.p_image.size

        x1, y1 = st_x / d, h - st_y / d
        x2, y2 = st_x / d + en_x / d, h - st_y / d + en_y / d

        if x1 > x2:
            x1, x2 = x2, x1
        if y1 > y2:
            y1, y2 = y2, y1

        self.p_image = self.p_image.crop((x1, y1, x2, y2))
        buf = io.BytesIO()
        self.p_image.save(buf, 'PNG')
        buf.seek(0)
        c_img = CoreImage(buf, ext='png')
        self.image.texture = c_img.texture
        print(self.image.size)
        self.wrapper.size_hint = (
            1, 0) if self.image_size[0] > self.image_size[1] else (0, 1)
Beispiel #16
0
    def __init__(self, config_handler, **kwargs):
        """
        Creates a WeatherWidgetLayout.
        :param kwargs: Kwargs for MDGridLayout
        """
        super(WeatherWidget, self).__init__(**kwargs)
        self.cols = 2
        self.rows = 3
        self.woeid = None
        self.update_weather_location_woeid()
        self.weather = self.update_weather()
        self.config_handler = config_handler

        self.weather_text = Label(
            text=self.weather["weather_state_name"],
            color=DARK_THEME_TEXT_COLOR
            if self.config_handler.get_setting(CONFIG_ENABLE_DARK_MODE_KEY)
            else LIGHT_THEME_TEXT_COLOR,
            font_name="RobotoMono-Regular",
            size_hint=(1, 1),
            font_size="15sp",
        )
        self.current_text = Label(
            color=DARK_THEME_TEXT_COLOR
            if self.config_handler.get_setting(CONFIG_ENABLE_DARK_MODE_KEY)
            else LIGHT_THEME_TEXT_COLOR,
            font_name="RobotoMono-Regular",
            size_hint=(1, 1),
            font_size="15sp",
        )
        self.low_text = Label(
            color=DARK_THEME_TEXT_COLOR
            if self.config_handler.get_setting(CONFIG_ENABLE_DARK_MODE_KEY)
            else LIGHT_THEME_TEXT_COLOR,
            font_name="RobotoMono-Regular",
            size_hint=(1, 1),
            font_size="10sp",
        )
        self.high_text = Label(
            color=DARK_THEME_TEXT_COLOR
            if self.config_handler.get_setting(CONFIG_ENABLE_DARK_MODE_KEY)
            else LIGHT_THEME_TEXT_COLOR,
            font_name="RobotoMono-Regular",
            size_hint=(1, 1),
            font_size="10sp",
        )
        if self.config_handler.get_setting(CONFIG_USE_FAHRENHEIT_KEY):
            self.current_text.text = (
                "Current: " +
                ("%.2f" % celcius_to_fahrenheit(self.weather["the_temp"])) +
                " °F")
            self.low_text.text = (
                "High: " +
                ("%.2f" % celcius_to_fahrenheit(self.weather["max_temp"])) +
                " °F")
            self.high_text.text = (
                "Low: " +
                ("%.2f" % celcius_to_fahrenheit(self.weather["min_temp"])) +
                " °F")
        else:
            self.current_text.text = ("Current: " +
                                      ("%.2f" % self.weather["the_temp"]) +
                                      " °C")
            self.low_text.text = "High: " + ("%.2f" %
                                             self.weather["max_temp"]) + " °C"
            self.high_text.text = "Low: " + ("%.2f" %
                                             self.weather["min_temp"]) + " °C"

        self.image = Image()
        self.image.texture = CoreImage(self.update_weather_image(
            self.weather["weather_state_abbr"]),
                                       ext="png").texture

        self.weather_text_anchor_layout = AnchorLayout(anchor_x="left",
                                                       anchor_y="top")
        self.current_text_anchor_layout = AnchorLayout(anchor_x="right",
                                                       anchor_y="top")
        self.low_text_anchor_layout = AnchorLayout(anchor_x="right",
                                                   anchor_y="bottom")
        self.high_text_anchor_layout = AnchorLayout(anchor_x="right",
                                                    anchor_y="center")
        self.image_anchor_layout = AnchorLayout(anchor_x="left",
                                                anchor_y="bottom")

        self.weather_text_anchor_layout.add_widget(self.weather_text)
        self.current_text_anchor_layout.add_widget(self.current_text)
        self.high_text_anchor_layout.add_widget(self.low_text)
        self.low_text_anchor_layout.add_widget(self.high_text)
        self.image_anchor_layout.add_widget(self.image)

        self.add_widget(self.weather_text_anchor_layout)
        self.add_widget(self.current_text_anchor_layout)
        self.add_widget(self.high_text_anchor_layout)
        self.add_widget(self.image_anchor_layout)
        self.add_widget(self.low_text_anchor_layout)
        self.last_update_time = datetime.datetime.now()
Beispiel #17
0
from kivy.uix.image import Image as CoreImage

textures = {
    (0, 0, 0): CoreImage(source='../resources/wall.png').texture,
    (255, 255, 255): CoreImage(source='../resources/air.png').texture
}
 def set_avatar(self, avatar_bytes):
     if not avatar_bytes:
         return
     img = io.BytesIO(avatar_bytes)
     texture = CoreImage(img, ext='png').texture
     self.avatar.texture = texture
Beispiel #19
0
 def __init__(self, picture_location, *args, **kwargs):
     super(Enlarge, self).__init__(picture_location=picture_location,*args,**kwargs)
     self.picture.save(f"{picture_location}_to_display.jpg")
     self.picture_to_display.texture = CoreImage(f"{picture_location}_to_display.jpg").texture
Beispiel #20
0
    def play_song(self, i):
        try:
            self.stop()
        except:
            pass
        link = self.down_path_list[i][0]
        if self.root.ids.screen_manager.current != 'PlayScreen':
            self.change_screen("PlayScreen")
        self.prepare(link)
        if link.endswith('.m4a'):
            self.audio = MP4(link)
            self.play_song_name = self.audio.get('\xa9nam', ['Unknown'])[0]
            #print(audio['\xa9alb'])
            self.play_art_name = self.audio.get('\xa9ART', ['Unknown'])[0]
            #print(audio['\xa9day'])
            #print(audio['\xa9gen'])
            try:
                self.img_data = self.audio["covr"][0]
            except:
                with open('cover.jpg', 'rb') as f:
                    self.img_data = f.read()
        elif link.endswith('.mp3'):
            self.audio = MP3(link, ID3=EasyID3)
            self.audio_tags = ID3(link)
            self.play_song_name = self.audio.get('title', ['Unknown'])[0]
            self.play_art_name = self.audio.get('artist', ['Unknown'])[0]
            try:
                self.img_data = self.audio_tags.get("APIC:").data
            except:
                with open('cover.jpg', 'rb') as f:
                    self.img_data = f.read()
        else:
            with open('cover.jpg', 'rb') as f:
                self.img_data = f.read()
                self.play_song_name = 'Unknown'
                self.play_art_name = 'Unknown'

        play_image_data = io.BytesIO(self.img_data)
        img = CoreImage(play_image_data, ext="jpg").texture
        song_image = Image(allow_stretch=True)
        song_image.texture = img
        self.root.ids.PlayScreen.clear_widgets()
        self.root.ids.PlayScreen.add_widget(
            MDIconButton(icon='chevron-left',
                         pos_hint={
                             "center_x": 0.05,
                             "center_y": 0.95
                         },
                         on_press=lambda x: self.back_screen()))
        card = MDCard(orientation='vertical',
                      pos_hint={
                          "center_x": 0.5,
                          "center_y": 0.65
                      },
                      size_hint=(None, None),
                      size=(self.win_size * 0.9, self.win_size * 0.9))
        card.add_widget(song_image)
        self.root.ids.PlayScreen.add_widget(card)
        self.root.ids.PlayScreen.add_widget(
            MDLabel(text=self.play_song_name,
                    halign='center',
                    theme_text_color='Custom',
                    text_color=self.theme_cls.primary_color,
                    font_style='H4',
                    bold=True,
                    pos_hint={"top": 0.84}))
        self.root.ids.PlayScreen.add_widget(
            MDLabel(text=self.play_art_name,
                    halign='center',
                    theme_text_color='Secondary',
                    font_style='H6',
                    pos_hint={"top": 0.8}))
        self.play_progress = MDProgressBar(pos_hint={
            'center_x': 0.5,
            'center_y': 0.25
        },
                                           size_hint_x=0.9,
                                           value=0,
                                           color=self.theme_cls.primary_color)
        self.root.ids.PlayScreen.add_widget(self.play_progress)
        self.root.ids.PlayScreen.add_widget(
            MDIconButton(icon="chevron-double-left",
                         pos_hint={
                             "center_x": .15,
                             "center_y": .15
                         },
                         user_font_size="40sp",
                         on_release=lambda x: self.rewind()))
        self.root.ids.PlayScreen.add_widget(
            MDIconButton(icon="chevron-double-right",
                         pos_hint={
                             "center_x": .85,
                             "center_y": .15
                         },
                         user_font_size="40sp",
                         on_release=lambda x: self.forward()))
        self.next_button = MDIconButton(
            icon="skip-next",
            pos_hint={
                "center_x": .65,
                "center_y": .15
            },
            user_font_size="55sp",
            on_release=lambda x: self.play_song(i + 1))
        self.root.ids.PlayScreen.add_widget(self.next_button)
        self.previous_button = (MDIconButton(
            icon="skip-previous",
            pos_hint={
                "center_x": .35,
                "center_y": .15
            },
            user_font_size="55sp",
            on_release=lambda x: self.play_song(i - 1)))
        self.root.ids.PlayScreen.add_widget(self.previous_button)
        self.play_btn = MDFloatingActionButton(
            icon='play',
            pos_hint={
                'center_x': 0.5,
                "center_y": 0.15
            },
            user_font_size="50sp",
            md_bg_color=(1, 1, 1, 1),
            elevation_normal=10,
            on_press=lambda x: self.play_song_offline(i))
        self.root.ids.PlayScreen.add_widget(self.play_btn)
        self.length_stamp = MDLabel(text=self.convert_sec(
            self.sound.getDuration()),
                                    halign='right',
                                    theme_text_color='Secondary',
                                    padding_x='20dp',
                                    pos_hint={"top": 0.725})
        self.root.ids.PlayScreen.add_widget(self.length_stamp)
        self.play_stamp = (MDLabel(text=self.convert_sec(
            self.sound.getCurrentPosition()),
                                   halign='left',
                                   theme_text_color='Secondary',
                                   padding_x='20dp',
                                   pos_hint={"top": 0.725}))
        self.root.ids.PlayScreen.add_widget(self.play_stamp)
        self.play_song_offline(i)
Beispiel #21
0
 def _read_images(
         imap_host, imap_port, imap_user, imap_pass, imap_folder,
         message_ID):  # reads the most recent email and parses the text
     try:  ## Time to search for the original email
         try:
             imap = IMAP4_SSL(imap_host, imap_port)
             ## login to server
             imap.login(imap_user, imap_pass)
             #imap.starttls()
         except:
             print("Failed to login")
             return False
         try:
             imap.select()
             # Search for the original email ID
             messages = imap.search(None, 'HEADER', 'MESSAGE-ID',
                                    message_ID)
             # Process the result to get the message id’s
             messages = messages[1][0].split()
             # Use the first id to view the headers for aroot.image message
             result, source_data = imap.fetch(messages[0], '(RFC822)')
             raw_source = source_data[0][
                 1]  # here's the body, which is raw headers and html and body of the whole email
             b = email.message_from_bytes(
                 raw_source)  # convert to message object
             print('checking images now')
             images = [{
                 'name': 'icon128.png',
                 'pic': CoreImage('icon128.png', ext="png").texture
             }]
             for part in b.walk():
                 image = {}
                 ctype = part.get_content_type()
                 if ctype in ['image/jpeg', 'image/png', 'image/gif']:
                     # un-comment to save file
                     #open(part.get_filename(), 'wb').write(part.get_payload(decode=True))
                     by = io.BytesIO(part.get_payload(decode=True))
                     by.seek(0)
                     image['name'] = part.get_filename()
                     image['pic'] = CoreImage(by, ext="png").texture
                     print(image)
                     # Below line is for saving to disk
                     images.append(image)
                     print('appended')
             return images
         except:
             print('not in inbox')
         if "gmail" in imap_host:
             imap.select('"[Gmail]/Sent Mail"')  # connect to sent mail.
             # Search for the original email ID
             messages = imap.search(None, 'HEADER', 'MESSAGE-ID',
                                    email_inreply)
             #print("Opening gmail 'Sent'")
         if 'gmail' not in imap_host:
             sentbox = False
             try:
                 imap.select('Sent')  # connect to sent mail.
                 # Search for the original email ID
                 messages = imap.search(None, 'HEADER', 'MESSAGE-ID',
                                        email_inreply)
                 sentbox = True
             except:
                 print('Sent folder not found')
             if sentbox == False:
                 try:
                     imap.select('INBOX.Sent')  # connect to sent mail.
                     # Search for the original email ID
                     messages = imap.search(None, 'HEADER', 'MESSAGE-ID',
                                            email_inreply)
                 except:
                     print(
                         'Inbox.Sent folder not found, no folders left to try'
                     )
         # Process the result to get the message id’s
         messages = messages[1][0].split()
         # Use the first id to view the headers for aroot.image message
         result, source_data = imap.fetch(messages[0], '(RFC822)')
         raw_source = source_data[0][
             1]  # here's the body, which is raw headers and html and body of the whole email
         b = email.message_from_bytes(
             raw_source)  # convert to message object
         print('checking images now')
         images = [{
             'name': 'icon128.png',
             'pic': CoreImage('icon128.png', ext="png").texture
         }]
         for part in b.walk():
             image = {}
             ctype = part.get_content_type()
             if ctype in ['image/jpeg', 'image/png', 'image/gif']:
                 # un-comment to save file
                 #open(part.get_filename(), 'wb').write(part.get_payload(decode=True))
                 by = io.BytesIO(part.get_payload(decode=True))
                 by.seek(0)
                 image['name'] = part.get_filename()
                 image['pic'] = CoreImage(by, ext="png").texture
                 print(image)
                 # Below line is for saving to disk
                 images.append(image)
                 print('appended')
         return images
     except:
         print('no images found')
         images = [{
             'name': 'icon128.png',
             'pic': CoreImage('icon128.png', ext="png").texture
         }]
         return images