class EncryptionManager(object):
    def __init__(self, interface_name):
        self.interface_name = interface_name
        self.template_manager = TemplateManager()
        self.template_manager.load_all_available_templates()
    def start(self, network):
        self.stop()
        profile = network.profile
        if not 'encryption_type' in network.profile:
            raise WicdError('Network profile does not specify encryption type')
        encryption_type = network.profile['encryption_type']
        template_class = self.template_manager.get_template(encryption_type)
        if not template_class:
            raise WicdError('Template type %s does not exist' % encryption_type)
        values = {}
        for requirement in template_class.require:
            if requirement.name in profile:
                values[requirement.name] = str(profile[requirement.name])
            else:
                raise WicdError('Missing required value %s' % requirement.name)
        values['essid'] = network.essid
        values['scan'] = 0
        log('wpa_supplicant values', values)
        wpa_conf_name = network.bssid.replace(':', '').lower()
        wpa_conf_name += 'vpb'
        self.create_configuration_file(wpa_conf_name, template_class, values)
        pathname = os.path.join(wpath.networks, wpa_conf_name)
        self.wpa_supplicant = misc.run([
            misc.find_program_in_path('wpa_supplicant'), '-i', 
            self.interface_name, '-D', 'wext', '-c', pathname
        ], return_fileobject=True)
    def stop(self):
        if hasattr(self, 'wpa_supplicant'):
            log('killing wpa_supplicant %s' % self.wpa_supplicant.pid)
            os.kill(self.wpa_supplicant.pid, 15)
        else:
            log('no wpa_supplicant running')
    def __del__(self):
        self.stop()
    def __copy__(self): return self
    def __deepcopy__(self, memo): return self
    def create_configuration_file(self, filename, template_class, values):
        wpa_supplicant_template = str(template_class.template)
        for key, value in values.iteritems():
            value = str(value)
            find = "$_%s" % key.upper()
            log('replacing %s with %s' % (find, value))
            wpa_supplicant_template = \
                                    wpa_supplicant_template.replace(find, value)
        pathname = os.path.join(wpath.networks, filename)
        log('writing wpa_supplicant configuration file %s' % pathname)
        the_file = open(pathname, 'w')
        the_file.write(wpa_supplicant_template)
        the_file.close()
Esempio n. 2
0
 def sample_with_template(self, num, prime):
     # create template
     tm = TemplateManager()
     tm.generate_template(length=num + len(prime.split()))
     while not tm.match(sentence=prime):
         print("The prime won't work with the template! Generating new template...")
         tm.generate_template(length=num)
     # sample words
     probs = self.sample_probs(num, prime)
     ret = prime
     for p in probs:
         valid = False
         while not valid:
             sample = np.random.choice(self.vocab_size, p=p)
             word = self.data_loader.vocab_list[sample]
             temp_ret = ret + " " + word
             valid = tm.match_latest(sentence=temp_ret)
             # renormalize
             p[sample] = 0.0
             p /= np.sum(p)
         ret = temp_ret
     return tm.format_sentence(ret)
 def __init__(self, interface_name):
     self.interface_name = interface_name
     self.template_manager = TemplateManager()
     self.template_manager.load_all_available_templates()
