How to use more than 1 Script in FPDF - fpdf

I'm using FPDF to render a document. I've downloaded 2 scripts from the website: "Force justification" and "EPS / AI support".
The problem is that when I use FPDF with the script "Forced Justification" everything works fine but when I add "EPS / AI support" I always get this message:
Fatal error: Cannot declare class FPDF, because the name is already in use in ...
Is it maybe because force_justify.php and fpdf_eps.php are not made to work together or there's a solution? These are the links:
FORCED JUSTIFICATION
EPS / AI support
Thanks for your help in advance.
Regards
----------------EDITED----------------------
I have adddata.php where I have this:
require('force_justify.php');
$pdf = new PDF();
$pdf->AddPage();
Then I have the 1st script force_justify.php with:
require('fpdf.php');
class PDF extends FPDF
{
And the 2nd script fpdf_eps.php with:
require('fpdf.php');
class PDF_EPS extends FPDF{
I try to follow the steps in the FAQ but I'm not sure how to do the last one:
and make your own class extend B:
require('b.php');
class PDF extends B
{
...
}
$pdf = new PDF();

------------------SOLUTION-------------------
I know it was easy but sometimes first times using specific tools are hard LOL. I found the solution:
I have adddata.php where I create the PDF, I called fpdf_eps.php(rather than force_justify.php)
require 'fpdf_eps.php';
$pdf = new PDF(); //(this was my mistake because I had to use the 2nd class which extends the 1st class which extends FPDF)
$pdf->AddPage();
Then I have the 1st script force_justify.php with:
require('fpdf.php');
class PDF extends FPDF
{
And the 2nd script fpdf_eps.php with require('force_justify.php'); (instead of fpdf.php)
require('force_justify.php');
class PDF_EPS extends PDF{
So fpdf_eps extends PDF (force_justify.php CLASS) which extends FPDF ...so I only had to use $pdf = new PDF_EPS(); in adddata.php to link those 2 scripts to the main one

Related

Odoo Modify or extend import process

I want modify or extend the process on csv import in Odoo.
I have some fields autocalculated and other needed but is not in the csv file.
Having search the code and try using ir.action.todo, and ir.action.client but dont work.
Any idea, using hooks, or other work?
Thanks
Yoinier.
You just need to inherit the 'base_import.import' model
class Import(models.TransientModel):
_inherit = 'base_import.import'
#api.model
def _convert_import_data(self, fields, options):
# Override base method
# Called when actual import start
data, import_fields = super(Import, self)._convert_import_data(fields, options)
# Do something ...
return data, import_fields
def parse_preview(self, options, count=10):
# Override base method
# Called when data loaded
preview_data = super(Import, self).parse_preview(options, count=count)
# Do something ...
return preview_data
but, override the base import method is probably not a good idea, I'd suggest to use custom import wizard to do your custom import.

Text widget is not accessible to a helper function in Python3x tkinter

I am learning python tkiner from a reference book. The examples are coded in plain style, i.e., not in class format. I want to learn coding in classes because I think it helps manage long codes.
I am trying to make the text widget (named textPad) accessible to a helper function inside a class called TextEditor. The job of the helper function is to select all the text which I type. However, as soon as I run the script, I get global error that the textPad is not defined. Even when I add self. to textPad, i.e., self.textPad, I get an attribute error that Class object has no attribute textPad. The code is part of an excercise to make a full functional text editor. Below, I provide the core code which generates the error. What is the wrong with this code?
Could you please clarify my doubts: where is the best place to define helper functions: inside class or outside class? In both cases, how to make them accessable?
from tkinter import *
class TextEditor():
def __init__(self, root):
self.select_all() #helper function declare
myMenu = Menu(root, tearoff=0) #Menu bar
editMenu = Menu(root, tearoff)
editMenu.add_command(label="Select All", accelerator="Ctrl+A", command=select_all)
myMenu.add_cascade(label="Edit", menu=editMenu)
root.config(menu=myMenu)
textPad = Text(root, wrap="word", undo=True)
textPad.pack(expand="yes", fill="both")
def select_all(self):
textPad.tag_add('sel', '1.0', 'end')
if __name__ == '__main__':
root=Tk()
app = TextEditor(root)
root.mainloop()
This is the error:
Traceback (most recent call last):
File "C:\Python33\gui\tkguibook\textpad.py", line 21, in <module>
app = TextEditor(root)
File "C:\Python33\gui\tkguibook\textpad.py", line 6, in __init__
self.select_all() #helper function declare
File "C:\Python33\gui\tkguibook\textpad.py", line 17, in select_all
textPad.tag_add('sel', '1.0', 'end')
NameError: global name 'textPad' is not defined
Thank you in advance for your kind help!
First of all, I advise you to watch some tutorials on object-oriented paradigm in Python without using tkinter directly.
The problem with your code is that textPad is not a property of the class, but it's a simple local variable to the __init__ method or constructor. To make it a property, you should use self to declare and then refer to the just declared property.
For example, suppose I have the following class:
class TextEditor:
def __init__(self):
# stuff
and you want to add a property, visible in all the points in your class, you can do it in this way:
class TextEditor:
def __init__(self):
self.textPad = tkinter.Text() # using 'self' to declare a property
now, if you want to refer to that property in another method, you should use always the self:
class TextEditor:
def __init__(self):
self.textPad = tkinter.Text()
def set_text(self, new_text):
self.textPad.insert(tkinter.END, "hello") # using 'self' to refer to the property
To know more about self.

TYPO3 Extension: Generate a PDF

Im trying to make an extension with Kickstarter that overrides the normal rendering of the page, and renders a PDF file. For this im using FPDF. But im not sure how to do it. I tried doing this, but it didnt work:
<?php
// require_once(PATH_tslib . 'class.tslib_pibase.php');
class tx_ishurkunde_pi1 extends tslib_pibase {
public $prefixId = 'tx_ishurkunde_pi1';
public $scriptRelPath = 'pi1/class.tx_ishurkunde_pi1.php';
public $extKey = 'ish_urkunde';
public $pi_checkCHash = TRUE;
public function main($content, array $conf) {
if (!t3lib_extMgm::isLoaded('fpdf')) return "Error!";
$pdf = new FPDF();
$pdf->AddPage();
$content = $pdf->Output('', 'S');
return $content;
}
}
?>
It still keeps rendering the normal web template. What am I missing?
FYI, Im not trying to render the HTML as PDF. Im trying to generate a PDF from scratch, using the URL parameters are text variables.
As far as I understood, your aim is to render a PDF instead of page elements.
Your current approach will not work since you are inserting a plugin onto the page. The plugin's return value is then given back to the TYPO3 content parser, and if the page has finished parsing, it is displayed. There is no part in it where you can throw over the whole page rendering; At least it is not intended to do, and you shouldn't to (albeit there are extensions that do this).
The eID approach would be to either create an eID script (have a look at dd_googlesitemap) which is called via GET param and renders only what you need. There you basically can do everything you want to.
In your extension's ext_localconf.php you register the eID script, like this:
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$_EXTKEY] = "EXT:{$_EXTKEY}/path/to/my/EIDHandler.php";
An Example eID handler structure:
class Tx_MyExt_EIDHandler
{
public function main()
{
// Your code here
}
}
$output = t3lib_div::makeInstance('Tx_MyExt_EIDHandler');
$output->main();
To call your eID script in the frontend, you append the appropriate GET params, like http://example.com/index.php?eID=tx_myext. This is the array key you defined in your ext_localconf.php (in my example, it is $_EXTKEY, but it can basically be any string).
The plugin/typoscript approach would be like e.g. TemplaVoila does it: You create a PAGE type and call a user_func which does your things. This would be the fastest approach because you already have a plugin. Important is that you render your own page type with only your plugin in it.
Example TypoScript:
specialPage = PAGE
specialPage {
type = 2
10 = USER
10.userFunc = tx_myextension_pi1->myFunc
}
After that, you can call your new page with http://example.com/index.php?type=2. However, headers etc are still rendered and you may need to remove them.

Silverstripe 3 doPublish in Controller

in an old silverstripe installation (2.4) i had a little counter function that looks basically like this:
class Page_Controller extends ContentController {
public function countUp(){
$this->Counter = $this->Counter+1;
$this->writeToStage('Stage');
$this->publish("Stage", "Live");
}
}
I want to move that over to SS 3.
Somehow it does not work anymore, the Counter Property is never updated in the Datebase.
Does someone know why?
Kind regards,
Florian
1 - That method should be on the Page class (model), not the controller. You can then call $this->data()->countUp(); from the Page_Controller class.
2 - You need the line $this->write(); before $this->writeToStage('Stage');

Django-Nonrel with Mongodb listfield

I am trying to implement manytomany field relation in django-nonrel on mongodb. It was suggessted at to:
Django-nonrel form field for ListField
Following the accepted answer
models.py
class MyClass(models.Model):
field = ListField(models.ForeignKey(AnotherClass))
i am not sure where the following goes, it has been tested in fields.py, widgets,py, models.py
class ModelListField(ListField):
def formfield(self, **kwargs):
return FormListField(**kwargs)
class ListFieldWidget(SelectMultiple):
pass
class FormListField(MultipleChoiceField):
"""
This is a custom form field that can display a ModelListField as a Multiple Select GUI element.
"""
widget = ListFieldWidget
def clean(self, value):
#TODO: clean your data in whatever way is correct in your case and return cleaned data instead of just the value
return value
admin.py
class MyClassAdmin(admin.ModelAdmin):
form = MyClassForm
def __init__(self, model, admin_site):
super(MyClassAdmin,self).__init__(model, admin_site)
admin.site.register(MyClass, MyClassAdmin)
The following Errors keep popping up:
If the middle custom class code is used in models.py
name 'SelectMultiple' is not defined
If custom class code is taken off models.py:
No form field implemented for <class 'djangotoolbox.fields.ListField'>
You just need to import SelectMultiple by the sound of it. You can put the code in any of those three files, fields.py would make sense.
Since it's pretty usual to have:
from django import forms
at the top of your file already, you probably just want to edit the code below to:
# you'll have to work out how to import the Mongo ListField for yourself :)
class ModelListField(ListField):
def formfield(self, **kwargs):
return FormListField(**kwargs)
class ListFieldWidget(forms.SelectMultiple):
pass
class FormListField(forms.MultipleChoiceField):
"""
This is a custom form field that can display a ModelListField as a Multiple Select GUI element.
"""
widget = ListFieldWidget
def clean(self, value):
#TODO: clean your data in whatever way is correct in your case and return cleaned data instead of just the value
return value
You probably also want to try and learn a bit more about how python works, how to import modules etc.