#! /usr/bin/env python from __future__ import division import os,shlex,subprocess,math import math from math import pi , tan, radians, sqrt import pyglet from pyglet.gl import * from pyglet import window from pyglet.window import key, mouse, Window from pyglet import app,clock from pyglet.image.codecs import * import applications from my_camera import camera from objects import * #----------------------End Classes---------------------------- #_________________Globals_________________________________ def convert_color_alpha(color): r, g, b, a= color return float(r/255), float(g/255), float(b/255), float(a/255) def convert_color(color): r, g, b= color return float(r/255), float(g/255), float(b/255) window = window.Window(width=800, height=600, style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS,visible=False) screen_width = window.screen.width screen_height = window.screen.height window.set_location(int(screen_width/2 - window.width/2),int( screen_height/2 - window.height/2)) window.set_caption("BigSky") fps_display = pyglet.clock.ClockDisplay() batch = pyglet.graphics.Batch() batch2 = pyglet.graphics.Batch() text_group = pyglet.graphics.OrderedGroup(1) #self, name, execute, cat_type, x, y, z, w, h, boxs = [] x = 0 y = window.height z = 0 box_color = convert_color_alpha((165,165,255, 255)) box_color2 = convert_color_alpha((255,0,0, 255)) h_box_color = convert_color_alpha((255, 255, 255, 255)) text_color = (0, 255, 255, 255) window_color = convert_color_alpha((24, 24, 128, 255)) glClearColor(*window_color) camera = camera(window.width/2, window.height /2, window.width, window.height) camera.update() drag = False drag_lenght = 0 drag_base = window.width*.04 # ---- Build Objects -------- anchor_lower_x = 1 box_height = 80 box_width = 200 spacer = 10 offset = 20 top_bottom_offset = 100 +box_height left_right_offset = 20 x = 0 y= window.height ml = applications.application_list() lables = [] section_location_x = [] section_list = [] s_iter = 0 max_x = 0 def calc_objects(): global x, y, ml, boxs, lables, section_location_x, box_height, box_width, spacer global left_right_offset, top_bottom_offset, batch , batch2, anchor_lower_x , s_iter global section_list, max_x , text_color del boxs[:] del lables[:] favs = ['Google Chrome', "Firefox"] batch = pyglet.graphics.Batch() batch2 = pyglet.graphics.Batch() z = 8 x=0 y = window.height for i in ml.known_cats: title = i #titles thelist = ml.list[i] # The List for this cat number_of_items = float(len(thelist)) #number of items in cat title_y = top_bottom_offset/2 #setup title for cat title_x = x col_num = 0 # Add space to the sections. if len(thelist) > 0: col_num = 1 title_x = x for level2 in thelist: if y - top_bottom_offset <= box_height: x += (box_width + spacer) y = window.height col_num += 1 if level2.name in favs: box_c = box_color2 else: box_c = box_color boxs.append(l_items(level2.name, level2.execute, level2.icon, title, x + left_right_offset, y - top_bottom_offset , z , box_width , box_height , box_c, text_color, batch)) y -= (box_height + spacer) y = window.height width_of_section =int(col_num * (box_width+spacer)) # this over all witdh of cat if col_num > 0: #if there is somethinng there draw title of cat lables.append(top_titles(title_x, title_y, width_of_section ,window.width, window.height, title, batch2)) x += (box_width + spacer + left_right_offset) section_location_x.append(lables[-1].get_center_x()) section_list.append(title) if number_of_items > 0: x += spacer*2 max_x = x + spacer + left_right_offset camera.max_world_x = max_x # -----draw and stuff------- def move(n): camera.pan(n) def goto_full_screen(): window.set_fullscreen(fullscreen = True) def get_next_section(): global s_iter if s_iter + 1 < len(section_location_x): s_iter += 1 print s_iter, section_location_x[s_iter] , section_list[s_iter] return section_location_x[s_iter] def get_prev_section(): global s_iter if s_iter > 1: s_iter -= 1 print s_iter, section_location_x[s_iter] , section_list[s_iter] return section_location_x[s_iter] @window.event def on_resize(width, height): calc_objects() window.set_location(int(screen_width/2 - window.width/2),int( screen_height/2 - window.height/2)) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, 1.0 * width / height, 0.1, 100.0) camera.w = width camera.h = height camera.x = window.width/2 camera.y = window.height /2 camera.target.x = camera.x camera.target.y = camera.y camera.headsup(window.width, window.height) @window.event def on_draw(): glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_TEXTURE_2D) glEnable (GL_BLEND) glEnable (GL_LINE_SMOOTH) glClear(GL_COLOR_BUFFER_BIT) glLoadIdentity() camera.update() camera.project(window.width, window.height) batch.draw() batch2.draw() camera.headsup(window.width, window.height) fps_display.draw() clock.schedule(lambda _: None) key_handlers = { key.ESCAPE: lambda: window.close(), key.PAGEUP: lambda: camera.pan_lr(window.width), key.PAGEDOWN: lambda: camera.pan_lr(-window.width), key.LEFT: lambda:camera.pan_lr(-box_width+spacer), key.RIGHT: lambda: camera.pan_lr(box_width+spacer), key.DOWN: lambda: camera.goto_x(get_next_section()), key.UP: lambda: camera.goto_x(get_prev_section()), key.END: lambda: camera.goto_x(max_x), key.HOME: lambda:camera.goto_x(0), key.F: lambda: goto_full_screen(), } def launch_ap(application): print("starting {0}".format(application)) a = shlex.split(application) subprocess.Popen(a) exit_app() def exit_app(): window.set_fullscreen(fullscreen=False) window.minimize() pyglet.app.exit() def check_for_box( x , y , nx , ny ): for i in boxs: if nx > i.x and nx < (i.x + i.w) and ny > i.y and ny < (i.y + i.h): print ("starting {0}".format(i.execute)) launch_ap(i.execute) @window.event def on_deactivate(): exit_app() @window.event def on_key_press(symbol, modifiers): handler = key_handlers.get(symbol, lambda: None) handler() @window.event def on_mouse_motion(x, y, dx, dy): nx, ny = camera.calc_pos(x, y) #print x , y , nx , ny , camera.scale for i in boxs: if nx > i.x and nx < (i.x + i.w) and ny > i.y and ny < (i.y + i.h): i.box_color = h_box_color i.highted = True i.z = -5 i.update() elif i.highted == True : i.highted = False i.box_color = box_color i.z = 8 i.update() print i.icon @window.event def on_mouse_release(x, y, button, modifiers): global drag, drag_lenght, drag_base print drag_lenght, drag if button & mouse.LEFT: if drag == True and drag_lenght >= drag_base: camera.pan_lr(-window.width) elif drag == True and drag_lenght <= -drag_base: camera.pan_lr(+window.width) elif drag == True and (drag_lenght < drag_base and drag_lenght > -drag_base): nx, ny = camera.calc_pos(x, y) cb = check_for_box(x, y, nx, ny ) drag = False drag_lenght = 0 @window.event def on_mouse_drag(x, y, dx, dy, buttons, modifiers): global drag_lenght , drag print x, dx if buttons & mouse.MIDDLE: camera.pan(dx, 0) if buttons & mouse.LEFT : #camera.pan(dx, 0) drag = True drag_lenght += dx @window.event def on_mouse_press(x, y, button, modifiers): global drag if button == mouse.LEFT and drag == False: drag = True @window.event def on_mouse_scroll(x, y, scroll_x, scroll_y): if scroll_y > 0: camera.goto_x(get_next_section()) if scroll_y < 0: camera.goto_x(get_prev_section()) window.set_visible(visible=True) pyglet.app.run()