--- a/flickr.py Sat Mar 29 05:23:36 2008 -0400
+++ b/flickr.py Sat Mar 29 07:06:33 2008 -0400
@@ -43,11 +43,11 @@
self.xml = xml
def url(self):
- return 'http://farm%s.static.flickr.com/%s/%s_%s_t.jpg' % \
+ return 'http://farm%s.static.flickr.com/%s/%s_%s_s.jpg' % \
(self.xml['farm'], self.xml['server'], self.xml['primary'], self.xml['secret'])
def filename(self):
- return '%s_%s_t.jpg' % (self.xml['primary'], self.xml['secret'])
+ return '%s_%s_s.jpg' % (self.xml['primary'], self.xml['secret'])
def id(self):
return self.xml['id']
@@ -64,30 +64,61 @@
self.xml = xml
self.info = None
+ def id(self):
+ return self.xml['id']
+
def url(self, size = 't'):
return 'http://farm%s.static.flickr.com/%s/%s' % \
(self.xml['farm'], self.xml['server'], self.filename(size))
def filename(self, size = ''):
if size != '': size = '_' + size
- return '%s_%s%s.jpg' % (self.xml['id'], self.xml['secret'], size)
+ return '%s_%s%s.jpg' % (self.id(), self.xml['secret'], size)
def get(self, working_path, size, force = False):
return get_photo(working_path, self.url(size), self.filename(size), force)
def get_info(self):
- self.info = flickr.photos_getInfo(photo_id = self.xml['id'])
+ self.info = flickr.photos_getInfo(photo_id = self.id())
+ self.tags = []
+ try:
+ self.tags = [t['raw'] for t in self.info.photo[0].tags[0].tag]
+ except:
+ pass
- def tags(self):
+ def getTags(self):
if not self.info: self.get_info()
- if not self.info.photo[0].tags[0].xml: return []
- return [t['raw'] for t in self.info.photo[0].tags[0].tag]
+ return self.tags
+
+ def addTag(self, tag):
+ if tag == '': return
+ flickr.photos_addTags(photo_id = self.id(), tags = '"%s"' % tag)
+ self.tags = self.tags + [tag]
def rotate(self):
- res = flickr.photos_transform_rotate(photo_id = self.xml['id'], degrees = 90)
+ res = flickr.photos_transform_rotate(photo_id = self.id(), degrees = 90)
+ self.update(res)
+
+ def is_public(self):
+ if not self.info: self.get_info()
+ if self.info.photo[0].visibility[0]['ispublic'] == '1': return True
+ return False
+
+ def toggle_public(self):
+ if not self.info: self.get_info()
+ if self.is_public(): set_public = '0'
+ else: set_public = '1'
+ res = flickr.photos_setPerms(photo_id = self.id(), is_public = set_public,
+ is_friend = self.info.photo[0].visibility[0]['isfriend'],
+ is_family = self.info.photo[0].visibility[0]['isfamily'],
+ perm_comment = self.info.photo[0].permissions[0]['permcomment'],
+ perm_addmeta = self.info.photo[0].permissions[0]['permaddmeta'])
+ self.update(res)
+
+ def update(self, res):
self.xml['secret'] = res.photoid[0]['secret']
self.xml['originalsecret'] = res.photoid[0]['originalsecret']
-
+ self.get_info()
if __name__ == "__main__":
authenticate(raw_input)
--- a/pyqflickr.py Sat Mar 29 05:23:36 2008 -0400
+++ b/pyqflickr.py Sat Mar 29 07:06:33 2008 -0400
@@ -26,24 +26,29 @@
if self.photos == None: return
if key == QtCore.Qt.Key_Right:
self.photo = (self.photo + 1) % len(self.photos)
- self.show_photo()
+ self.showPhoto()
elif key == QtCore.Qt.Key_Left:
self.photo = (self.photo - 1) % len(self.photos)
- self.show_photo()
+ self.showPhoto()
elif key == QtCore.Qt.Key_Up:
self.photos = None
self.photo = None
- self.show_sets()
+ self.showSets()
elif key == QtCore.Qt.Key_R:
self.photos[self.photo].rotate()
- self.show_photo(force = True)
+ self.showPhoto(force = True)
+ elif key == QtCore.Qt.Key_P:
+ self.photos[self.photo].toggle_public()
+ self.showPhoto()
- def show_photo(self, force = False):
+ def showPhoto(self, force = False):
photo = self.photos[self.photo]
- tags = photo.tags()
- tags_txt = '<b>Tags</b>:<br>'
+ tags = photo.getTags()
+ info_txt = '<b>Tags</b>:<br>'
for t in tags:
- tags_txt = tags_txt + t + '<br>'
+ info_txt = info_txt + t + '<br>'
+ if photo.is_public(): info_txt = info_txt + "Public"
+ else: info_txt = info_txt + "Private"
txt = '''<center>
<table>
@@ -55,19 +60,19 @@
</tr>
</table>
</center>''' % \
- (photo.get(working_path, photo_size, force), tags_txt)
+ (photo.get(working_path, photo_size, force), info_txt)
self.ui.interfaceBrowser.setHtml(txt)
def anchorClicked(self, url):
if self.photos == None: # In set mode
self.photos = flickr.photos(url.toString()) # url must be the setid
self.photo = 0
- self.show_photo()
+ self.showPhoto()
def message(self, msg):
QtGui.QMessageBox.warning(None, "Warning", msg)
- def show_sets(self):
+ def showSets(self):
txt = '<table><tr>'
i = 1
for s in self.sets:
@@ -78,6 +83,15 @@
txt = txt + '</tr></table>'
self.ui.interfaceBrowser.setHtml(txt)
+ def addTag(self):
+ if self.photo == None: return # Need to be in the photo editing mode
+ tag = self.ui.tagEdit.text()
+ self.photos[self.photo].addTag(tag)
+ if tag not in self.tags: self.tags.append(tag)
+ self.completions.setStringList(self.tags)
+ self.ui.tagEdit.setText('')
+ self.showPhoto()
+
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
@@ -91,6 +105,7 @@
# Connect signals
self.connect(self.ui.tagEdit, QtCore.SIGNAL("shortcutPressed"), self.shortcutPressed)
+ self.connect(self.ui.tagEdit, QtCore.SIGNAL("returnPressed()"), self.addTag)
self.connect(self.ui.interfaceBrowser, QtCore.SIGNAL("anchorClicked(const QUrl&)"), self.anchorClicked)
# Init member
@@ -100,8 +115,16 @@
# Deal with Flickr
flickr.authenticate(self.message)
+ self.tags = flickr.tags().values()
self.sets = flickr.photosets()
- self.show_sets()
+ self.showSets()
+
+ # Tag completer
+ self.completions = QtGui.QStringListModel(QtCore.QStringList(self.tags))
+ self.completer = QtGui.QCompleter()
+ self.completer.setModel(self.completions)
+ self.completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
+ self.ui.tagEdit.setCompleter(self.completer)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)