def main(self): self.app = QApplication(sys.argv) self.form = MainInterface() self.form.show() # db stuff self.db = PhotagDB() #setup thumbnailer self.thumbnailerThread = QThread() self.thumbnailer = Thumbnailer() self.thumbnailer.moveToThread(self.thumbnailerThread) self.thumbnailer.thumbnailFetched.connect(self.addThumb) self.thumbnailerThread.started.connect( self.thumbnailer.processRequests) self.thumbnailerThread.start() # context menu self.form.image_tree_view.customContextMenuRequested.connect( self.imageTreeContextMenu) baseQuery = WholeTreeQuery(self.db) self.form.image_tree_view.setModel(ImageViewModel(baseQuery)) self.form.tag_tree_view.setModel(TagViewModel(self.db)) self.form.image_tree_view.selectionModel().currentChanged.connect( self.updateMediaLabel) self.form.action_new_tag.triggered.connect(self.newTag) self.form.action_walk_roots.triggered.connect(self.walkAllRoots) self.form.tag_tree_view.doubleClicked.connect(self.tagCurrentSelected) self.form.query_bar.returnPressed.connect(self.enterQuery) self.form.action_manage_roots.triggered.connect(self.manageRoots) self.app.exec_()
def __createSubDirs(self, album_dir): os.mkdir(os.path.join(album_dir, 'pics')) os.mkdir(os.path.join(album_dir, 'pics', 'highres')) os.mkdir(os.path.join(album_dir, 'thumbs')) album_thumb_size = Thumbnailer.getInstance().album_thumb_size os.mkdir(os.path.join(album_dir, 'thumbs', '%dx%d' % album_thumb_size)) slide_thumb_size = Thumbnailer.getInstance().slide_thumb_size if slide_thumb_size != album_thumb_size: os.mkdir(os.path.join(album_dir, 'thumbs', '%dx%d' % slide_thumb_size))
def __addIndexTable(self): thumb_size = Thumbnailer.getInstance().gallery_thumb_size thumb_dir = 'thumbs/%dx%d' % (thumb_size[0], thumb_size[1]) content_element = self.getContentTag() table = etree.SubElement(content_element, 'table') table.set('cellpadding', '0') table.set('cellspacing', '0') table.set('class', 'table1') colgroup = etree.SubElement(table, 'colgroup') colgroup.set('span', str(self.__column_count)) colgroup.set('id', 'gallery-index-column') tr = None column_count = 0 row_count = 0 cell_count = 0 for child in self.entity.children: if tr is None or column_count == self.__column_count: tr = etree.SubElement(table, 'tr') row_count += 1 column_count = 0 column_count += 1 cell_count += 1 if row_count % 2: pic_first = True else: pic_first = False td = etree.SubElement(tr, 'td') td.set('class', 'albumzelle') a = etree.SubElement(td, 'a') div = etree.SubElement(td, 'div') a.set('href', '%s/index.html' % child.name) img = etree.SubElement(a, 'img') img.set('class', 'thumb') img.set('src', '%s/%s' % (thumb_dir, child.pic_file_name)) img.set('alt', '%s' % child.name) if pic_first: div.set('align', 'left') img.set('style', 'float: left; margin-left: 2px;') else: div.set('align', 'right') img.set('style', 'float: right; margin-right: 2px;') title_a = etree.SubElement(div, 'a') title_a.set('class', 'album') title_a.set('href', '%s/index.html' % child.name) etree.SubElement(title_a, 'br') etree.SubElement(title_a, 'br') title_span = etree.SubElement(title_a, 'span') title_span.text = child.title etree.SubElement(title_a, 'br') subtitle_span = etree.SubElement(title_a, 'span') subtitle_span.set('style', 'font-size: 11px;') subtitle_span.text = child.subtitle # fill up with empty cells for i in range(self.__column_count * self.__row_count - cell_count): if tr is None or column_count == self.__column_count: tr = etree.SubElement(table, 'tr') row_count += 1 column_count = 0 td = etree.SubElement(tr, 'td') td.set('class', 'albumzelle') column_count += 1 cell_count += 1
def __updateThumbStripe(self): thumb_tag = self.getThumbStripeTag() if thumb_tag == None: raise Exception, 'No thumb stripe tag contained in template' slide_thumb_size = Thumbnailer.getInstance().slide_thumb_size table = etree.SubElement(thumb_tag, 'table') table.set('class', 'table1'); table.set('cellspacing', '0'); table.set('cellpadding', '0'); pictures = self.__getThumbStripePictures() for i in range(self.SLIDE_THUMB_COUNT): if i >= len(pictures): break #<tr><td class="thumbzelle_small"><a href="peyto_lake.html"><img src="navithumbs/Peyto_Lake.jpg" class="navithumb"></a></td></tr> tr = etree.SubElement(table, 'tr') td = etree.SubElement(tr, 'td') td.set('class', 'thumbzelle_small') div1 = etree.SubElement(td, 'div') div1.set('class', 'thumbzelle_small') div2 = etree.SubElement(div1, 'div') div2.set('class', 'thumbzelle_small_inner') a = etree.SubElement(div2, 'a') a.set('href', pictures[i].html_file_name) img = etree.SubElement(a, 'img') if not pictures[i].pic_file_name.endswith('.jpg'): raise Exception, 'currently only jpg files are supported' img.set('src', 'thumbs/%dx%d/%s' % (slide_thumb_size[0], slide_thumb_size[1], pictures[i].pic_file_name)) img.set('class', 'navithumb') if pictures[i] == self.entity: img.set('id', 'effect2')
def __generateAlbumThumbs(self, gallery_dir): thumbnailer = Thumbnailer.getInstance() (width, height) = thumbnailer.gallery_thumb_size for child in self.entity.children: thumb_path = os.path.join(gallery_dir, 'thumbs', '%dx%d' % (width, height), child.pic_file_name) if not os.path.lexists(thumb_path): thumb = thumbnailer.getThumbnail(child.pic_location, 'gallery') thumb.save(thumb_path, 'JPEG')
def __generateThumbs(self, album_dir): project = Core.getInstance().project thumbnailer = Thumbnailer.getInstance() slide_thumb_size = thumbnailer.slide_thumb_size thumb_path = os.path.join(album_dir, 'thumbs', '%dx%d' % (slide_thumb_size[0], slide_thumb_size[1]), self.entity.pic_file_name) if not os.path.lexists(thumb_path): thumb = thumbnailer.getThumbnail(self.entity.pic_location, 'slide') thumb.save(thumb_path, 'JPEG') album_thumb_size = thumbnailer.album_thumb_size thumb_path = os.path.join(album_dir, 'thumbs', '%dx%d' % (album_thumb_size[0], album_thumb_size[1]), self.entity.pic_file_name) if not os.path.lexists(thumb_path): thumb = thumbnailer.getThumbnail(self.entity.pic_location, 'album') thumb.save(os.path.join(album_dir, 'thumbs', '%dx%d' % (album_thumb_size[0], album_thumb_size[1]), self.entity.pic_file_name), 'JPEG')
def start(self): start_time = datetime.now() image_list = self.find_images() print "Found %(num)d images, checking thumbnails..." % \ {'num': len(image_list)} print "(- skipped, . generating)" thumbnailer = Thumbnailer() thumbnailer.set_config(self.config) thumbnailer.set_image_list(image_list) thumbnailer.create_thumbnails() print "Images OK." image_data = self.get_image_data(image_list) template_params = { 'image_data': image_data, 'title': self.config["title"], 'now': datetime.now().strftime("%Y-%m-%d %H:%M:%S %z") } generator = HtmlGenerator() print "Generating HTML..." generator.generate( os.path.join(self.config["template_path"], 'index.html'), template_params ) print "Saving HTML..." generator.save( os.path.join(self.config["build_path"], 'index.html') ) end_time = datetime.now() elapsed = (end_time - start_time).total_seconds() print "All done! Time taken: %(time).3f seconds" % {'time': elapsed}
def addIndexTable(self): thumb_size = Thumbnailer.getInstance().album_thumb_size thumb_dir = 'thumbs/%dx%d' % (thumb_size[0], thumb_size[1]) content_element = self.getContentTag() table = etree.SubElement(content_element, 'table') table.set('class', 'table1') table.set('cellspacing', '0') table.set('cellpadding', '0') colgroup = etree.SubElement(table, 'colgroup') colgroup.set('span', str(self.__column_count)) colgroup.set('id', 'album-index-column') tr = None column_count = 0 cell_count = 0 child_count = 0 if self.__current_idx_page > 1: # pointer to prevoius page tr = etree.SubElement(table, 'tr') tr.set('align', 'center') td = etree.SubElement(tr, 'td') td.set('class', 'bildzelle') column_count += 1 cell_count += 1 a = etree.SubElement(td, 'a') if self.__current_idx_page > 2: prev_idx_html = 'index%d.html' % (self.__current_idx_page - 1) else: prev_idx_html = 'index.html' a.set('href', prev_idx_html) img = etree.SubElement(a, 'img') img.set('class', 'index-pager') img.set('src', 'http://seycek.eu/style/back_thumbs.png') img.set('alt', 'back') for child in self.entity.children: child_count += 1 if child_count <= self.__handled_thumbs: # already handled on on of previous pages continue if tr is None or column_count == self.__column_count: tr = etree.SubElement(table, 'tr') tr.set('align', 'center') column_count = 0 td = etree.SubElement(tr, 'td') td.set('class', 'bildzelle') column_count += 1 cell_count += 1 a = etree.SubElement(td, 'a') if cell_count == self.__column_count * self.__row_count and \ len(self.entity.children) - self.__handled_thumbs > 1: # pointer to next page next_idx_html = 'index%d.html' % (self.__current_idx_page + 1) a.set('href', next_idx_html) img = etree.SubElement(a, 'img') img.set('class', 'index-pager') img.set('src', 'http://seycek.eu/style/next_thumbs.png') img.set('alt', 'next') break else: a.set('href', '%s/%s' % (self.__picture_page_dir, child.html_file_name)) img = etree.SubElement(a, 'img') img.set('class', 'thumb') img.set('src', '%s/%s' % (thumb_dir, child.pic_file_name)) self.__handled_thumbs += 1 # fill up with empty cells for i in range(self.__column_count * self.__row_count - cell_count): if tr is None or column_count == self.__column_count: tr = etree.SubElement(table, 'tr') tr.set('align', 'center') column_count = 0 td = etree.SubElement(tr, 'td') td.set('class', 'bildzelle') column_count += 1 cell_count += 1
class Photag(): def __init__(self): pass def newTag(self, event): text, okay = QInputDialog.getText( None, "New Tag", "Tag: ", QLineEdit.Normal, ) if okay: split = str.split(text, '.') last_tag = None for tag_name in split: new_tag = self.db.session.query(Tag).filter( Tag.name == tag_name).first() if not new_tag: new_tag = Tag(name=tag_name, parent=last_tag) last_tag = new_tag self.db.session.add(new_tag) self.db.session.commit() self.form.tag_tree_view.model().reset() def tagCurrentSelected(self, index): node = index.internalPointer() selected = self.form.image_tree_view.selectionModel().selectedIndexes() for selection in selected: if selection.internalPointer().media: selection.internalPointer().media.tags.append(node.tag) self.db.session.commit() def updateMediaLabel(self, selected, old_selected): index = selected node = index.internalPointer() #print(node.media.getFullPath()) if node.media: pm = QPixmap(node.media.getFullPath()) self.form.media_label.setSPixmap(pm) # update tags in taglist taglist = self.form.current_tags_list taglist.clear() tags = node.media.tags for tag in tags: taglist.addItem(tag.name) elif node.query: self.form.thumbnail_list.clear() self.thumbnailer.cancelAllRequests() medias = node.query.medias for media in medias: self.thumbnailer.requestThumbnail(media) self.thumbnailer.conn.commit() def addThumb(self, thumb, filename): self.form.thumbnail_list.addItem( QListWidgetItem(QIcon(QPixmap(thumb)), filename)) def walkAllRoots(self): self.db.walkAllRoots() def enterQuery(self): new_query = self.db.stringQuery(self.form.query_bar.text()) self.form.image_tree_view.model().setQuery(new_query) def manageRoots(self): self.manageRootsForm = ManageRootsInterface(self.db) self.manageRootsForm.show() def imageTreeContextMenu(self, point): index = self.form.image_tree_view.indexAt(point) if index.isValid(): query = index.internalPointer().query #this node is a directory if query and type(query) == DirQuery: self.db.walkDir(query.directory) def main(self): self.app = QApplication(sys.argv) self.form = MainInterface() self.form.show() # db stuff self.db = PhotagDB() #setup thumbnailer self.thumbnailerThread = QThread() self.thumbnailer = Thumbnailer() self.thumbnailer.moveToThread(self.thumbnailerThread) self.thumbnailer.thumbnailFetched.connect(self.addThumb) self.thumbnailerThread.started.connect( self.thumbnailer.processRequests) self.thumbnailerThread.start() # context menu self.form.image_tree_view.customContextMenuRequested.connect( self.imageTreeContextMenu) baseQuery = WholeTreeQuery(self.db) self.form.image_tree_view.setModel(ImageViewModel(baseQuery)) self.form.tag_tree_view.setModel(TagViewModel(self.db)) self.form.image_tree_view.selectionModel().currentChanged.connect( self.updateMediaLabel) self.form.action_new_tag.triggered.connect(self.newTag) self.form.action_walk_roots.triggered.connect(self.walkAllRoots) self.form.tag_tree_view.doubleClicked.connect(self.tagCurrentSelected) self.form.query_bar.returnPressed.connect(self.enterQuery) self.form.action_manage_roots.triggered.connect(self.manageRoots) self.app.exec_()
def __createSubDirs(self, gallery_dir): os.mkdir(os.path.join(gallery_dir, 'thumbs')) gallery_thumb_size = Thumbnailer.getInstance().gallery_thumb_size os.mkdir(os.path.join(gallery_dir, 'thumbs', '%dx%d' % gallery_thumb_size))