view window.py @ 0:661e6ef8f8e4 draft default tip

Initial commit
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 14 Jan 2017 13:22:10 +0100
parents
children
line wrap: on
line source

import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade

import browser

class MainWindow:
    def __init__(self):
        self.xml = gtk.glade.XML('racoon.glade')
        self.xml.signal_autoconnect(self)
        self.location_entry =  self.xml.get_widget('location_entry')
        self.location_entry.connect('activate', self.on_location_entry_activate)
        self.status_bar = self.xml.get_widget('status_bar')
        self.load_progress = self.xml.get_widget('load_progress')
        self.stop_button = self.xml.get_widget('stop_button')
        self.refresh_button = self.xml.get_widget('refresh_button')
        self.main_window = self.xml.get_widget('main_window')
        self.link_menu = self.xml.get_widget('link_menu')
        self.page_menu = self.xml.get_widget('page_menu')
        self.browser = browser.Browser(self)

    def status_push(self, context, text):
        context_id = self.status_bar.get_context_id(context)
        self.status_bar.push(context_id, text)

    def status_pop(self, context):
        context_id = self.status_bar.get_context_id(context)
        self.status_bar.pop(context_id)

    def set_title(self, text):
        self.main_window.set_title(text)

    def set_location(self, url):
        self.location_entry.set_text(url)


    def start_loading(self, url):
        self.load_progress.set_text(url)
        self.load_progress.set_property('visible',  True)
        self.location_entry.set_property('visible', False)
        self.stop_button.set_property('visible',  True)
        self.refresh_button.set_property('visible', False)

    def finish_loading(self):
        self.load_progress.set_property('visible',  False)
        self.location_entry.set_property('visible', True)
        self.stop_button.set_property('visible',  False)
        self.refresh_button.set_property('visible', True)
        

# ----- The event handlers -----------

    def on_location_entry_activate(self, entry):
        self.browser.open_url(self.location_entry.get_text())

    def on_back_button_clicked(self, button):
        self.browser.history_back()

    def on_refresh_button_clicked(self, button):
        self.browser.open_url(self.browser.current_url)

    def on_main_window_destroy(self, window):
        gtk.main_quit()

    def on_location_dropdown_change(self, dropdown):
        if self.location_entry.get_text()=='clear':
            self.location_entry.set_text('')