def init(self): gtk.threads_init() if self.load_last_crawled() and datetime.date.today().day <= self.last_crawled.day and agromaret.load_prices() and bulog.load_prices(): self.update_bulog_table() self.update_agromaret_table(1) self.show_prices() else: thread.start_new_thread(self.crawl, (True,)) thread.start_new_thread(self.crawl_periodically, ()) gtk.main()
def __init__(self, handle): activity.Activity.__init__(self, handle) self.toolbox = activity.ActivityToolbox(self) self.activity_toolbar = self.toolbox.get_activity_toolbar() self.activity_toolbar.keep.props.visible = False self.activity_toolbar.share.props.visible = False self.set_toolbox(self.toolbox) self.toolbox.show() self.prices = gtk.VBox(False, 10) self.button_update = gtk.Button('Perbarui Sekarang') self.button_update.connect('clicked', self.update_prices) align = gtk.Alignment(1, 0, 0, 0) align.add(self.button_update) self.button_update.show() self.prices.pack_start(align, False, False) align.show() self.tables = gtk.Notebook() self.bulog = gtk.VBox(False, 10) self.bulog_scrolled_window = gtk.ScrolledWindow() self.bulog_scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.bulog_viewport = gtk.Viewport() self.bulog_viewport.modify_bg(gtk.STATE_NORMAL, COLOR_WHITE) self.bulog_table = gtk.Table(13, 7) self.bulog_label_name = gtk.Label() self.bulog_label_name.set_markup('<span weight="bold" size="x-large">Nama</span>') self.bulog_table.attach(self.bulog_label_name, 0, 1, 0, 1) self.bulog_label_name.show() self.bulog_label_price1 = gtk.Label() self.bulog_table.attach(self.bulog_label_price1, 2, 3, 0, 1) self.bulog_label_price1.show() self.bulog_label_price2 = gtk.Label() self.bulog_table.attach(self.bulog_label_price2, 4, 5, 0, 1) self.bulog_label_price2.show() self.bulog_label_change = gtk.Label() self.bulog_label_change.set_markup('<span weight="bold" size="x-large">Perubahan</span>') self.bulog_table.attach(self.bulog_label_change, 6, 7, 0, 1) self.bulog_label_change.show() for c in xrange(1, 7, 2): separator = gtk.VSeparator() self.bulog_table.attach(separator, c, c + 1, 0, 13, gtk.SHRINK, gtk.SHRINK) separator.show() separator = gtk.HSeparator() self.bulog_table.attach(separator, 0, 7, 1, 2, gtk.SHRINK, gtk.SHRINK) separator.show() for r in xrange(2, 13, 1): for c in xrange(0, 7, 2): label = self.bulog_labels[r - 2][c / 2] viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.modify_bg(gtk.STATE_NORMAL, COLOR_BLUE if r % 2 == 0 else COLOR_PINK) viewport.add(label) label.show() self.bulog_table.attach(viewport, c, c + 1, r, r + 1) viewport.show() self.bulog_viewport.add(self.bulog_table) self.bulog_table.show() self.bulog_scrolled_window.add(self.bulog_viewport) self.bulog_viewport.show() self.bulog.pack_start(self.bulog_scrolled_window, True, True) self.bulog_scrolled_window.show(); self.bulog_tab_label = gtk.Label() self.bulog_tab_label.set_markup('<span size="xx-large">Beras</span>') self.tables.append_page(self.bulog, self.bulog_tab_label); self.bulog.show() self.bulog_tab_label.show() self.agromaret = gtk.VBox(False, 10) self.agromaret_scrolled_window = gtk.ScrolledWindow() self.agromaret_scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.agromaret_viewport = gtk.Viewport() self.agromaret_viewport.modify_bg(gtk.STATE_NORMAL, COLOR_WHITE) self.agromaret_table = gtk.Table(12, 7) self.agromaret_label_name = gtk.Label() self.agromaret_label_name.set_markup('<span weight="bold" size="x-large">Nama</span>') self.agromaret_table.attach(self.agromaret_label_name, 0, 1, 0, 1) self.agromaret_label_name.show() self.agromaret_label_price = gtk.Label() self.agromaret_label_price.set_markup('<span weight="bold" size="x-large">Harga</span>') self.agromaret_table.attach(self.agromaret_label_price, 2, 3, 0, 1) self.agromaret_label_price.show() self.agromaret_label_city = gtk.Label() self.agromaret_label_city.set_markup('<span weight="bold" size="x-large">Kota</span>') self.agromaret_table.attach(self.agromaret_label_city, 4, 5, 0, 1) self.agromaret_label_city.show() self.agromaret_label_date = gtk.Label() self.agromaret_label_date.set_markup('<span weight="bold" size="x-large">Tanggal</span>') self.agromaret_table.attach(self.agromaret_label_date, 6, 7, 0, 1) self.agromaret_label_date.show() for c in xrange(1, 7, 2): separator = gtk.VSeparator() self.agromaret_table.attach(separator, c, c + 1, 0, 12, gtk.SHRINK, gtk.SHRINK) separator.show() separator = gtk.HSeparator() self.agromaret_table.attach(separator, 0, 7, 1, 2, gtk.SHRINK, gtk.SHRINK) separator.show() for r in xrange(2, 12, 1): for c in xrange(0, 7, 2): label = self.agromaret_labels[r - 2][c / 2] viewport = gtk.Viewport() viewport.set_shadow_type(gtk.SHADOW_NONE) viewport.modify_bg(gtk.STATE_NORMAL, COLOR_BLUE if r % 2 == 0 else COLOR_PINK) viewport.add(label) label.show() self.agromaret_table.attach(viewport, c, c + 1, r, r + 1) viewport.show() self.agromaret_viewport.add(self.agromaret_table) self.agromaret_table.show() self.agromaret_scrolled_window.add(self.agromaret_viewport) self.agromaret_viewport.show() self.agromaret.pack_start(self.agromaret_scrolled_window, True, True) self.agromaret_scrolled_window.show() self.agromaret_page = gtk.HBox(False, 5) self.agromaret_label_page = gtk.Label() self.agromaret_label_page.set_markup('<span size="x-large">Halaman</span>') self.agromaret_page.pack_start(self.agromaret_label_page, False, False) self.agromaret_label_page.show() self.agromaret_combo_page = gtk.combo_box_new_text() self.agromaret_combo_page.append_text('') for i in xrange(1, 11, 1): self.agromaret_combo_page.append_text(str(i)) self.agromaret_combo_page.set_active(1) self.agromaret_combo_page.connect('changed', self.agromaret_page_changed) self.agromaret_page.pack_start(self.agromaret_combo_page, False, False) self.agromaret_combo_page.show() align = gtk.Alignment(0.5, 0, 0, 0) align.add(self.agromaret_page) self.agromaret_page.show() self.agromaret.pack_start(align, False, False) align.show() self.agromaret_tab_label = gtk.Label() self.agromaret_tab_label.set_markup('<span size="xx-large">Lainnya</span>') self.tables.append_page(self.agromaret, self.agromaret_tab_label); self.agromaret.show() self.agromaret_tab_label.show() self.prices.pack_start(self.tables, True, True) self.tables.show() self.prices.show() self.loading = gtk.VBox(False, 10) self.spinner = gtk.Spinner() self.spinner.start() self.loading.pack_start(self.spinner, True, True) self.spinner.show() self.label_wait = gtk.Label() self.loading.pack_start(self.label_wait, False, False) self.label_wait.show() self.loading.show() self.error = gtk.VBox(False, 10) self.label_error_message = gtk.Label() self.label_error_message.set_markup('<span size="xx-large">Tidak bisa akses situs web</span>') align = gtk.Alignment(0.5, 1.0, 0, 0) align.add(self.label_error_message) self.label_error_message.show() self.error.pack_start(align, True, True) align.show() self.button_try_again = gtk.Button('Coba lagi') self.button_try_again.connect('clicked', self.update_prices) align = gtk.Alignment(0.5, 0, 0, 0) align.add(self.button_try_again) self.button_try_again.show() self.error.pack_start(align, True, True) align.show() self.error.show() if self.load_last_crawled() and datetime.date.today().day <= self.last_crawled.day and agromaret.load_prices() and bulog.load_prices(): self.update_bulog_table() self.update_agromaret_table(1) self.show_prices() else: thread.start_new_thread(self.crawl, (True,)) thread.start_new_thread(self.crawl_periodically, ())