Exemplo n.º 1
0
    def getComicPage(self, comic_id, page_number, max_height=None):
        (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \
            .filter(Comic.id == int(comic_id)).first()

        image_data = None
        default_img_file = AppFolders.imagePath("default.jpg")

        if path is not None:
            if int(page_number) < page_count:
                ca = self.getComicArchive(path)
                image_data = ca.getPage(int(page_number))

        if image_data is None:
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            return image_data

        # resize image
        if max_height is not None:
            try:
                image_data = comicstreamerlib.utils.resizeImage(
                    int(max_height), image_data)
            except Exception as e:
                logging.exception(e)
                pass
        return image_data
Exemplo n.º 2
0
    def getComicPage(self, comic_id, page_number, max_height=None):
        (path, page_count) = self.getSession().query(Comic.path, Comic.page_count) \
                                 .filter(Comic.id == int(comic_id)).first()

        image_data = None
        default_img_file = AppFolders.imagePath("default.jpg")

        if path is not None:
            if int(page_number) < page_count:
                ca = self.getComicArchive(path)
                image_data = ca.getPage(int(page_number))

        if image_data is None:
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            return image_data

        # resize image
        if max_height is not None:
            try:
                image_data = comicstreamerlib.utils.resizeImage(
                    int(max_height), image_data)
            except:
                pass
        return image_data
Exemplo n.º 3
0
    def __init__(self, apiServer):
        self.apiServer = apiServer

        self.app = QtGui.QApplication(sys.argv)

        pixmap = QtGui.QPixmap(AppFolders.imagePath("trout.png"))
        icon = QtGui.QIcon(pixmap.scaled(16, 16))

        self.trayIcon = SystemTrayIcon(icon, self)

        self.trayIcon.show()
Exemplo n.º 4
0
 def __init__(self, apiServer):
     
     self.apiServer = apiServer
     
     self.icon = AppFolders.imagePath("trout.ico")
     self.hover_text = "ComicStreamer"
     self.on_quit = self.bye    
         
     menu_options = (
                     ('Show ComicStreamer UI', None, self.show),
                    )
     
     menu_options = menu_options + (('Quit', None, self.QUIT),)
     self._next_action_id = self.FIRST_ID
     self.menu_actions_by_id = set()
     self.menu_options = self._add_ids_to_menu_options(list(menu_options))
     self.menu_actions_by_id = dict(self.menu_actions_by_id)
     del self._next_action_id
     
     
     self.default_menu_index = 1
     self.window_class_name = "ComicStreamerTrayIcon"
     
     message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
                    win32con.WM_DESTROY: self.destroy,
                    win32con.WM_COMMAND: self.command,
                    win32con.WM_USER+20 : self.notify,}
     # Register the Window class.
     window_class = win32gui.WNDCLASS()
     hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
     window_class.lpszClassName = self.window_class_name
     window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
     window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
     window_class.hbrBackground = win32con.COLOR_WINDOW
     window_class.lpfnWndProc = message_map # could also specify a wndproc.
     classAtom = win32gui.RegisterClass(window_class)
     # Create the Window.
     style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
     self.hwnd = win32gui.CreateWindow(classAtom,
                                       self.window_class_name,
                                       style,
                                       0,
                                       0,
                                       win32con.CW_USEDEFAULT,
                                       win32con.CW_USEDEFAULT,
                                       0,
                                       0,
                                       hinst,
                                       None)
     win32gui.UpdateWindow(self.hwnd)
     self.notify_id = None
     self.refresh_icon()
Exemplo n.º 5
0
 def __init__(self, apiServer):
     super(MacGui, self).__init__("ComicStreamer", icon=AppFolders.imagePath("trout.png"))
     self.apiServer =  apiServer
     
     self.menu = [
         #rumps.MenuItem('About'), 
         'Show ComicStreamer UI',
         #None,  # None functions as a separator in your menu
         #{'Arbitrary':
         #    {"Depth": ["Menus", "It's pretty easy"],
         #     "And doesn't": ["Even look like Objective C", rumps.MenuItem("One bit", callback=self.onebitcallback)]}},
         None
     ]         
Exemplo n.º 6
0
    def get(self, comic_id):
        self.validateAPIKey()
        thumbnail = self.library.getComicThumbnail(comic_id)

        if thumbnail != None:
            self.setContentType('image/jpg')
            self.write(thumbnail)
        else:
            default_img_file = AppFolders.imagePath("default.jpg")
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            self.setContentType('image/jpg')
            self.write(image_data)
Exemplo n.º 7
0
    def get(self, comic_id):
        self.validateAPIKey()
        thumbnail = self.library.getComicThumbnail(comic_id)

        if thumbnail != None:
            self.setContentType('image/jpg')
            self.write(thumbnail)
        else:
            default_img_file = AppFolders.imagePath("default.jpg")
            with open(default_img_file, 'rb') as fd:
                image_data = fd.read()
            self.setContentType('image/jpg')
            self.write(image_data)
Exemplo n.º 8
0
    def __init__(self, apiServer):
        super(MacGui, self).__init__("ComicStreamer",
                                     icon=AppFolders.imagePath("trout.png"))
        self.apiServer = apiServer

        self.menu = [
            # rumps.MenuItem('About'),
            'Show ComicStreamer UI',
            # None,  # None functions as a separator in your menu
            # {'Arbitrary':
            #    {"Depth": ["Menus", "It's pretty easy"],
            #     "And doesn't": ["Even look like Objective C", rumps.MenuItem("One bit", callback=self.onebitcallback)]}},
            None
        ]
