def get_graphics(self): graphics = Graphics() email_address = self._task_master.read_task_data(EMAIL_UID) url = os.path.join(self._task_master.get_bundle_path(), 'html-content', self._uri[0]) graphics.add_uri('file://' + url, height=self._height) graphics.set_zoom_level(self._zoom_level) if email_address is not None: self._entry[0] = graphics.add_entry(text=email_address) else: self._entry[0] = graphics.add_entry() self._entry[0].connect('activate', self._enter_entered) phone_number = self._task_master.read_task_data(PHONE_NUMBER_UID) url = os.path.join(self._task_master.get_bundle_path(), 'html-content', self._uri[1]) graphics.add_uri('file://' + url, height=self._height) graphics.set_zoom_level(self._zoom_level) if phone_number is not None: self._entry[1] = graphics.add_entry(text=phone_number) else: self._entry[1] = graphics.add_entry() return graphics, self._prompt
def __init__(self, handle): activity.Activity.__init__(self, handle) # we do not have collaboration features # make the share option insensitive self.max_participants = 1 # toolbar with the new toolbar redesign toolbar_box = ToolbarBox() activity_button = ActivityButton(self) toolbar_box.toolbar.insert(activity_button, 0) activity_button.show() title_entry = TitleEntry(self) toolbar_box.toolbar.insert(title_entry, -1) title_entry.show() description_item = DescriptionItem(self) toolbar_box.toolbar.insert(description_item, -1) description_item.show() share_button = ShareButton(self) toolbar_box.toolbar.insert(share_button, -1) share_button.show() separator = Gtk.SeparatorToolItem() separator.props.draw = False separator.set_expand(True) toolbar_box.toolbar.insert(separator, -1) separator.show() stop_button = StopButton(self) toolbar_box.toolbar.insert(stop_button, -1) stop_button.show() # FONT DEFINITIONS FONT_FACE = 'Monospace' input_font = Pango.FontDescription('%s %d' % (FONT_FACE, int(FONT_SIZE * 1.2))) entry_font = Pango.FontDescription('%s %d' % (FONT_FACE, int(FONT_SIZE * 10.0 ))) self.set_toolbar_box(toolbar_box) toolbar_box.show() # label with the text, make the string translatable center_in_panel = Gtk.Alignment.new(0.5, 0, 0, 0) graphics = Graphics() first = 'methane' self._first_entry = graphics.add_entry(first) self._first_entry.override_font(input_font) self._spac1 = graphics.add_text(' ') print("LOG: #56, ", self._first_entry, self._first_entry ) button = graphics.add_button(_("COMPUTE"), self.something ) self._spac2 = graphics.add_text(' ') button.show() self.hold_hi3 = graphics.add_text( _(" "), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold_hi3.override_font(input_font) self.hold_hi2 = graphics.add_text( _(" "), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold_hi2.override_font(input_font) self.hold_hi1 = graphics.add_text( _(" "), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold_hi1.override_font(input_font) self.hold0 = graphics.add_text( _("CH4"), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold0.override_font(input_font) self.hold_lo1 = graphics.add_text( _(" "), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold_lo1.override_font(input_font) self.hold_lo2 = graphics.add_text( _(" "), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold_lo2.override_font(input_font) self.hold_lo3 = graphics.add_text( _(" "), size="xx-large", bold=True, justify=Gtk.Justification.CENTER) self.hold_lo3.override_font(input_font) center_in_panel.add(graphics) graphics.show() self.set_canvas(center_in_panel) center_in_panel.show()
class Support5Task(HTMLTask): def __init__(self, task_master): HTMLTask.__init__(self, task_master) self._name = _('Enter School Name') self.uid = _ENTER_SCHOOL_TASK self._uri = ['support5a.html', 'support5b.html'] self._height = 60 self._graphics = None self._school_entry = None self._postal_code_entry = None self._postal_code_changed = True self._postal_code = -1 self._buttons = [] self._schools = [] self._sf_ids = [] self._results = [] self._default_sf_id = '0019000000pETbT' self._completer = None def _postal_code_enter_entered(self, widget): # Force new list self._postal_code_changed = True if self._is_valid_postal_code_entry(): self._school_entry.grab_focus() self._is_valid_school_entry() def _postal_code_entry_cb(self, widget, event): if self._is_valid_postal_code_entry(): self._is_valid_school_entry() def _is_valid_postal_code_entry(self, target=None): if target is None: target = self._postal_code_entry.get_text() if len(target) < 3: return False try: i = int(target) except: return False if i >= 0 and i < 9999: self._postal_code_changed = True self._postal_code = i self._task_master.write_task_data(POST_CODE, target) return True else: return False def _school_enter_entered(self, widget): if self._is_valid_school_entry(): self._task_master.enter_entered() def test(self): return self._is_valid_school_entry() def _is_valid_school_entry(self): # build a completer for this postal code if self._postal_code < 0: return False if self._postal_code_changed: # get rid of any old buttons for button in self._buttons: button.destroy() f = open(os.path.join(self._task_master.activity.bundle_path, 'schools.txt'), 'r') schools = f.read().split('\n') f.close() self._schools = [] self._sf_ids = [] for school in schools: if len(school) == 0: continue try: sf_id, name, campus, address, city, state, postal_code = \ school.split(',') except: _logger.debug('bad school data? (%s)' % school) # save the SF_ID from One Education in case we need it if name == 'One Education School': self._default_sf_id = sf_id try: if int(postal_code) != self._postal_code: continue except: _logger.error('bad postal code? (%s: %s)' % (name, postal_code)) continue if len(campus) > 0: self._schools.append('%s %s, %s, %s' % (name, campus, city, state)) else: self._schools.append('%s, %s, %s' % (name, city, state)) self._sf_ids.append(sf_id) # _logger.debug('%d schools in the list' % (len(self._schools))) self._completer = utils.Completer(self._schools) if len(self._schools) < 10: self._make_buttons(self._schools) self._postal_code_changed = False if len(self._school_entry.get_text()) == 0: return False else: return True def _make_buttons(self, school_list): for button in self._buttons: button.destroy() self._buttons = [] for i, school in enumerate(school_list): self._buttons.append( self._graphics.add_button(school, self._button_cb, arg=school)) self._buttons[-1].show() def _button_cb(self, widget, text): self._school_entry.set_text(text) for button in self._buttons: button.destroy() def _school_entry_focus_cb(self, widget, event): if not self._is_valid_postal_code_entry(): return elif len(widget.get_text()) == 0 and len(self._schools) > 0: self._make_buttons(self._schools) def _school_entry_release_cb(self, widget, event): if len(self._results) == 1: widget.set_text(self._results[0]) for button in self._buttons: button.destroy() elif len(self._results) < 10: for button in self._buttons: button.destroy() self._make_buttons(self._results) def _school_entry_press_cb(self, widget, event): if not self._is_valid_postal_code_entry(): return self._results = self._completer.complete( widget.get_text() + Gdk.keyval_name(event.keyval), 0) def _yes_no_cb(self, widget, arg): if arg == 'yes': self._task_master.write_task_data(SCHOOL_UID, None) school = self._school_entry.get_text() postal_code = self._postal_code_entry.get_text() self._task_master.write_task_data(self.uid, self._task_data) self._task_master.write_task_data(SCHOOL_NAME, school) self._task_master.write_task_data(POST_CODE, postal_code) self._task_master.write_task_data(SCHOOL_UID, self._default_sf_id) self._task_master.current_task += 1 self._task_master.write_task_data('current_task', self._task_master.current_task) self._task_master.task_master() def after_button_press(self): school = self._school_entry.get_text() if school in self._schools: i = self._schools.index(school) self._task_master.write_task_data(SCHOOL_UID, self._sf_ids[i]) self._task_master.write_task_data(SCHOOL_NAME, school) return True else: # Confirm that it is OK to use a school not in the list. self._task_master.task_button.hide() self._graphics.add_text(_('Your school does not appear in our ' 'list of schools in Australia. ' 'OK to continue?')) self._graphics.add_yes_no_buttons(self._yes_no_cb) return False def get_graphics(self): self._graphics = Graphics() url = os.path.join(self._task_master.get_bundle_path(), 'html-content', self._uri[0]) self._graphics.add_uri('file://' + url, height=self._height) self._graphics.set_zoom_level(self._zoom_level) target = self._task_master.read_task_data(POST_CODE) if target is not None and \ self._is_valid_postal_code_entry(target=target): self._postal_code_entry = self._graphics.add_entry(text=target) else: self._postal_code_entry = self._graphics.add_entry() self._postal_code_entry.connect('key-release-event', self._postal_code_entry_cb) self._postal_code_entry.connect('key-press-event', self._postal_code_entry_cb) self._postal_code_entry.connect('activate', self._postal_code_enter_entered) url = os.path.join(self._task_master.get_bundle_path(), 'html-content', self._uri[1]) self._graphics.add_uri('file://' + url, height=self._height) self._graphics.set_zoom_level(self._zoom_level) target = self._task_master.read_task_data(SCHOOL_NAME) if target is not None: self._school_entry = self._graphics.add_entry(text=target) else: self._school_entry = self._graphics.add_entry() self._school_entry.connect('key-release-event', self._school_entry_release_cb) self._school_entry.connect('key-press-event', self._school_entry_press_cb) self._school_entry.connect('focus-in-event', self._school_entry_focus_cb) self._school_entry.connect('activate', self._school_enter_entered) self._postal_code_entry.grab_focus() return self._graphics, self._prompt def grab_focus(self): self._postal_code_entry.set_can_focus(True) self._school_entry.set_can_focus(True) if len(self._postal_code_entry.get_text()) < 3: self._task_master.activity.set_copy_widget( text_entry=self._postal_code_entry) self._task_master.activity.set_paste_widget( text_entry=self._postal_code_entry) else: self._task_master.activity.set_copy_widget( text_entry=self._school_entry) self._task_master.activity.set_paste_widget( text_entry=self._school_entry)