Exemple #1
0
    def __init__(self, width, height):
        """Initializes the Canvas Object
        
        width,height -- passed to the inner EventBox in order to request a given size,
            the Socket is the only child of this EventBox, and the Pygame commands
            will be writing to the Window ID of the socket.  The internal EventBox is 
            centered via an Alignment instance within the PygameCanvas instance.
            
        XXX Should refactor so that the internal setup can be controlled by the 
        sub-class, e.g. to get size from the host window, or something similar.
        """
        # Build the main widget
        log.info('Creating the pygame canvas')
        super(PygameCanvas, self).__init__()
        self.set_flags(gtk.CAN_FOCUS)

        # Build the sub-widgets
        self._align = gtk.Alignment(0.5, 0.5)
        self._inner_evb = gtk.EventBox()
        self._socket = gtk.Socket()

        # Add internal widgets
        self._inner_evb.set_size_request(width, height)
        self._inner_evb.add(self._socket)

        self._socket.show()

        self._align.add(self._inner_evb)
        self._inner_evb.show()

        self._align.show()

        self.put(self._align, 0, 0)

        # Construct a gtkEvent.Translator
        self._translator = gtkEvent.Translator(self, self._inner_evb)
        # <Cue Thus Spract Zarathustra>
        self.show()
Exemple #2
0
    def __init__(self, runaslib=True):
        #if runaslib is True -> we are in a Xo laptop
        paths.set_environment(runaslib)

        #local variables
        self.clicked = False  #is a clic chosen to download?
        self.selected = False  #is a clic chosen to play?
        self.start_clic_view = False  #is a clic_activity running?
        self.views_path = paths.views_path  #path to the icons folder (appIcons)
        self.icons_path = paths.icons_path  #path to the views folder (appViews)

        #loading application views
        self.xmlMain = gtk.glade.XML(self.views_path + '/windowApp.glade')
        #loading window (Sugar has it owns window - not this one)
        self.window = self.xmlMain.get_widget('window')
        self.window.connect("destroy", gtk.main_quit)

        # Get Windows child (Vertical Box with the views)
        self.w_child = self.window.get_child()
        # Needs to remove the parent (we will use the Sugar's window)
        if runaslib:
            gtk.Container.remove(self.window, self.w_child)
#        else :
#            state = gtk.STATE_NORMAL
#            color = gtk.gdk.Color("orange")
#            self.window.modify_bg(state, color)

