REBOL
I currently trying to redo a small app I made in Delphi.
This application displays a background image among n and a text among n, but I cannot change the image or the text, the change of image and text is done by the button >>.
This is the simplified code without the random part because I found out about it:
Rebol[
Title: "You have a message !"
Version: 1.0.0
Needs: [1.2.115]
]
the-imag1: load %"/C/MyFile/Cours CD/Affiche/Images/Vague9.jpg"
the-imag2: load %"/C/MyFile/Cours CD/Affiche/Images/Vague3.jpg"
the-image: the-imag1
text1: "Your banner text here"
view xx1: layout [
size the-image/size
b1: backdrop the-image
at b1/offset + 110x120
box 350x150 font-size 20 font-color black [align: 'center] text1
at b1/offset + 530x370
btn ">>" [the-image: the-imag2 ; new image
text1: "Hello" ; new text
show xx1] effect [multiply 90]
]
You are redefining the face, not just the content. Just redefine the field you need. Try this:
Rebol[
Title: "You have a message !"
Version: 1.0.0
Needs: [1.2.115]
]
the-imag1: load %"/C/MyFile/Cours CD/Affiche/Images/Vague9.jpg"
the-imag2: load %"/C/MyFile/Cours CD/Affiche/Images/Vague3.jpg"
the-image: the-imag1
text1: "Your banner text here"
view xx1: layout [
size the-image/size
b1: backdrop the-image
at b1/offset + 110x120
t1: text text1
at b1/offset + 530x370
btn ">>" [
b1/image: the-imag2 ; new image
t1/text: "Hello" ; new text
show xx1
] effect [multiply 90]
]
Related
Drag a corner of an image in DM triggers the image content refreshed to the new window size. What is the DM script command to trigger that refreshing?
Specifically, I want to add a text below the image. So, I get the imageDocument as root component, add a text annotation below the image (the vertical position of the text is beyond the bottom border of the image). Without "imgDoc.ImageDocumentSwitchToPageMode()", the text is not visible. When I change the image size with mouse, the image content is updated and the text is shown. Looking for script doing that.
Thanks,
The command you're seeking is void ImageDocumentOptimizeWindow( ImageDocument imgDoc )
but there is a bit more to the story:
You can add annotations (which really are Components ) to any other Component. An ImageDisplay is also a specialization of a Component. Thus, you may either add text as an annotation on an ImageDisplay - or on an ImageDocument.
If the first, then the text will move & resize when you move/resize the ImageDisplay, but if you add it to the ImageDocument's root component, it is "side-ordered" to and independent of the ImageDisplay on the page.
Here is a code example for either:
image test := RealImage("Test",4,512,512)
test=icol
test.ShowImage()
imageDisplay disp = test.ImageGetImageDisplay(0)
imageDocument doc = test.ImageGetOrCreateImageDocument()
If ( TwoButtonDialog("Add as part of Image or Page?","Image","Page") )
{
component text1 = NewTextAnnotation( 10, 550, "Under image as part of ImageDisplay", 20)
disp.ComponentAddChildAtEnd(text1)
doc.ImageDocumentOptimizeWindow()
}
else
{
component text2 = NewTextAnnotation( 10, 550, "Under image as part of ImageDocument", 20)
doc.ImageDocumentEnsurePlacedOnPage()
doc.ImageDocumentSwitchToPageMode()
doc.ImageDocumentGetRootComponent().ComponentAddChildAtEnd(text2)
}
To better understand the structure of things, you may want to run a script like the following on an ImageDocument:
void RecursiveListChildren( component parent, string preFix )
{
number numChild = parent.ComponentCountChildren()
Result("\n"+preFix+" [Type "+parent.ComponentGetType()+"]")
for( Number i =0; i<numChild; i++ )
RecursiveListChildren( parent.ComponentGetChild(i), prefix + "..." )
}
component root = GetFrontImageDocument().ImageDocumentGetRootComponent()
ClearResults()
RecursiveListChildren(root,".")
For the two documents of the first script, this will give you:
. [Type 24]
.... [Type 20]
....... [Type 13]
and
. [Type 24]
.... [Type 20]
.... [Type 13]
For new GMS 2.x or higher, the answer is void ImageDocumentOptimizeWindow( ImageDocument imgDoc ). Not tested.
For older GMS, a generic solution is like this,
void resetImageDisplay(image img) {
imageDisplay imgDsp=img.ImageGetImageDisplay(0)
imageDocument imgDoc = img.ImageGetOrCreateImageDocument()
imgDoc.ImageDocumentSwitchToPageMode()
imgDoc.ImageDocumentSwitchToImageMode(imgDsp)
}
void main() {
image img:=exprSize(512,512, random())
img.showImage()
imageDisplay imgDsp=img.ImageGetImageDisplay(0)
component comp1=imgDsp.NewTextAnnotation(200, 540, "text 1", 14)
component comp2=imgDsp.NewTextAnnotation(200, 560, "text 2", 18)
comp1.ComponentSetForegroundColor(0,0,0)
comp2.ComponentSetForegroundColor(0,0,0)
imgDsp.ComponentAddChildAtEnd(comp1)
imgDsp.ComponentAddChildAtEnd(comp2)
img.resetImageDisplay()
//img.setWindowSize(1024,1024)
}
main()
I finally got my html2pdf to work showing my web page just how I want it in the pdf(Any other size was not showing right so I kept adjusting the format size until it all fit properly), and the end result is exactly what I want it to look like... EXCEPT even though my aspect ratio is correct for a landscape, it is still using a very large image and the pdf is not standard letter size (Or a4 for that matter), it is the size I set. This makes for a larger pdf than necessary and does not print well unless we adjust it for the printer. I basically want this exact image just converted to a a4 or letter size to make a smaller pdf. If I don't use the size I set though things are cut off.
Anyway to take this pdf that is generated and resize to be an a4 size(Still fitting the image on it). Everything I try is not working, and I feel like I am missing something simple.
const el = document.getElementById("test);
var opt = {
margin: [10, 10, 10, 10],
filename: label,
image: { type: "jpeg", quality: 0.98 },
//pagebreak: { mode: ["avoid-all", "css"], after: ".newPage" },
pagebreak: {
mode: ["css"],
avoid: ["tr"],
// mode: ["legacy"],
after: ".newPage",
before: ".newPrior"
},
/*pagebreak: {
before: ".newPage",
avoid: ["h2", "tr", "h3", "h4", ".field"]
},*/
html2canvas: {
scale: 2,
logging: true,
dpi: 192,
letterRendering: true
},
jsPDF: {
unit: "mm",
format: [463, 600],
orientation: "landscape"
}
};
var doc = html2pdf()
.from(el)
.set(opt)
.toContainer()
.toCanvas()
.toImg()
.toPdf()
.save()
I have been struggling with this a lot as well. In the end I was able to resolve the issue for me. What did the trick for me was setting the width-property in html2canvas. My application has a fixed width, and setting the width of html2canvas to the width of my application, scaled the PDF to fit on an A4 paper.
html2canvas: { width: element_width},
Try adding the above option to see if it works. Try to find out the width of your print area in pixels and replace element_width with that width.
For completeness: I am using Plotly Dash to create web user interfaces. On my interface I include a button that when clicked generates a PDF report of my dashboard. Below I added the code that I used for this, in case anybody is looking for a Dash solution. To get this working in Dash, download html2pdf.bundlemin.js and copy it to the assets/ folder. The PDF file will be downloaded to the browsers default downloads folder (it might give a download prompt, however that wasn't how it worked for me).
from dash import html, clientside_callback
import dash_bootstrap_components as dbc
# Define your Dash app in the regular way
# In the layout define a component that will trigger the download of the
# PDF report. In this example a button will be responsible.
app.layout = html.Div(
id='main_container',
children = [
dbc.Button(
id='button_download_report',
children='Download PDF report',
className='me-1')
])
# Clientside callbacks allow you to directly insert Javascript code in your
# dashboards. There are also other ways, like including your own js files
# in the assets/ directory.
clientside_callback(
'''
function (button_clicked) {
if (button_clicked > 0) {
// Get the element that you want to print. In this example the
// whole dashboard is printed
var element = document.getElementById("main_container")
// create a date-time string to use for the filename
const d = new Date();
var month = (d.getMonth() + 1).toString()
if (month.length == 1) {
month = "0" + month
}
let text = d.getFullYear().toString() + month + d.getDay() + '-' + d.getHours() + d.getMinutes();
// Set the options to be used when printing the PDF
var main_container_width = element.style.width;
var opt = {
margin: 10,
filename: text + '_my-dashboard.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 3, width: main_container_width, dpi: 300 },
jsPDF: { unit: 'mm', format: 'A4', orientation: 'p' },
// Set pagebreaks if you like. It didn't work out well for me.
// pagebreak: { mode: ['avoid-all'] }
};
// Execute the save command.
html2pdf().from(element).set(opt).save();
}
}
''',
Output(component_id='button_download_report', component_property='n_clicks'),
Input(component_id='button_download_report', component_property='n_clicks')
)
I am trying following code where user enters 2 numbers and on clicking calculate button, answer should be shown. There are also buttons for clearing fields and for exiting.
REBOL[]
fields: [f-ht f-wt ans]
reset-fields: does [
unfocus
f-ht/text: " " ; Changing this to "ENTER NUMBER HERE" does not help
f-wt/text: " "
focus f-ht
]
oncalc: does [
ans/text: (to integer! f-wt/text) / ((100 * to integer! f-ht/text) * (100 * to integer! f-ht/text))
show fields
]
lo: layout [
style tx label 200x24 center
style fld field 200x24 center
style btn button 200x24 center
tx "First Number:"
f-ht: fld
tx "Second Number:"
f-wt: fld
btn "Calculate" [oncalc]
ans: tx "Answer"
btn "Clear" [reset-fields show fields] ; NOT WORKING- NOTHING HAPPENS
btn "Exit" escape [unview/only lo]
]
reset-fields
view center-face lo
The GUI is showing all right. However, there are following problems:
On clear button clicking, nothing is happening.
There are no changes on GUI and no errors are being reported. Where is the problem and how can this be solved? Thanks for your help.
Clear the fields instead of setting to new strings
reset-fields: does [
unfocus
clear f-ht/text
clear f-wt/text
focus f-ht
]
I tried to implement a save-as-ftp button in Rebol embedded editor. Implementation of the save-as-button is this:
save-as-ftp: has [file-content][
file-content: t1/text
prefs-file: rejoin [_self-path %ftp.preferences.txt]
either exists? prefs-file [
prefs-ftp: construct load prefs-file; see article application configuration file
user: prefs-ftp/user
password: prefs-ftp/password
server-path: prefs-ftp/server-path
][
user: ask "User: "
password: ask/hide "Password: "
server-path: ask "Server-Path: "
]
view ftp-view: layout [
origin 10x10 space 8x4
style btn btn 140
ftp-field: text bold "" 140 center
pad 0x4
btn-enter 140 "Save" #"s" [hide-popup result: ftp-field/text]
btn red + 50 "Quit - No Save" [hide-popup quit-now]
]
file-target: result
ftp-target: rejoin [ftp:// user ":" password "#" server-path file-target]
write ftp-target file-content
print ["uploaded" file-target "to" rejoin [ftp:// "XXXXXXX" ":" "XXXXXXX" "#" server-path]]
true
]
My problem is with view ftp-view : I cannot even type in ftp-field text box as the popup window loses focus.
hide-popup is used to close a modal window.
A modal window is opened by using 'inform
I don't see any modal windows here.
Oh .. this is a button or something that you are attaching to the rebol editor?
I modified mine some years ago to edit ftp files ... I'll have to see if I can find what I did.
download-dir: request-dir
Print ["downloading " "VStudio2008Express.iso" "..." ]
url: http://go.microsoft.com/fwlink/?LinkId=104679
file-save: to-rebol-file rejoin [download-dir "VStudio2008Express.iso"]
request-download/to url file-save
In the end whereas the progress bar has shown the download has finished:
** Script Error: Not enough memory
** Where: append
** Near: insert tail series :value
>>
So how to correct request-download as it is a mezzanine function:
func [
{Request a file download from the net. Show progress. Return none on error.}
url [url!]
/to "Specify local file target." local-file [file! none!]
/local prog lo stop data stat event-port event
][
view/new center-face lo: layout [
backeffect [gradient 1x1 water gray]
space 10x8
vh2 300 gold "Downloading File:"
vtext bold center 300 to-string url
prog: progress 300
across
btn 90 "Cancel" [stop: true]
stat: text 160x24 middle
]
stop: false
data: read-thru/to/progress/update url local-file func [total bytes] [
prog/data: bytes / (max 1 total)
stat/text: reform [bytes "bytes"]
show [prog stat]
not stop
]
unview/only lo
if not stop [data]
]
Rebol's read functions read all the input data into memory at once and cannot be used on large datasets. You have to open a port and copy the data from it in chunks to handle large datasets.
I would think that the request-download function could be modified to use ports for both the input and output data. This thread from the Rebol Mailing List may help you:
http://www.rebol.org/ml-display-thread.r?m=rmlFQXC
You can find a fuller example on Carl's blog at http://www.rebol.com/cgi-bin/blog.r?view=0281#comments
Even using this technique there is a limit of approximately 2Gb to the size of files that can be handled in Rebol 2.
Try this
http://anton.wildit.net.au/rebol/util/batch-download.r