Esempio n. 4
0
    def __init__(self, parent):
        super(CopyVerseDialog, self).__init__(parent)
        self.tm = TemplateManager(self)
        self.is_custom = False
        self.based_on = ""

        # fill up the list of templates
        self.fill_templates()

        fields = None

        settings = config_manager["BPBible"]["copy_verse"]

        # if we are a tuple, we represent based_on, fields
        # otherwise we are a template name
        copy_formatted = False
        if isinstance(settings, tuple):
            if len(settings) == 2:
                # old style
                based_on, fields = settings
                self.is_custom = True
            else:
                based_on, fields, copy_formatted = settings
                self.is_custom = fields != None

        else:
            # old style
            based_on = settings

        if self.is_custom:
            self.make_custom(based_on)

        else:
            item_id = 0
            for idx, item in enumerate(self.tm.templates):
                if item.name == based_on:
                    item_id = idx
                    break

                # remember default, but keep on looking
                if item.name == "Default":
                    item_id = idx

            self.tm.change_template(item_id)
            self.gui_template_list.SetStringSelection(self.tm.template.name)

            fields = self.tm.template

        # put the template panel in
        self.template_panel = TemplatePanel(self.tp_holder, fields, False)
        self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW)
        self.tp_holder.Fit()
        self.tp_holder.Parent.Parent.Label = _("Edit Template...")
        self.Fit()
        self.SetMinSize(self.Size)

        # do binding
        for event in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
            self.reference.Bind(event, self.update)

        self.copy_formatted.SetValue(copy_formatted)
        self.copy_formatted.Bind(wx.EVT_CHECKBOX, self.update)

        for item in self.template_panel.fields:
            for event in [wx.EVT_KILL_FOCUS]:  #, stc.EVT_STC_MODIFIED]:
                item.Bind(event, self.update)
            item.Bind(stc.EVT_STC_MODIFIED, self.on_text_changed)

            colour, text_colour = guiconfig.get_window_colours()
            for style in stc.STC_STYLE_DEFAULT, 0:
                item.StyleSetBackground(style, colour)
                item.StyleSetForeground(style, text_colour)

            item.SetCaretForeground(text_colour)

        self.wxID_CANCEL.Bind(wx.EVT_BUTTON, lambda x: self.Destroy())
        self.wxID_OK.Bind(wx.EVT_BUTTON, self.ok_button_clicked)

        self.gui_save_template.Bind(wx.EVT_BUTTON, self.save_template)
        self.gui_load_template.Bind(wx.EVT_BUTTON, self.load_template)
        self.gui_template_list.Bind(wx.EVT_CHOICE, self.on_template_choice)

        self.preview.book = biblemgr.bible
        self.has_preview_been_loaded = False