#LOADING MAIN VIEW
        self.xml = gtk.glade.XML(self.views_path + '/mainView.glade')
        self.win = self.xml.get_widget('window')
        self.Main = self.xml.get_widget('Main')
        #remove parent (in glade there is always a parent (window))
        gtk.Container.remove(self.win, self.Main)

        #loading the image of the title (SugarClic)
        self.ImageSearch = self.xml.get_widget('imageTitle')
        self.ImageSearch.set_from_file(self.icons_path + '/title.png')

        #MyClics button
        self.bMy = self.xml.get_widget('buttonMyClics')
        self.bMy.connect('clicked', self.__available_clics_view)
        self.bMy.connect('enter', self.__change_icon, '/clics_2.png', 0)
        self.bMy.connect('leave', self.__change_icon, '/clics.png', 0)
        self.ImageMy = self.xml.get_widget('imageMyClics')
        self.ImageMy.set_from_file(self.icons_path + '/clics.png')

        #Manual button
        self.bManual = self.xml.get_widget('buttonManual')
        self.bManual.connect('clicked', self.__manual_view)
        self.bManual.connect('enter', self.__change_icon, '/manual_2.png', 1)
        self.bManual.connect('leave', self.__change_icon, '/manual.png', 1)
        self.ImageManual = self.xml.get_widget('imageManual')
        self.ImageManual.set_from_file(self.icons_path + '/manual.png')

        #About button
        self.bAbout = self.xml.get_widget('buttonAbout')
        self.bAbout.connect('clicked', self.__about_view)
        self.bAbout.connect('enter', self.__change_icon, '/about_2.png', 2)
        self.bAbout.connect('leave', self.__change_icon, '/about.png', 2)
        self.ImageAbout = self.xml.get_widget('imageAbout')
        self.ImageAbout.set_from_file(self.icons_path + '/about.png')

        #Search button
        self.bS = self.xml.get_widget('buttonSearch')
        self.bS.connect('clicked', self.__browser_view)
        self.bS.connect('enter', self.__change_icon, '/download_2.png', 3)
        self.bS.connect('leave', self.__change_icon, '/download.png', 3)
        self.ImageSearch = self.xml.get_widget('imageSearch')
        self.ImageSearch.set_from_file(self.icons_path + '/download.png')

        #set the labels to translate
        self.labelMan = self.xml.get_widget('labelManual')
        self.labelMan.set_text(_('MANUAL'))
        self.labelAbout = self.xml.get_widget('labelAbout')
        self.labelAbout.set_text(_('ABOUT SUGARCLIC'))
        self.labelSearch = self.xml.get_widget('labelSearch')
        self.labelSearch.set_text(_('DOWNLOAD CLICS'))
        self.labelMYCLICS = self.xml.get_widget('labelMyClics')
        self.labelMYCLICS.set_text(_('MY CLICS'))

        #load the test that appears in the centre of the main menu
        path_to_texto = os.path.join(paths.application_bundle_path,
                                     'data/textoInicio.txt')
        file = open(path_to_texto, 'r')
        self.labelTextoInicial = self.xml.get_widget('labelInitText')
        self.labelTextoInicial.set_text(file.read())
        file.close()

        #LOADING MY CLICS VIEW
        self.xml = gtk.glade.XML(self.views_path + '/MyClicsView.glade')
        #loading window
        self.windowAva = self.xml.get_widget('window')

        self.iconView = self.xml.get_widget('iconviewAvailable')
        self.iconView.connect(
            'selection-changed', self.__clics_view
        )  #item-activated 2 clicks //selection-changed 1 click

        self.bClics = self.xml.get_widget('buttonClics')
        self.bClics.connect('clicked', self.__generate_list)
        self.currentClicsView = 'Clics'

        self.bPM = self.xml.get_widget('buttonAvaMain')
        self.bPM.connect('clicked', self.__main_view)

        self.labelMy = self.xml.get_widget('labelMyClics')
        self.vboxAvailable = self.xml.get_widget('vboxAvailable')
        self.labelButBorrar = self.xml.get_widget('labelButBorrar')
        self.labelButAvaMain = self.xml.get_widget('labelButAvaMain')
        self.labelButAvaMain.set_text(_('MAIN MENU'))

        self.imageBorrar = self.xml.get_widget('imageClics')
        self.imageSI = self.xml.get_widget('imageSI')
        self.imageSI.set_from_file(self.icons_path + '/si.png')
        self.imageNO = self.xml.get_widget('imageNO')
        self.imageNO.set_from_file(self.icons_path + '/no.png')

        self.ImageHome = self.xml.get_widget('imageHome')
        self.ImageHome.set_from_file(self.icons_path + '/home.png')

        self.hboxSure = self.xml.get_widget('hboxSure')
        self.buttonSI = self.xml.get_widget('buttonSI')
        self.buttonSI.connect('clicked', self.__remove_clic)
        self.buttonNO = self.xml.get_widget('buttonNO')
        self.buttonNO.connect('clicked', self.__dont_remove_clic)
        self.labelSure = self.xml.get_widget('labelSure')

        gtk.Container.remove(self.windowAva, self.vboxAvailable)

        #LOADING BROWSER VIEW
        self.xml = gtk.glade.XML(self.views_path + '/BrowserView.glade')
        #loading window
        self.windowBrowser = self.xml.get_widget('window')

        self.bBM = self.xml.get_widget('buttonHome')
        self.bBM.connect('clicked', self.__main_view)
        self.ImageBr = self.xml.get_widget('imageHome')
        self.ImageBr.set_from_file(self.icons_path + '/home.png')

        self.bGo = self.xml.get_widget('buttonFirstPage')
        self.bGo.connect('clicked', self.__browser_view_galeria)
        self.ImageGo = self.xml.get_widget('imageGoBack')
        self.ImageGo.set_from_file(self.icons_path + '/goBack.png')

        self.labelButHome = self.xml.get_widget('labelButHome')
        self.labelButHome.set_text(_('MAIN MENU'))
        self.labelButFirst = self.xml.get_widget('labelButFirst')
        self.labelButFirst.set_text(_('CLICS TO DOWNLOAD'))

        self.vboxBrowser = self.xml.get_widget('vboxBrowser')
        self.browser = Browser()
        self.vboxBrowser.add(self.browser)
        gtk.Container.remove(self.windowBrowser, self.vboxBrowser)

        #LOADING VIEW FOR CLICS PLAYER
        self.xml = gtk.glade.XML(self.views_path + '/PlayView.glade')
        #loading window
        self.windowPlay = self.xml.get_widget('window')
        self.vboxPlay = self.xml.get_widget('vboxPlay')
        #initialize play_clics area
        self.area = self.xml.get_widget('playArea')
        self.area.set_size_request(Constants.MAX_WIDTH, Constants.MAX_HEIGHT)
        #translates GTK events into Pygame events
        t = gtkEvent.Translator(self.area)
        self.area.connect('map-event', self.__callback)
        t.hook_pygame()
        gtk.Container.remove(self.windowPlay, self.vboxPlay)

        # self.widget will be attached to the XO-Activity
        # This can be any GTK widget except a window
        self.widget = self.w_child

        #initiate controller
        self.controller = Controller()

        #current(first) view is the main menu
        self.current_view = self.Main
        self.w_child.add(self.current_view)

        if not runaslib:
            #called every 250 miliseconds (for communication with pygame module (player))
            gobject.timeout_add(250, self.updating)
            self.window.show()
            gtk.main()