Exemplo n.º 9
0
 def getComicArchive(self, path):
     # should also look at modified time of file
     for ca in self.comicArchiveList:
         if ca.path == path:
             # remove from list and put at end
             self.comicArchiveList.remove(ca)
             self.comicArchiveList.append(ca)
             return ca
     else:
         ca = ComicArchive(
             path, default_image_path=AppFolders.imagePath("default.jpg"))
         self.comicArchiveList.append(ca)
         if len(self.comicArchiveList) > 10:
             self.comicArchiveList.pop(0)
         return ca
Exemplo n.º 10
0
 def getComicArchive(self, path):
     # should also look at modified time of file
     for ca in self.comicArchiveList:
         if ca.path == path:
             # remove from list and put at end
             self.comicArchiveList.remove(ca)
             self.comicArchiveList.append(ca)
             return ca
     else:
         ca = ComicArchive(
             path, default_image_path=AppFolders.imagePath("default.jpg"))
         self.comicArchiveList.append(ca)
         if len(self.comicArchiveList) > 10:
             self.comicArchiveList.pop(0)
         return ca
Exemplo n.º 11
0
def resizeImage(max, image_data):
    # disable WebP for now, due a memory leak in python library
    imtype = imghdr.what(StringIO(image_data))
    if imtype == "webp":
        with open(AppFolders.imagePath("default.jpg"), 'rb') as fd:
            image_data = fd.read()

    im = Image.open(StringIO(image_data)).convert('RGB')
    w, h = im.size
    if max < h:
        im.thumbnail((w, max), Image.ANTIALIAS)
        output = StringIO()
        im.save(output, format="JPEG")
        return output.getvalue()
    else:
        return image_data
Exemplo n.º 12
0
def resizeImage(max, image_data):
    # disable WebP for now, due a memory leak in python library
    imtype = imghdr.what(StringIO.StringIO(image_data))
    if imtype == "webp":
        with open(AppFolders.imagePath("default.jpg"), 'rb') as fd:
            image_data = fd.read()

    im = Image.open(StringIO.StringIO(image_data)).convert('RGB')
    w,h = im.size
    if max < h:
        im.thumbnail((w,max), Image.ANTIALIAS)
        output = StringIO.StringIO()
        im.save(output, format="JPEG")
        return output.getvalue()
    else:
        return image_data
Exemplo n.º 13
0
def resize(img, box, out, fit=False):
    '''Downsample the image.
    @param img: Image -  an Image-object
    @param box: tuple(x, y) - the bounding box of the result image
    @param fix: boolean - crop the image to fill the box
    @param out: file-like-object - save the image into the output stream
    '''

    if type(img) != Image and type(img) == str:
        try:
            img = Image.open(StringIO.StringIO(img))
        except:
            img = Image.open(
                StringIO(open(AppFolders.imagePath("default.jpg")).read()))

    #preresize image with factor 2, 4, 8 and fast algorithm
    factor = 1
    while img.size[0] / factor > 2 * box[0] and img.size[
            1] * 2 / factor > 2 * box[1]:
        factor *= 2
    if factor > 1:
        img.thumbnail((img.size[0] / factor, img.size[1] / factor),
                      Image.NEAREST)

    #calculate the cropping box and get the cropped part
    if fit:
        x1 = y1 = 0
        x2, y2 = img.size
        wRatio = 1.0 * x2 / box[0]
        hRatio = 1.0 * y2 / box[1]
        if hRatio > wRatio:
            y1 = int(y2 / 2 - box[1] * wRatio / 2)
            y2 = int(y2 / 2 + box[1] * wRatio / 2)
        else:
            x1 = int(x2 / 2 - box[0] * hRatio / 2)
            x2 = int(x2 / 2 + box[0] * hRatio / 2)
        img = img.crop((x1, y1, x2, y2))

    #Resize the image with best quality algorithm ANTI-ALIAS
    img.thumbnail(box, Image.ANTIALIAS)

    img = img.convert('RGB')

    #save it into a file-like object
    img.save(out, "JPEG", quality=65)
Exemplo n.º 14
0
    def __init__(self, apiServer):

        self.apiServer = apiServer

        self.icon = AppFolders.imagePath("trout.ico")
        self.hover_text = "ComicStreamer"
        self.on_quit = self.bye

        menu_options = (('Show ComicStreamer UI', None, self.show), )

        menu_options = menu_options + (('Quit', None, self.QUIT), )
        self._next_action_id = self.FIRST_ID
        self.menu_actions_by_id = set()
        self.menu_options = self._add_ids_to_menu_options(list(menu_options))
        self.menu_actions_by_id = dict(self.menu_actions_by_id)
        del self._next_action_id

        self.default_menu_index = 1
        self.window_class_name = "ComicStreamerTrayIcon"

        message_map = {
            win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
            win32con.WM_DESTROY: self.destroy,
            win32con.WM_COMMAND: self.command,
            win32con.WM_USER + 20: self.notify,
        }
        # Register the Window class.
        window_class = win32gui.WNDCLASS()
        hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
        window_class.lpszClassName = self.window_class_name
        window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
        window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
        window_class.hbrBackground = win32con.COLOR_WINDOW
        window_class.lpfnWndProc = message_map  # could also specify a wndproc.
        classAtom = win32gui.RegisterClass(window_class)
        # Create the Window.
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, self.window_class_name,
                                          style, 0, 0, win32con.CW_USEDEFAULT,
                                          win32con.CW_USEDEFAULT, 0, 0, hinst,
                                          None)
        win32gui.UpdateWindow(self.hwnd)
        self.notify_id = None
        self.refresh_icon()