Esempio n. 5
0
class CopyVerseDialog(xrcCopyVerseDialog):
    def __init__(self, parent):
        super(CopyVerseDialog, self).__init__(parent)
        self.tm = TemplateManager(self)
        self.is_custom = False
        self.based_on = ""

        # fill up the list of templates
        self.fill_templates()

        fields = None

        settings = config_manager["BPBible"]["copy_verse"]

        # if we are a tuple, we represent based_on, fields
        # otherwise we are a template name
        copy_formatted = False
        if isinstance(settings, tuple):
            if len(settings) == 2:
                # old style
                based_on, fields = settings
                self.is_custom = True
            else:
                based_on, fields, copy_formatted = settings
                self.is_custom = fields != None

        else:
            # old style
            based_on = settings

        if self.is_custom:
            self.make_custom(based_on)

        else:
            item_id = 0
            for idx, item in enumerate(self.tm.templates):
                if item.name == based_on:
                    item_id = idx
                    break

                # remember default, but keep on looking
                if item.name == "Default":
                    item_id = idx

            self.tm.change_template(item_id)
            self.gui_template_list.SetStringSelection(self.tm.template.name)

            fields = self.tm.template

        # put the template panel in
        self.template_panel = TemplatePanel(self.tp_holder, fields, False)
        self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW)
        self.tp_holder.Fit()
        self.tp_holder.Parent.Parent.Label = _("Edit Template...")
        self.Fit()
        self.SetMinSize(self.Size)

        # do binding
        for event in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
            self.reference.Bind(event, self.update)

        self.copy_formatted.SetValue(copy_formatted)
        self.copy_formatted.Bind(wx.EVT_CHECKBOX, self.update)

        for item in self.template_panel.fields:
            for event in [wx.EVT_KILL_FOCUS]:  #, stc.EVT_STC_MODIFIED]:
                item.Bind(event, self.update)
            item.Bind(stc.EVT_STC_MODIFIED, self.on_text_changed)

            colour, text_colour = guiconfig.get_window_colours()
            for style in stc.STC_STYLE_DEFAULT, 0:
                item.StyleSetBackground(style, colour)
                item.StyleSetForeground(style, text_colour)

            item.SetCaretForeground(text_colour)

        self.wxID_CANCEL.Bind(wx.EVT_BUTTON, lambda x: self.Destroy())
        self.wxID_OK.Bind(wx.EVT_BUTTON, self.ok_button_clicked)

        self.gui_save_template.Bind(wx.EVT_BUTTON, self.save_template)
        self.gui_load_template.Bind(wx.EVT_BUTTON, self.load_template)
        self.gui_template_list.Bind(wx.EVT_CHOICE, self.on_template_choice)

        self.preview.book = biblemgr.bible
        self.has_preview_been_loaded = False

    def on_text_changed(self, event):
        # one of our text fields have changed
        # if we are not custom, add a custom item at the end
        event.Skip()
        if self.is_custom:
            return

        self.make_custom(self.gui_template_list.StringSelection)

    def make_custom(self, based_on):
        self.is_custom = True
        self.based_on = based_on
        self.gui_template_list.Append(
            _("<custom: based on %s>") % self.based_on)

        self.gui_template_list.SetSelection(self.gui_template_list.Count - 1)

    def on_template_choice(self, event):
        selection = event.Selection
        if self.is_custom:
            custom_idx = self.gui_template_list.Count - 1
            # custom one
            if selection == custom_idx:
                return

            # remove the custom one
            self.gui_template_list.Delete(custom_idx)

        event.Skip()
        self.is_custom = False
        self.transfer_from_templatemanager(selection)
        self.update()

    def load_template(self, event=None):
        was_custom, based_on = self.is_custom, self.based_on

        selection = self.tm.template.name

        ansa = self.tm.ShowModal()

        if ansa == wx.ID_OK:
            # transfer the fields across
            self.transfer_from_templatemanager()

            # use the new selection
            selection = self.tm.template.name

        # fill up the list again
        was_selected = self.fill_templates(selection)

        # if we were custom, put ourselves back in proper
        if was_custom and ansa != wx.ID_OK:
            self.make_custom(based_on)

        # if the user has deleted the template we were using, make it a custom
        # template based on the original name
        elif not was_selected:
            self.make_custom(selection)

        self.update()

    def transfer_from_templatemanager(self, selection=None):
        if selection is not None:
            self.tm.change_template(selection)

        self.gui_template_list.SetStringSelection(self.tm.template.name)

        for field in self.template_panel.fields:
            field.set_text(self.tm.template[field.field])

    def fill_templates(self, selection=None):
        """Fill the template choice up with the template names.

		Returns True if selection was found, False otherwise.
		If selection isn't found, first item will be selected"""
        self.gui_template_list.Clear()
        found = False
        for idx, item in enumerate(self.tm.templates):
            self.gui_template_list.Append(item.name)
            if item.name == selection:
                self.gui_template_list.SetSelection(idx)
                found = True

        if not found:
            # if not found, select the last item
            self.gui_template_list.SetSelection(0)

        return found

    def Destroy(self):
        self.tm.Destroy()
        return super(CopyVerseDialog, self).Destroy()

    def save_template(self, event=None):
        name = self.tm.template.name
        if self.is_custom:
            name = self.based_on

        template = Template(name=name, readonly=False)
        for field in self.template_panel.fields:
            template[field.field] = field.Text

        if not self.tm.save_template(template):
            return

        self.tm.save()
        self.is_custom = False

        self.fill_templates(template.name)

    def get_internal_reference(self):
        return GetBestRange(self.reference.GetValue(),
                            userInput=True,
                            userOutput=False)

    def update(self, event=None, ref=None, dialog_hidden_mode=False):
        if not self.has_preview_been_loaded:
            # Have to make sure this doesn't include the placeholder divs and styles,
            # since they cause boxes to appear around the text when pasted into OpenOffice.
            self.preview.SetPage("&nbsp;", include_wrapper_divs=False)
            self.has_preview_been_loaded = True

        if event:
            event.Skip()

        plain_text = self.GetText(ref or self.get_internal_reference())
        if (not dialog_hidden_mode) or self.formatted:
            text = plain_text
            if not self.formatted: text = text.replace("\n", "<br />")
            self.preview.ExecuteScriptAfterDocumentLoaded(
                """$("body").html(%s);""" % json.dumps(text))
        return plain_text

    def ShowDialog(self, text):
        # set the reference
        self.reference.SetValue(
            GetBestRange(text, userInput=False, userOutput=True))

        # update the text
        self.update()

        super(CopyVerseDialog, self).Show()

    def ok_button_clicked(self, event):
        self.copy_verses(self.get_internal_reference())
        if self.is_custom:
            config_manager["BPBible"]["copy_verse"] = (
                self.based_on,
                dict(header=self.template_panel.header.GetText(),
                     body=self.template_panel.body.GetText(),
                     footer=self.template_panel.footer.GetText()),
                self.formatted)

        else:
            config_manager["BPBible"]["copy_verse"] = (
                self.gui_template_list.StringSelection), None, self.formatted

        self.Destroy()

    @property
    def formatted(self):
        return self.copy_formatted.IsChecked()

    def copy_verses(self, ref, dialog_hidden_mode=False):
        print "Updating...", ref
        text_to_copy = self.update(ref=ref,
                                   dialog_hidden_mode=dialog_hidden_mode)
        if self.formatted:
            self.preview.copyall()
        else:
            guiutil.copy(text_to_copy)

    def GetText(self, ref):
        print "Getting text for", ref
        template = VerseTemplate(header=self.template_panel.header.GetText(),
                                 body=self.template_panel.body.GetText(),
                                 footer=self.template_panel.footer.GetText())

        #no footnotes
        biblemgr.temporary_state(biblemgr.plainstate)
        if display_options.options["colour_speakers"] == "woc_in_red":
            biblemgr.set_option("Words of Christ in Red", "On")

        #apply template
        biblemgr.bible.templatelist.append(template)
        biblemgr.parser_mode = COPY_VERSES_PARSER_MODE

        data = biblemgr.bible.GetReference(ref)
        if data is None:
            data = config.MODULE_MISSING_STRING()

        if self.formatted:
            # TODO: make it scan CSS and amalgamate rules?
            data = data.replace("<span class='WoC'>",
                                "<span style='color: red'>")
            data = data.replace("<span class='divineName'>",
                                "<span style='font-variant:small-caps'>")

            # Use the font that has been selected for the module.
            # XXX: We could still use language specific fonts for particular
            # sections of the text, but I'm not sure it's worth doing.
            # It would probably only apply to Hebrew and Greek (which we
            # treat specially) anyway.
            default, (font, size, in_gui) = fonts.get_module_font_params(
                biblemgr.bible.mod)
            data = u"<span style=\"font-family: %s; font-size: %spt;\">%s</span>" % (
                font, size, data)
        else:
            data = string_util.br2nl(data)
            data = string_util.KillTags(data)
            data = string_util.amps_to_unicode(data)

        #restore
        biblemgr.restore_state()
        biblemgr.bible.templatelist.pop()
        biblemgr.parser_mode = NORMAL_PARSER_MODE
        return data
