shoeset

Check-in [73a783ca97]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:First release candidate of App * API Key and Shared secret in external file * Separated app into different methods * This allows redrawing. If new set is selected redraws progress bar and tag cloud * Added logout method to clear token * Other GUI refinements: - Click on username to show/hide token - logout button - progress bar nudged slightly to right
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | v0.0.1
Files: files | file ages | folders
SHA3-256: 73a783ca9794089a3c09334600d3ffa7f4994303d05e768d39e5ddc7c7722f23
User & Date: i5ivem@gmail.com 2010-03-16 15:27:23
Original User & Date: i5ivem@gmail.com 2010-03-16 15:27:24
Context
2010-03-16
15:27
Adding .gitignore file check-in: bfa08d3a35 user: i5ivem@gmail.com tags: trunk
15:27
First release candidate of App * API Key and Shared secret in external file * Separated app into different methods * This allows redrawing. If new set is selected redraws progress bar and tag cloud * Added logout method to clear token * Other GUI refinements: - Click on username to show/hide token - logout button - progress bar nudged slightly to right check-in: 73a783ca97 user: i5ivem@gmail.com tags: trunk, v0.0.1
15:27
Changed formatting only check-in: 2e3ea62bd5 user: i5ivem@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to shoeset.rb.

3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18



19
20
21
22
23


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39


40
41
42
43
44
45
46













47
48
49
50
51


52
53
54




55















56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85







86
87
88
89
end

require 'flickraw'
require 'yaml'
require 'cloud'


Shoes.app do

	
	#Need to improve GUI feedback on opening. Thread??

	FlickRaw.api_key=""
	FlickRaw.shared_secret=""
	
	TOKENFILE = ENV['HOME']+"\\.shoeset.yml"
	#Load token if it exists



	if File.exists?(TOKENFILE)
				$SETTINGS = YAML::load(File.read(TOKENFILE))
				@token = $SETTINGS["Token"]
				auth = flickr.auth.checkToken :auth_token => @token
				


	else

		frob = flickr.auth.getFrob
		auth_url = FlickRaw.auth_url :frob => frob, :perms => 'read'
	
		para "Click to authorise with Flickr : ", link("Authorise", :click =>auth_url)
		para "Click OK when you are finished."
		@okbutton = button "OK" do
			begin
				auth = flickr.auth.getToken :frob => frob
				
				$SETTINGS = { "Token" => auth.token }
				f = File.open(TOKENFILE, 'w')
				f.write(YAML.dump $SETTINGS)
				f.close



			rescue FlickRaw::FailedResponse => e
				para "Authentication failed : #{e.msg}"
			end
		end
	end
	login = flickr.test.login
	para "You are authenticated as #{login.username} with token #{auth.token}"













	@setlist = []
	@photosetlist = flickr.photosets.getList.each do |set|
		@setlist << set["title"]
	end



	list_box :items => @setlist, 
		:chose => @setlist[0] do |set|
			#Need to implement redraw on next select, etc....




			para set.text















			$p = progress :width => 1.0

			photosetinfo = @photosetlist.select {|s| s["title"] == set.text}
		
			debug(photosetinfo)
			count = photosetinfo[0]["photos"].to_f
			counter = 0.0
			debug photosetinfo[0]["id"].to_s #it's an array of a hash. Even though just one
			photosetphotos = flickr.photosets.getPhotos(:photoset_id => photosetinfo[0]["id"] )
			debug(photosetphotos["photo"])
			$array = []
			Thread.new do
				photosetphotos["photo"].each do |photo|
					debug flickr.tags.getListPhoto(:photo_id => photo["id"])
					temp = flickr.tags.getListPhoto(:photo_id => photo["id"])
					temp["tags"].each do |tags| #should be an array
						$array << tags["_content"]
					end
					debug $array
					sleep(1) # Sleep interval between calls.
					counter += 1.0
					$p.fraction = counter/count
					debug (counter/count)
					# Caching - anyway? Could cache list of photos from set, but then what about if updated?
				end

			cloud = TagCloud.new($array.join(" "))
			$p.hide
			debug cloud.build
			eval cloud.build
			end
		end







end










|


|
>
|
|
<

