def take_a_selfie(self, filename='.temp.jpg'): self.name = raw_input() self.selfie = raw_input() if 'selfie' in self.selfie: img = photos.capture_image() if img: img.save(filename) console.show_image(filename) speech.say(self.name + ', you look stunning!') print self.name + ', you look stunning!' speech.say( 'Would you like to save your master piece in a custom album?' ) print 'Would you like to save your master piece in a custom album?' self.to_save_or_not_to_save = raw_input() if 'ye' in self.to_save_or_not_to_save: photos.create_album(self.name + 's Album') speech.say( 'Okay. I have created your own custom album to save your legendary pic.' ) print 'Okay. I have created your own custom album to save your legendary pic.' speech.say( 'Hold the image to save your elegant pic in your custom album' ) print 'Hold the image to save your elegant pic in your custom album' self.idle() else: speech.say( 'Affirmative... Your photo will be deleted after this session.' ) print 'Affirmative... Your photo will be deleted after this session.' self.idle() console.clear()
def get_album(): albums = photos.get_albums() albums = [a for a in albums if a.title == ALBUM_NAME] if not albums: return photos.create_album(ALBUM_NAME) else: return albums[0]
def get_album(title): for coll in photos.get_albums(): if coll.title == title: break else: coll = photos.create_album(title) return coll
def album_create(self, title): title = title.strip() if title in self.album_titles: self._alert_error('Album already exists.') return try: album = photos.create_album(title) if isinstance(album, photos.AssetCollection): self.albums.append(album) self.album_titles.append(title) return album else: self.albums_load() if title in self.album_titles: id = self.album_titles.index(title) return self.albums[id] else: self._alert_error('An unknown error has occurred resulting in the album not being created.\n' \ 'Please restart Pythonista and try again.') return False except Exception as e: """ There are no documented expected Exceptions with this call; so our only choice is a generic handler. Note: This is working primarily around iOS's internal frameowrks. Determing the exception time, or rather any exception beyond a base exception (captured above). """ self._alert_error('Unable to create album {}. \nError: {}'.format( title, e))
def addImagefileToAlbum(imagefilePath, albumName): try: album = [a for a in photos.get_albums() if a.title == albumName][0] except IndexError: album = photos.create_album(albumName) asset = photos.create_image_asset(imagefilePath) album.add_assets([asset])
def add_to_album(image_path, album_name): try: album = [a for a in photos.get_albums() if a.title == album_name][0] except IndexError: album = photos.create_album(album_name) asset = photos.create_image_asset(image_path) album.add_assets([asset]) os.remove(image_path)
def check_for_album_or_make(album_name): all_albums = photos.get_albums() found = False for some_album in all_albums: if found: continue elif some_album.title == album_name: found = True found_album = some_album if not found: found_album = photos.create_album(album_name) return found_album
def add_to_album(image_path, album_name): # KUDOS to Ole Zorn here! # Source: https://forum.omz-software.com/topic/3889/adding-an-image-to-my-own-album-in-photos-how/2 # Find the album or create it: try: album = [a for a in photos.get_albums() if a.title == album_name][0] except IndexError: album = photos.create_album(album_name) # Add the file as an asset to the library: asset = photos.create_image_asset(image_path) # Workaround a possible timestamp bug: asset.creation_date = datetime.datetime.now() # Add the asset to the album: album.add_assets([asset])
def export_images(): all_images = glob(os.path.join( 'images', '*.png', )) album = photos.create_album('AWS Icon Export') album_assets = [] for image in all_images: print('Processing Image: {}'.format(os.path.basename(image))) img_asset = photos.create_image_asset(image) album_assets.append(img_asset) print('Exporitng...') album.add_assets(album_assets)
def touch_began(self, touch): current = location.get_location() latLong = (round(current['latitude'], 4), round(current['longitude'], 4) ) #solved the close points problem using rounding picTaken = latLong in self.photoLocations x, y = touch.location if self.imageModeOpen == True: self.imageModeOpen = False self.img.hidden = True if self.loopPrompt == True: if x > 50 and x < self.size.x / 2 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x / 2 and x < self.size.x - 50 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 2 elif self.MoreState == True: #SOS State if x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView elif x < 100 and x > 50 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) elif x < self.size.x / 2 + 40 and x > self.size.x / 2 - 40 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True elif x < self.size.x - 50 and x > self.size.x - 100 and y < 220 and y > 160 and len( self.locations) > 2: self.pathState = True else: self.MoreState = False self.clipState = False self.pathState = False #open landmark elif y > 150 and y < 200 and self.imageMode == True: sound.play_effect('arcade:Laser_2') self.imageModeOpen = True self.imageMode = False self.heightFrame = (self.photoHeight / self.photoWidth) * (self.size.x) self.widthFrame = (self.photoWidth / self.photoWidth) * (self.size.x) self.heightPhoto = (self.photoHeight / self.photoWidth) * (self.size.x - 20) self.widthPhoto = (self.photoWidth / self.photoWidth) * (self.size.x - 20) self.halfScreenFrame = self.size.y / 2 - self.heightFrame / 2 self.halfScreen = self.size.y / 2 - self.heightPhoto / 2 self.img = ui.Button(name='image') self.img.frame = (10, self.halfScreen, self.widthPhoto, self.heightPhoto) self.img.background_image = self.ui_image self.img.enable = False self.img.hidden = False self.view.add_subview(self.img) elif y < 150 and y > 200 and self.imageMode == True: self.imageMode = False #reset button elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.checkedOnce = 0 self.background_color = self.theme["backgroundColor"] self.locations = [] self.needMore = False self.photoCount = 0 self.photoLocations = [] self.locationsLeft = [] self.needMore = False self.timerCount = 0 #more button elif x < self.size.w / 2 + 25 and x > self.size.w / 2 - 25 and y < 30 and y > 0: self.MoreState = True #take photos and add to album elif x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == False and self.measuringOn == True and picTaken == False: imageree = photos.capture_image() if imageree != None: photos.save_image(imageree) time.sleep(1) self.photoCount += 1 allAssets = photos.get_assets() theImage = allAssets[-1] #print("Divider") # Find the album or create it: try: self.photoLibrary = [ a for a in photos.get_albums() if a.title == 'Thread' ][0] except IndexError: self.photoLibrary = photos.create_album('Thread') # Add the file as an asset to the library: # asset = photos.create_image_asset(theImage) # Add the asset to the album: theImage = allAssets[len(allAssets) - 1] self.photoLibrary.add_assets([theImage]) self.photoLocations += [latLong] #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) elif self.measuringOn == False and self.checkedOnce == 0: #sound.play_effect('arcade:Laser_2') self.measuringOn = True self.background_color = self.theme["backgroundColor"] self.checkedOnce += 1 elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) < 4: #sound.play_effect('arcade:Laser_1') self.needMore = True elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = self.theme["backgroundColor"] self.checkedOnce += 1 elif self.measuringOn == False and self.checkedOnce == 3: #sound.play_effect('arcade:Laser_1') self.background_color = self.theme["backgroundColor"] self.checkedOnce += 1
def touch_began(self, touch): sound.play_effect('Footstep') #creates a query of the locations recorded and opens it on google maps #because the query accepts at most around 20 points, if you have more #than 20 points it will create a new list and get points evenly spaced #throughout the path to a total of less than 20. Looks representative #and accurate. def mapView(self): googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) #when you run across a landmark (photo) you placed down, it will #notify you its present and you can tap to reveal the photo def openLandmark(self): sound.play_effect('Click_1') self.imageModeOpen = True self.imageMode = False self.heightPhoto = (self.photoHeight/self.photoWidth) * \ (self.size.x-20) self.widthPhoto = (self.photoWidth/self.photoWidth) * \ (self.size.x-20) self.heightFrame = self.heightPhoto + 10 self.widthFrame = self.widthPhoto + 10 self.halfScreenFrame = self.size.y / 2 - self.heightFrame / 2 self.halfScreen = self.size.y / 2 - self.heightPhoto / 2 #asked a question on the omz (Pythonista) forum and they answered! #'https://forum.omz-software.com/topic/5263/displaying-an-image- #from-album-in-photos-onto-screen-in-scene-module' #opens the image and has it hidden. self.img = ui.Button(name='image') self.img.frame = (10, self.halfScreen, self.widthPhoto, self.heightPhoto) self.img.background_image = self.ui_image self.img.enable = False self.img.hidden = False self.view.add_subview(self.img) #when you tap, get the current location to perform functions current = location.get_location() #solved the close points problem using rounding latLong = (round(current['latitude'], 4), round(current['longitude'], 4)) picTaken = latLong in self.photoLocations #get the location on the screen of the touch x, y = touch.location #if the image is open, close it when you tap (has to be off the image) if self.imageModeOpen == True: self.imageModeOpen = False self.img.hidden = True #if you have the loop Prompt, you must tap an answer in order to use #the other functions if self.loopPrompt == True: if x > 50 and x < self.size.x/2 and y < self.size.y/2 \ and y > self.size.y/2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x/2 and x < self.size.x-50 \ and y < self.size.y/2 and y > self.size.y/2 - 50: self.loopPrompt = False self.loopPromptState = 2 #when it has the more menu open, you must are not able to tap any of #the other buttons, other than the ones in the more menu elif self.MoreState == True: #SOS State tap, call the cops if you tap if x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView tap elif x < 100 and x > 50 and y < 220 and y > 160 and \ len(self.locations) >= 2: mapView(self) #create the query, but make it a link for phone users, and copy #it to the clipboard elif x < self.size.x/2+40 and x > self.size.x/2-40 and \ y < 220 and y > 160 and len(self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True #tap on Trace button to reveal the path elif x < self.size.x-50 and x > self.size.x-100 and y < 220 \ and y > 160 and len(self.locations) > 2: self.pathState = True #tap on theme button to switch the theme elif x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > self.size.y-95-40 and y < self.size.y-95+40: self.themeSwitch += 1 if self.themeSwitch % 2 == 0: self.theme = self.lightMode elif self.themeSwitch % 2 == 1: self.theme = self.darkMode #tap off a button while in the more menu, and it exits the menu else: self.MoreState = False self.clipState = False self.pathState = False #open landmark by tapping on the banner elif y > 150 and y < 200 and self.imageMode == True: openLandmark(self) #if in image mode, tap off the image to get rid of it off the screen elif y < 150 and y > 200 and self.imageMode == True: self.imageMode = False #reset button resets everything elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.functionState = 0 self.background_color = self.theme["backgroundColor"] self.locations = [] self.needMore = False self.photoCount = 0 self.photoLocations = [] self.locationsLeft = [] self.needMore = False self.timerCount = 0 #more button is a small and out of the way, opens up more menu elif x < self.size.w/2 + 25 and x > self.size.w/2 - 25 and y < 30 \ and y > 0: self.MoreState = True #take photos and add to album elif x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > 50 and y < 100 and self.MoreState == False and \ self.measuringOn == True and picTaken == False: imageree = photos.capture_image() if imageree != None: #open up the camera and you can take photo photos.save_image(imageree) time.sleep(1) self.photoCount += 1 allAssets = photos.get_assets() theImage = allAssets[-1] #if there is no album, create album 'Thread' try: self.photoLibrary = [a for a in photos.get_albums() \ if a.title == 'Thread'][0] except IndexError: self.photoLibrary = photos.create_album('Thread') #add the image to the album for the user to have and for #future use in the app's use (landmarks!) theImage = allAssets[len(allAssets) - 1] self.photoLibrary.add_assets([theImage]) self.photoLocations += [latLong] #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) #go to measuring mode when tapped for the first time elif self.measuringOn == False and self.functionState == 0: self.measuringOn = True self.background_color = self.theme["backgroundColor"] self.functionState += 1 #if you need more values do not let the user stop recording elif self.measuringOn == True and self.functionState == 1 \ and len(self.locations) < 4: self.needMore = True #if you have enough locations, when you tap you can move to next state elif self.measuringOn == True and self.functionState == 1 \ and len(self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = self.theme["backgroundColor"] self.functionState += 1 #move function state up to state 4 so you can begin tracing back elif self.measuringOn == False and self.functionState == 3: #sound.play_effect('arcade:Laser_1') self.background_color = self.theme["backgroundColor"] self.functionState += 1
def getAlbum(album_name): albums = photos.get_albums() for ab in albums: if ab.title == album_name: return ab return photos.create_album(album_name)
import photos if __name__ == '__main__': photos.create_album('Test1') photos.create_album('Test2') albums = photos.get_albums() for k, a in enumerate(albums): if a.title in ('Test1', 'Test2'): print(f'Deleting album "{a.title}"...') a.delete() print(f'"{a.title}" is gone, dude!')
def touch_began(self, touch): x, y = touch.location if self.loopPrompt == True: if x > 50 and x < self.size.x / 2 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x / 2 and x < self.size.x - 50 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 2 elif self.MoreState == True: #SOS State if x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView elif x < 100 and x > 50 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) elif x < self.size.x / 2 + 40 and x > self.size.x / 2 - 40 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True elif x < self.size.x - 50 and x > self.size.x - 100 and y < 220 and y > 160: self.pathState = True else: self.MoreState = False self.clipState = False self.pathState = False #reset button elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.checkedOnce = 0 self.background_color = 'white' self.locations = [] self.needMore = False #more button elif x < self.size.w / 2 + 25 and x > self.size.w / 2 - 25 and y < 30 and y > 0: self.MoreState = True elif x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == False: imageree = photos.capture_image() photos.save_image(imageree) time.sleep(3) self.photoCount += 1 all_assets = photos.get_assets() theImage = all_assets[-1] #print("Divider") # Find the album or create it: try: album = [ a for a in photos.get_albums() if a.title == 'Thread' ][0] except IndexError: album = photos.create_album('Thread') # Add the file as an asset to the library: # asset = photos.create_image_asset(theImage) # Add the asset to the album: theImage = all_assets[len(all_assets) - 1] album.add_assets([theImage]) #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) elif self.measuringOn == False and self.checkedOnce == 0: #sound.play_effect('arcade:Laser_2') self.measuringOn = True self.background_color = 'white' self.checkedOnce += 1 elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) < 4: #sound.play_effect('arcade:Laser_1') self.needMore = True elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = 'white' self.checkedOnce += 1 elif self.measuringOn == False and self.checkedOnce == 3: #sound.play_effect('arcade:Laser_1') self.background_color = 'white' self.checkedOnce += 1