Esempio n. 6
0
	def __init__(self, parent):
		super(CopyVerseDialog, self).__init__(parent)
		self.tm = TemplateManager(self)
		self.is_custom = False
		self.based_on = ""
		
		# fill up the list of templates
		self.fill_templates()
		
		fields = None

		settings = config_manager["BPBible"]["copy_verse"]

		# if we are a tuple, we represent based_on, fields
		# otherwise we are a template name
		copy_formatted = False
		if isinstance(settings, tuple):
			if len(settings) == 2:
				# old style
				based_on, fields = settings
				self.is_custom = True
			else:
				based_on, fields, copy_formatted = settings
				self.is_custom = fields != None

		else:
			# old style
			based_on = settings

		if self.is_custom:
			self.make_custom(based_on)

		else:
			item_id = 0
			for idx, item in enumerate(self.tm.templates):
				if item.name == based_on:
					item_id = idx
					break

				# remember default, but keep on looking
				if item.name == "Default":
					item_id = idx

			self.tm.change_template(item_id)
			self.gui_template_list.SetStringSelection(
				self.tm.template.name
			)
			
			fields = self.tm.template

		# put the template panel in
		self.template_panel = TemplatePanel(self.tp_holder, fields, False)
		self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW)
		self.tp_holder.Fit()
		self.tp_holder.Parent.Parent.Label = _("Edit Template...")
		self.Fit()
		self.SetMinSize(self.Size)


		# do binding
		for event in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
			self.reference.Bind(event, self.update)

		self.copy_formatted.SetValue(copy_formatted)
		self.copy_formatted.Bind(wx.EVT_CHECKBOX, self.update)

		for item in self.template_panel.fields:
			for event in [wx.EVT_KILL_FOCUS]:#, stc.EVT_STC_MODIFIED]:
				item.Bind(event, self.update)
			item.Bind(stc.EVT_STC_MODIFIED, self.on_text_changed)
			
			colour, text_colour = guiconfig.get_window_colours()
			for style in stc.STC_STYLE_DEFAULT, 0:
				item.StyleSetBackground(style, colour)
				item.StyleSetForeground(style, text_colour)
			
			item.SetCaretForeground(text_colour)

		self.wxID_CANCEL.Bind(wx.EVT_BUTTON, 
					lambda x:self.Destroy())
		self.wxID_OK.Bind(wx.EVT_BUTTON, self.ok_button_clicked)

		self.gui_save_template.Bind(wx.EVT_BUTTON, self.save_template)
		self.gui_load_template.Bind(wx.EVT_BUTTON, self.load_template)
		self.gui_template_list.Bind(wx.EVT_CHOICE, self.on_template_choice)

		self.preview.book = biblemgr.bible
		self.has_preview_been_loaded = False
