def expose(self, widget,event): alloc = self.get_allocation() line_scale = self.drawing_size*15/32 line_shift_x = alloc[0]+(alloc[2]+1)/2 line_shift_y = alloc[1]+(alloc[3]+1)/2 lines = [ ] if not self.others_angle and self.connected: self.connected = 0 self.set_from_file(utility.find_file("pixmaps/diagram-bg-red.xpm")) if self.others_angle and not self.connected: self.connected = 1 self.set_from_file(utility.find_file("pixmaps/diagram-bg.xpm")) for it in self.others_angle: it_p = complex(math.cos(it),math.sin(it)) me_p = complex(math.cos(self.my_angle),math.sin(self.my_angle)) if not self.hashtable_running: lines.append( [ (int(it_p.real*line_scale+line_shift_x),int(it_p.imag*line_scale+line_shift_y)), (int(it_p.real*line_scale*0.7+line_shift_x),int(it_p.imag*line_scale*0.7+line_shift_y)) ]) continue chord_len = abs(it_p - me_p) if chord_len < 0.001: continue # Simpler code for drawing between almost-opposite points. if abs(it_p + me_p) * line_scale < 2 * 3.0: lines.append( [ (int(me_p.real*line_scale+line_shift_x),int(me_p.imag*line_scale+line_shift_y)), (int(it_p.real*line_scale+line_shift_x),int(it_p.imag*line_scale+line_shift_y)) ]) continue n_bends = 8 n_segments = n_bends + 1 list = [ ] point = me_p tot_rot = (it_p / -me_p) rot = tot_rot ** (1.0/n_bends) delta = (chord_len * abs((rot - 1) / ((tot_rot * rot) - 1)) * -me_p) for i in range(n_segments + 1): list.append((int(point.real*line_scale+line_shift_x),\ int(point.imag*line_scale+line_shift_y))) point = point + delta delta = delta * rot lines.append(list) style = widget.get_style() for list in lines: gtk.gdk.Drawable.draw_lines(widget.window,style.light_gc[0],list)
def __init__(self): gtk.Image.__init__(self) self.set_from_file(utility.find_file("pixmaps/diagram-bg.xpm")) self.connected = 0 self.drawing_size = self.get_pixbuf().get_width() self.connect_after("expose-event",self.expose) self.my_angle = 0 self.others_angle = [1,2, 3, 4] self.hashtable_running = 0
def search_task(daemon,query,input,output,connection): global http_mode,http_port,http_socket global http_socket file=open(utility.find_file("ui_http/search.html")) str=file.read() file.close() if http_mode=='local': image_tag = "<img src=\"file://"+utility.find_file("pixmaps/circle-logo.png")\ +"\" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> " hostname = 'localhost' else: image_tag = "<img src=\"http://thecircle.org.au/circle-logo.png\" "\ +" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> " hostname = 'thecircle.dyndns.org' for char in '+-_.,?()![]': query = query.replace(char," ") query=query.lower() list=query.split() if list: key=list[0] else: key='' try: output.write('HTTP/1.1 200 OK\n') output.write('content-type: text/html\n') output.write('Cache-control: max-age=60\n') output.write('\n') output.write(str%(hostname,http_port,hostname,http_port,image_tag)) output.flush() if key.__len__()<3: output.write("<p>Keyword %s too short: must be at least 3 characters<p></body></html>"%key) input.close() output.close() connection.close() return except: return pipe = daemon.node.retrieve(hash.hash_of(key)) results = [] restricted = 0 while not pipe.finished() and not restricted: for item in pipe.read_all(): if results.__len__()==100: restricted = 1 break if item[1]['name'] not in results: results.append(item[1]['name']) filename = utility.force_string(item[1]['filename']) extension = string.split(string.split(filename,'.')[-1],'-')[0] lext = string.lower(extension) if lext in ['mp3','ogg']: music=1 else: music=0 if item[1].has_key('music_title'): ref = utility.force_string(item[1]['music_title']) if ref.strip()=='': ref= filename else: ref = utility.force_string(item[1]['filename']) try: output.write("<p class=g><t>\n") output.write(url(stress(ref,key),\ hash.hash_to_url(item[1]['name']),filename,http_port)) output.write("<br><font size=-1>") if music: line=0 if item[1].has_key('music_artist'): artist_str="Artist:"+stress(utility.force_string(item[1]['music_artist']),key) output.write(artist_str) line=1 if item[1].has_key('music_album'): if item[1]['music_album']!='': album_str=" Album:"+stress(utility.force_string(item[1]['music_album']),key) output.write(album_str) line=1 if line: output.write("<br>") #line=0 #if item[1].has_key('rate'): # output.write("Rate:"+item[1]['rate']+".") # line=1 #if item[1].has_key('freq'): # output.write(" Frequency:"+item[1]['freq']+".") # line=1 #if item[1].has_key('misc'): # output.write(" -- "+item[1]['misc']) # line=1 #if line: # output.write("<br>") output.write("File name: "+stress(filename,key)) output.write("<br>") if item[1].has_key('mime'): if item[1]['mime'] != 'unknown': output.write('Mime: '+item[1]['mime'].replace(' \x08','')) output.write("<br>") if item[1].has_key('generic'): output.write(item[1]['generic'].replace('\x08','')) output.write("<br>") else: for i in item[1].items(): if i[0] not in ['keywords', 'mime','length', 'name','filename', 'type','music_album', 'music_artist','music_title']: output.write(i[0]+':'+stress(i[1],key)+' ') output.write("<br>") output.write("<font color=#008000>"+hash.hash_to_url(item[1]['name'])+" - "\ +utility.human_size(item[1]['length'])+"- </font>") #output.write("<font color=#656565>Sources:<a href="">Sources</a></font>") output.write("</font></p>\n") except: return time.sleep(0.5) try: output.flush() except: return pipe.stop() try: if not results: output.write("<br><br><p>Your search: <b>"+key+"</b> did not match any document.</p>") else: if restricted: output.write("<p><br>Displaying only 100 results for <b>%s</b></p>" % key) else: output.write("<p><br>Found %d files matching <b>%s</b></p>" % (results.__len__(),key)) output.write("<hr><p class=g align=\"right\"></font size=-1>"\ +utility.force_string(random.choice(settings.gratuitous_plugs))+"</font></p><hr>") output.write("</body></html>") input.close() output.close() connection.close() except: pass print "returned %d files for \"%s\""%(results.__len__(), query) sys.stdout.flush()
def find_task(daemon,query,input,output,connection): global http_mode,http_port,http_socket file=open(utility.find_file("ui_http/search.html")) str=file.read() file.close() if http_mode=='local': image_tag = "<img src=\"file://"+utility.find_file("pixmaps/circle-logo.png")\ +"\" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> " hostname = 'localhost' else: image_tag = "<img src=\"http://thecircle.org.au/circle-logo.png\" "\ +" title=\"\" alt=\"\" border=0 style=\"width: 150px; height: 50px;\"> " hostname = 'thecircle.dyndns.org' try: output.write('HTTP/1.1 200 OK\n') output.write('content-type: text/html\n') output.write('Cache-control: max-age=60\n') output.write('\n') output.write(str%(hostname,http_port,hostname,http_port,image_tag)) output.flush() except: return for char in '+-_.,?()![]': query = query.replace(char," ") query=query.lower() list=query.split() if list: key=list[0] pipe = daemon.node.retrieve(hash.hash_of('identity-name '+key), settings.identity_redundancy) else: pipe = daemon.node.retrieve(hash.hash_of('service identity'), settings.identity_redundancy) results = [] while not pipe.finished(): list = pipe.read_all() prev_pair = None for pair in list: if pair == prev_pair: continue link, item = prev_pair = pair try: item = utility.check_and_demangle_item(item) except: continue if item['key'] not in results: results.append(item['key']) name = hash.hash_of(safe_pickle.dumps(item['key'])) check.check_is_name(name) str = "circle-person:"+string.join(map(lambda a:hex(ord(a))[2:], name), '') try: output.write("<p class=g><t><b>\n") output.write(item['name']) output.write(" ("+utility.force_string(item['human-name'])+")") output.write("</b><br>") if item['description']: output.write( "<font size=-1>"+utility.force_string(item['description'])+"<br></font>") output.write("<font color=#008000 size=-1> "+str+"</font></p>\n") except: return time.sleep(0.5) try: output.flush() except: return pipe.stop() try: if not results: output.write("<br><br><p>Your search: <b>"+key+"</b> did not match any circle user.</p>") else: if results.__len__()==1: what = "one identity" else: what = "%d identities"%results.__len__() if query: msg = "Returned " + what + " matching <b>\"" + query + "\"</b>." else: msg = "Returned " + what +"." output.write("<p><br>"+msg+"</p>") output.write("<hr><p class=g align=\"right\"></font size=-1>"\ +utility.force_string(random.choice(settings.gratuitous_plugs))+"</font></p><hr>") output.write("</body></html>") input.close() output.close() connection.close() except: return print "returned %d people for \"%s\""%(results.__len__(), query) sys.stdout.flush()
def __init__(self,app,main_vbox): self.app=app self.playlist=[] self.selected_row = -1 self.playing_row = -1 self.player = None #self.keep_downloading_button = gtk.CheckButton("Keep downloading file") #vbox.pack_start(self.keep_downloading_button) #self.keep_downloading_button.set_active(1) #left_vbox = gtk.VBox(gtk.FALSE, 5) #main_hbox.pack_start(left_vbox,gtk.FALSE,gtk.TRUE) #left_vbox.show() #vbox2 = gtk.VBox(gtk.FALSE, 5) #hbox2.pack_start(vbox2,gtk.FALSE) #vbox2.show() #self.name_label = gtk.Label("") #self.name_label.set_alignment(0,0.5) #main_vbox.pack_start(self.name_label,gtk.FALSE) #self.name_label.show() # hbox for bar and controls dd_hbox = gtk.HBox(gtk.FALSE, 5) main_vbox.pack_start(dd_hbox,gtk.FALSE) dd_hbox.show() # vbox for bar and controls dd_vbox = gtk.VBox(gtk.FALSE, 5) dd_hbox.pack_start(dd_vbox,gtk.TRUE, gtk.FALSE) dd_vbox.show() self.title_label = gtk.Label("") #self.title_label.set_alignment(0.2,0.5) dd_vbox.pack_start(self.title_label,gtk.FALSE) self.title_label.show() #self.artist_label = gtk.Label("") #self.artist_label.set_alignment(0,0.5) #main_vbox.pack_start(self.artist_label,gtk.FALSE) #self.artist_label.show() #self.album_label = gtk.Label("") #self.album_label.set_alignment(0,0.5) #main_vbox.pack_start(self.album_label,gtk.FALSE) #self.album_label.show() self.bitstream_label = gtk.Label("") #self.bitstream_label.set_alignment(0.8,0.5) dd_vbox.pack_start(self.bitstream_label,gtk.FALSE) self.bitstream_label.show() # hbox for bar bar_hbox = gtk.HBox(gtk.FALSE, 5) dd_vbox.pack_start(bar_hbox,gtk.TRUE) bar_hbox.show() self.progress = gtk.ProgressBar() bar_hbox.pack_start(self.progress,gtk.TRUE,gtk.FALSE) self.progress.set_size_request(368,20) def on_press(w,e,self=self): fraction = float(e.x)/float(w.get_allocation().width) if self.player: self.player.seek(fraction) self.progress.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK) self.progress.connect("button_press_event", on_press) # hbox for controls ctrl_hbox = gtk.HBox(gtk.FALSE, 3) dd_vbox.pack_start(ctrl_hbox,gtk.TRUE,gtk.FALSE) ctrl_hbox.show() prev_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-prev.png")) prev_button.add(image) prev_button.set_size_request(50,25) ctrl_hbox.pack_start(prev_button,gtk.FALSE) prev_button.connect("clicked", self.prev_music) prev_button.show() rewind_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-rewind.png")) rewind_button.add(image) rewind_button.set_size_request(50,25) ctrl_hbox.pack_start(rewind_button,gtk.FALSE) rewind_button.connect("clicked", self.back_music) rewind_button.show() play_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-play.png")) play_button.add(image) play_button.set_size_request(50,25) ctrl_hbox.pack_start(play_button,gtk.FALSE) play_button.connect("clicked", self.play_music) play_button.show() pause_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-pause.png")) pause_button.add(image) pause_button.set_size_request(50,25) ctrl_hbox.pack_start(pause_button,gtk.FALSE) pause_button.connect("clicked", self.pause_music) pause_button.show() ffwd_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-ffwd.png")) ffwd_button.add(image) ffwd_button.set_size_request(50,25) ctrl_hbox.pack_start(ffwd_button,gtk.FALSE) ffwd_button.connect("clicked", self.ffwd_music) ffwd_button.show() next_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-next.png")) next_button.add(image) next_button.set_size_request(50,25) ctrl_hbox.pack_start(next_button,gtk.FALSE) next_button.connect("clicked", self.next_music) next_button.show() stop_button = gtk.Button() image = gtk.Image() image.set_from_file(utility.find_file("pixmaps/media-stop.png")) stop_button.add(image) stop_button.set_size_request(50,25) ctrl_hbox.pack_start(stop_button,gtk.FALSE) stop_button.connect("clicked", self.stop_music) stop_button.show() playlist_label = gtk.Label(" ") playlist_label.set_alignment(0.1,0) main_vbox.pack_start(playlist_label,gtk.FALSE) playlist_label.show() self.scrolly = gtk.ScrolledWindow() self.scrolly.set_policy(gtk.POLICY_NEVER,gtk.POLICY_AUTOMATIC) main_vbox.pack_start(self.scrolly, gtk.TRUE,gtk.TRUE,0) self.scrolly.show() #self.scrolly.set_size_request(350,70) self.list = gtk.CList(3) self.list.set_column_min_width(0,350) self.list.set_column_width(1,20) self.list.set_column_width(2,40) self.list.set_selection_mode(gtk.SELECTION_SINGLE) self.scrolly.add(self.list) self.list.show() # hbox for buttons self.bottom_hbox = gtk.HBox(gtk.FALSE, 5) play_button = gtk.Button("Play") self.bottom_hbox.pack_start(play_button,gtk.TRUE) play_button.connect("clicked", self.play_row) play_button.show() close_button = gtk.Button("Discard") self.bottom_hbox.pack_start(close_button,gtk.TRUE) close_button.connect("clicked", self.on_delete) close_button.show() clear_button = gtk.Button("Clear") self.bottom_hbox.pack_start(clear_button,gtk.TRUE) clear_button.connect("clicked", self.clear) clear_button.show() def on_unselect(list,index,column,event,self=self): main_vbox.remove(self.bottom_hbox) self.list.connect("unselect-row",on_unselect) def on_select(list,index,column,event,self=self): self.selected_row = index #self.update_info() main_vbox.pack_end(self.bottom_hbox, 0,0,0) self.bottom_hbox.show() self.list.connect("select-row",on_select)