<
>
>
>
|
|
|
|
<
>
>
|
<
|
|
|
|
|
|
|
|
<
|
|
|
|
<
>
>
|
|
|
|
|
<
<
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
<
>
>
|
|
<
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>


|
|
|
|
>
>
>
>
>
>
>




3
4
5
6
7
8
9
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24

25
26
27

28
29
30
31
32
33
34
35

36
37
38
39

40
41
42
43
44
45
46


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

64
65
66
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
end

require 'flickraw'
require 'yaml'
require 'cloud'


Shoes.app :title => "Shoeset" do

	
	KEYFILE = "keys.yml"
	KEYS = YAML::load(File.read(KEYFILE))
	FlickRaw.api_key=KEYS["api_key"]
	FlickRaw.shared_secret=KEYS["shared_secret"]

	TOKENFILE = ENV['HOME']+"\\.shoeset.yml"


	#Need to improve GUI feedback/responsive on opening. Thread??
	def login
		if File.exists?(TOKENFILE) #Load token if it exists
					$SETTINGS = YAML::load(File.read(TOKENFILE))
					@token = $SETTINGS["Token"]
					@auth = flickr.auth.checkToken :auth_token => @token

					@login = flickr.test.login
					@container.clear{ui} #draw ui 		
		else

			frob = flickr.auth.getFrob
			auth_url = FlickRaw.auth_url :frob => frob, :perms => 'read'
		
			para "Click to ", link("authorise", :click =>auth_url), " with Flickr."
			para "Click OK when you are finished."
			@okbutton = button "OK" do
				begin
					@auth = flickr.auth.getToken :frob => frob

					$SETTINGS = { "Token" => @auth.token }
					f = File.open(TOKENFILE, 'w')
					f.write(YAML.dump $SETTINGS)
					f.close

					@login = flickr.test.login
					@container.clear{ui} #draw ui
				rescue FlickRaw::FailedResponse => e
					para "Authentication failed : #{e.msg}"
				end
			end
		end


	end


	def ui
		flow do
			para "You are logged in as "
			para link(@login.username){@token.toggle}
			button "Logout", :displace_left => 10 do
				logout
			end
		end
		@token = para "Token: #{@auth.token}"
		@token.hide
		@setlist = []
		@photosetlist = flickr.photosets.getList.each do |set|
			@setlist << set["title"]
		end

		flow do
			para "Pick a set to generate Tag Cloud: "
			list_box :items => @setlist, 
				:chose => @setlist[0] do |set|

					fluffygen(set)				
				end
		end #flow
		@tagcloud = flow do #if this is a stack then clearing it goes crazy
			para ""
		end #set-up placeholder for tag cloud
	end
	

	def logout
		#remove token file
		File.delete(TOKENFILE)
		#clear window and restart
		@container.clear
		login
	end

	
	def fluffygen(set)
		@tagcloud.clear #is this because it's on a global variable that it clears everything???? Nope
		$p = progress :width => 0.8, :displace_left => 10
		#debug(set.text)
		photosetinfo = @photosetlist.select {|s| s["title"] == set.text}

		#debug(photosetinfo)
		count = photosetinfo[0]["photos"].to_f
		counter = 0.0
		#debug photosetinfo[0]["id"].to_s #it's an array of a hash. Even though just one
		photosetphotos = flickr.photosets.getPhotos(:photoset_id => photosetinfo[0]["id"] )
		#debug(photosetphotos["photo"])
		$array = []
		Thread.new do
			photosetphotos["photo"].each do |photo|
				#debug flickr.tags.getListPhoto(:photo_id => photo["id"])
				temp = flickr.tags.getListPhoto(:photo_id => photo["id"])
				temp["tags"].each do |tags| #should be an array
					$array << tags["_content"]
				end
				#debug $array
				sleep(1) # Sleep interval between calls.
				counter += 1.0
				$p.fraction = counter/count
				#debug (counter/count)
				# Caching - anyway? Could cache list of photos from set, but then what about if updated?
			end
			#debug $array
			cloud = TagCloud.new($array.join(" "))
			$p.hide
			#debug cloud.build
			@tagcloud.clear{eval cloud.build}
		end
	end


	@container = slot do
		para "Never see this"
	end
	login

end