Esempio n. 7
0
class CopyVerseDialog(xrcCopyVerseDialog):
	def __init__(self, parent):
		super(CopyVerseDialog, self).__init__(parent)
		self.tm = TemplateManager(self)
		self.is_custom = False
		self.based_on = ""
		
		# fill up the list of templates
		self.fill_templates()
		
		fields = None

		settings = config_manager["BPBible"]["copy_verse"]

		# if we are a tuple, we represent based_on, fields
		# otherwise we are a template name
		copy_formatted = False
		if isinstance(settings, tuple):
			if len(settings) == 2:
				# old style
				based_on, fields = settings
				self.is_custom = True
			else:
				based_on, fields, copy_formatted = settings
				self.is_custom = fields != None

		else:
			# old style
			based_on = settings

		if self.is_custom:
			self.make_custom(based_on)

		else:
			item_id = 0
			for idx, item in enumerate(self.tm.templates):
				if item.name == based_on:
					item_id = idx
					break

				# remember default, but keep on looking
				if item.name == "Default":
					item_id = idx

			self.tm.change_template(item_id)
			self.gui_template_list.SetStringSelection(
				self.tm.template.name
			)
			
			fields = self.tm.template

		# put the template panel in
		self.template_panel = TemplatePanel(self.tp_holder, fields, False)
		self.tp_holder.Sizer.Add(self.template_panel, 1, wx.GROW)
		self.tp_holder.Fit()
		self.tp_holder.Parent.Parent.Label = _("Edit Template...")
		self.Fit()
		self.SetMinSize(self.Size)


		# do binding
		for event in [wx.EVT_KILL_FOCUS, wx.EVT_TEXT_ENTER]:
			self.reference.Bind(event, self.update)

		self.copy_formatted.SetValue(copy_formatted)
		self.copy_formatted.Bind(wx.EVT_CHECKBOX, self.update)

		for item in self.template_panel.fields:
			for event in [wx.EVT_KILL_FOCUS]:#, stc.EVT_STC_MODIFIED]:
				item.Bind(event, self.update)
			item.Bind(stc.EVT_STC_MODIFIED, self.on_text_changed)
			
			colour, text_colour = guiconfig.get_window_colours()
			for style in stc.STC_STYLE_DEFAULT, 0:
				item.StyleSetBackground(style, colour)
				item.StyleSetForeground(style, text_colour)
			
			item.SetCaretForeground(text_colour)

		self.wxID_CANCEL.Bind(wx.EVT_BUTTON, 
					lambda x:self.Destroy())
		self.wxID_OK.Bind(wx.EVT_BUTTON, self.ok_button_clicked)

		self.gui_save_template.Bind(wx.EVT_BUTTON, self.save_template)
		self.gui_load_template.Bind(wx.EVT_BUTTON, self.load_template)
		self.gui_template_list.Bind(wx.EVT_CHOICE, self.on_template_choice)

		self.preview.book = biblemgr.bible
		self.has_preview_been_loaded = False
	
	def on_text_changed(self, event):
		# one of our text fields have changed
		# if we are not custom, add a custom item at the end
		event.Skip()
		if self.is_custom:
			return
		
		self.make_custom(self.gui_template_list.StringSelection)
		
	def make_custom(self, based_on):
		self.is_custom = True
		self.based_on = based_on
		self.gui_template_list.Append(
			_("<custom: based on %s>") % self.based_on
		)

	
		self.gui_template_list.SetSelection(self.gui_template_list.Count - 1)
		
	def on_template_choice(self, event):
		selection = event.Selection
		if self.is_custom:
			custom_idx = self.gui_template_list.Count - 1
			# custom one
			if selection == custom_idx:
				return

			# remove the custom one
			self.gui_template_list.Delete(custom_idx)

		event.Skip()
		self.is_custom = False
		self.transfer_from_templatemanager(selection)
		self.update()
		
	
	def load_template(self, event=None):
		was_custom, based_on = self.is_custom, self.based_on

		selection = self.tm.template.name

		ansa = self.tm.ShowModal()
		
		if ansa == wx.ID_OK:
			# transfer the fields across
			self.transfer_from_templatemanager()

			# use the new selection
			selection = self.tm.template.name

		# fill up the list again
		was_selected = self.fill_templates(selection)

		# if we were custom, put ourselves back in proper
		if was_custom and ansa != wx.ID_OK:
			self.make_custom(based_on)
		
		# if the user has deleted the template we were using, make it a custom
		# template based on the original name
		elif not was_selected:
			self.make_custom(selection)

		self.update()
			

	def transfer_from_templatemanager(self, selection=None):
		if selection is not None:
			self.tm.change_template(selection)
		
		self.gui_template_list.SetStringSelection(self.tm.template.name)

		for field in self.template_panel.fields:
			field.set_text(self.tm.template[field.field])
	
	def fill_templates(self, selection=None):
		"""Fill the template choice up with the template names.

		Returns True if selection was found, False otherwise.
		If selection isn't found, first item will be selected"""
		self.gui_template_list.Clear()
		found = False
		for idx, item in enumerate(self.tm.templates):
			self.gui_template_list.Append(item.name)
			if item.name == selection:
				self.gui_template_list.SetSelection(idx)
				found = True
		
		if not found:
			# if not found, select the last item
			self.gui_template_list.SetSelection(0)
		
		return found
		
	def Destroy(self):
		self.tm.Destroy()
		return super(CopyVerseDialog, self).Destroy()
	
	def save_template(self, event=None):
		name = self.tm.template.name
		if self.is_custom:
			name = self.based_on

		template = Template(name=name, readonly=False)
		for field in self.template_panel.fields:
			template[field.field] = field.Text

		if not self.tm.save_template(template):
			return

		self.tm.save()
		self.is_custom = False
		
		self.fill_templates(template.name)

	def get_internal_reference(self):
		return GetBestRange(self.reference.GetValue(), 
				userInput=True, userOutput=False)
		
	def update(self, event=None, ref=None, dialog_hidden_mode=False):
		if not self.has_preview_been_loaded:
			# Have to make sure this doesn't include the placeholder divs and styles,
			# since they cause boxes to appear around the text when pasted into OpenOffice.
			self.preview.SetPage("&nbsp;", include_wrapper_divs=False)
			self.has_preview_been_loaded = True

		if event: 
			event.Skip()

		plain_text = self.GetText(ref or self.get_internal_reference())
		if (not dialog_hidden_mode) or self.formatted:
			text = plain_text
			if not self.formatted: text = text.replace("\n", "<br />")
			self.preview.ExecuteScriptAfterDocumentLoaded(
				"""$("body").html(%s);""" % json.dumps(text))
		return plain_text

	def ShowDialog(self, text):
		# set the reference
		self.reference.SetValue(
			GetBestRange(text, userInput=False, userOutput=True)
		)
		
		# update the text
		self.update()

		super(CopyVerseDialog, self).Show()

	def ok_button_clicked(self, event):
		self.copy_verses(self.get_internal_reference())
		if self.is_custom:
			config_manager["BPBible"]["copy_verse"] = (
				self.based_on, 
				dict(
					header=self.template_panel.header.GetText(),
					body=self.template_panel.body.GetText(), 
					footer=self.template_panel.footer.GetText()
				), self.formatted
			)

		else:
			config_manager["BPBible"]["copy_verse"] = (
				self.gui_template_list.StringSelection
			), None, self.formatted

		self.Destroy()

	@property
	def formatted(self):
		return self.copy_formatted.IsChecked()
	
	def copy_verses(self, ref, dialog_hidden_mode=False):
		print "Updating...", ref
		text_to_copy = self.update(ref=ref, dialog_hidden_mode=dialog_hidden_mode)
		if self.formatted:
			self.preview.copyall()
		else:
			guiutil.copy(text_to_copy)

	def GetText(self, ref):
		print "Getting text for", ref
		template = VerseTemplate(header=self.template_panel.header.GetText(),
			body=self.template_panel.body.GetText(), 
			footer=self.template_panel.footer.GetText())

		#no footnotes
		biblemgr.temporary_state(biblemgr.plainstate)
		if display_options.options["colour_speakers"] == "woc_in_red":
			biblemgr.set_option("Words of Christ in Red", "On")

		#apply template
		biblemgr.bible.templatelist.append(template)
		biblemgr.parser_mode = COPY_VERSES_PARSER_MODE
		
		data = biblemgr.bible.GetReference(ref)
		if data is None:
			data = config.MODULE_MISSING_STRING()

		if self.formatted:
			# TODO: make it scan CSS and amalgamate rules?
			data = data.replace("<span class='WoC'>",
								"<span style='color: red'>")
			data = data.replace("<span class='divineName'>",
								"<span style='font-variant:small-caps'>")

			# Use the font that has been selected for the module.
			# XXX: We could still use language specific fonts for particular
			# sections of the text, but I'm not sure it's worth doing.
			# It would probably only apply to Hebrew and Greek (which we
			# treat specially) anyway.
			default, (font, size, in_gui) = fonts.get_module_font_params(biblemgr.bible.mod)
			data = u"<span style=\"font-family: %s; font-size: %spt;\">%s</span>" % (font, size, data)
		else:
			data = string_util.br2nl(data)
			data = string_util.KillTags(data)
			data = string_util.amps_to_unicode(data)

		#restore
		biblemgr.restore_state()
		biblemgr.bible.templatelist.pop()
		biblemgr.parser_mode = NORMAL_PARSER_MODE
		return data
 def __init__(self, interface_name):
     ProfiledWirelessInterface.__init__(self, interface_name)
     self.template_manager = TemplateManager()
     self.template_manager.load_all_available_templates()
class EncryptableWirelessInterface(ProfiledWirelessInterface):
    ''' Adds wpa_supplicant support to the wireless interface.'''
    def __init__(self, interface_name):
        ProfiledWirelessInterface.__init__(self, interface_name)
        self.template_manager = TemplateManager()
        self.template_manager.load_all_available_templates()