Pharo Smalltalk: How to create an input field using TextMorph and then get the data off the input field? - textbox

I am completely new to Pharo, Smalltalk. I'm developing a small app that will convert temperature from Fahrenheit to Celsius. Can anyone give me any idea on how to create an input field using TextMorph and display it on a window as shown in the screen shot. In addition, being able to get the data back from the input field when the button is clicked. The below code is what I have done so far.
Screenshot
The class TemperatureMorph
BorderedMorph subclass: #TemperatureMorph
instanceVariableNames: 'tempInputField counter'
classVariableNames: ''
package: 'Assignment'
The initialize method: Contains a label, textbox and a button.
initialize
| headingLabel converterButton|
super initialize.
self bounds: (0#0 corner:300#300).
self color: Color gray.
headingLabel := StringMorph contents: 'Converter'.
headingLabel position: 130#20.
self addMorph: headingLabel.
tempInputField := TextMorph new.
tempInputField position: 50#50.
self addMorph: tempInputField.
Thanks

On a side not, if you're doing UI stuff in Pharo for anything other than learning (It looks like OP /is/ learning, so this probably doesn't apply). You should be looking at either Glamour or Spec. Both of which have really easy text input and control systems.
Spec
Glamour

You can already see the necessary code in your screenshot, you only have to replace the construction of a StringMorph with that of a TextMorph. I suggest you take a look at the Pharo by Example book. It has a chapter on Morphic, which is the UI framework in Pharo.
yourTextMorph := TextMorph new.
yourTextMorph contents: 'initial text'.
ownerMorph addMorph: yourTextMorph.
I guess you will also want to read the contents back out of the TextMorph. You can use yourTextMorph contents to achieve that. See also Pharo Smalltalk: Reading from TextMorph

Related

Printing an image to a dye based application

I am learning about fluid dynamics (and Haxe) and have come across this awesome project and thought I would try to extend to it to help me learn. A demo of the original project in action can be seen here.
So far, I have created a side menu of items containing different shapes. When the user clicks on one of the shapes, then, clicks onto the canvas, the image selected should be imprinted onto the dye. The user will then move the mouse and explore the art etc.
To try and achieve this I did the following:
import js.html.webgl.RenderingContext;
function imageSelection(): Void{
document.querySelector('.myscrollbar1').addEventListener('click', function() {
// twilight image clicked
closeNav();
reset();
var image:js.html.ImageElement = cast document.querySelector('img[src="images/twilight.jpg"]');
gl.current_context.texSubImage2D(cast fluid.dyeRenderTarget.writeToTexture, 0, Math.round(mouse.x), Math.round(mouse.y), RenderingContext.RGB, RenderingContext.UNSIGNED_BYTE, image);
TWILIGHT = true;
});
After this call, inside the update function, I have the following:
override function update( dt:Float ){
time = haxe.Timer.stamp() - initTime;
performanceMonitor.recordFrameTime(dt);
//Smaller number creates a bigger ripple, was 0.016
dt = 0.090;//#!
//Physics
//interaction
updateDyeShader.isMouseDown.set(isMouseDown && lastMousePointKnown);
mouseForceShader.isMouseDown.set(isMouseDown && lastMousePointKnown);
//step physics
fluid.step(dt);
particles.flowVelocityField = fluid.velocityRenderTarget.readFromTexture;
if(renderParticlesEnabled){
particles.step(dt);
}
//Below handles the cycling of colours once the mouse is moved and then the image should be disrupted into the set dye colours.
}
However, although the project builds, I can't seem to get the image imprinted onto the canvas. I have checked the console log and I can see the following error:
WebGL: INVALID_ENUM: texSubImage2D: invalid texture target
Is it safe to assume that my cast for the first param is not allowed?
I have read that the texture target is the first parameter and INVALID_ENUM in particular means that one of the gl.XXX parameters are just flat out wrong for that particular function.
Looking through to the file writeToTexture is declared as so: public var writeToTexture (default, null):GLTexture;. WriteToTexture is a wrapper around a regular webgl handle.
I am using Haxe version 3.2.1 and using Snow to build the project. WriteToTexture is defined inside HaxeToolkit\haxe\lib\gltoolbox\git\gltoolbox\render
writeToTexture in gltoolbox is a GLTexture. With snow and snow_web, this is defined in snow.modules.opengl.GL as:
typedef GLTexture = js.html.webgl.Texture;
So we're simply dealing with a js.html.webgl.Texture here, or WebGLTexture in native JS.
Which means that yes, this is definitely not a valid value for texSubImage2D()'s target, which is specified to take one of the gl.TEXTURE_* constants.
A GLenum specifying the binding point (target) of the active texture.
From this description it's obvious that the parameter isn't actually for the texture itself - it merely gives some info on how the active texture should be used.
The question then becomes how the "active" texture can be set. bindTexture() can be used for this.

Possible to make a composite symbol?

When editing a vertex I would like to substitute the vertex symbol with SimpleMarkerSymbol and a TextSymbol but that appears to be impossible. Any suggestions on how I could do this? I want the appearance of dragging something like this (text + circle):
After taking some time to look at the API I've come to the conclusion it is impossible. Here is my workaround:
editor.on("vertex-move", args => {
let map = this.options.map;
let g = <Graphic>args.vertexinfo.graphic;
let startPoint = <Point>g.geometry;
let tx = args.transform;
let endPoint = map.toMap(map.toScreen(startPoint).offset(tx.dx, tx.dy));
// draw a 'cursor' as a hack to render text over the active vertex
if (!cursor) {
cursor = new Graphic(endPoint, new TextSymbol({text: "foo"}));
this.layer.add(cursor);
} else {
cursor.setGeometry(endPoint);
cursor.draw();
}
})
You could use a TextSymbol to create a point with font type having numbers inside the circle. Here is one place where you can find such font. http://www.fontspace.com/the-fontsite/combinumerals
Wont be exactly as shown in the image but close enough. Also some limitation it wont work with IE9 or lower (this is as per esri documentation, as I am using halo to get the white border).
Here is the working Jsbin : http://jsbin.com/hayirebiga/edit?html,output use point of multipoint
PS: I have converted the ttf to otf and then added the font as base64, which is optional. I did it as I could not add the ttf or otf to jsbin.
Well, Achieve this seems impossible so far however ArcGIS JS API provides a new Application/platform where you can generate single symbol online for your applications.
We can simply create all kind of symbols(Provide by ESRI) online and it gives you on the fly code which you just need to paste in your application.
This will help us to try different type of suitable symbols for the applications.
Application URL: https://developers.arcgis.com/javascript/3/samples/playground/index.html
Hoping this will help you :)

How to create a Chat callout in delphi

I would like to create a chat ballon just like messengers does via FireMonkey TCalloutPanel , so how could I do that by giving it a text as a parameter then get the callout resized according to the text given ^^
Thanks in advance
I wrote this up quickly. Can use this as an example to work from to meet your specific needs/wants. Also, I would highly suggest going to the custom styling route as this way, adding TControls to the TListBoxItem ( although works ) makes the TListbox scrolling horrible.
procedure TForm1.LoadMessage(SelfSent:Boolean;msg:String;var LItem:TListBoxItem);
var
panel:Tcalloutpanel;
memo:TMemo;
begin
panel:=TCalloutPanel.Create(LItem);
panel.Parent:=LItem;
panel.Align:=TAlignLayout.Client;
panel.Margins.Left:=5;
panel.Margins.Right:=5;
panel.Margins.Top:=5;
panel.Margins.Bottom:=5;
if selfSent=true then
panel.CalloutPosition:=TCalloutPosition.right
else
panel.CalloutPosition:=TCalloutPosition.Left;
panel.CalloutOffset:=10;
memo:=TMemo.Create(panel);
memo.Parent:=panel;
memo.Align:=TAlignLayout.Contents;
memo.Margins.Left:=15;
memo.Margins.Right:=15;
memo.Margins.Top:=5;
memo.Margins.Bottom:=5;
memo.HitTest:=false;
memo.Text:=msg;
LItem.Height:=memo.ContentBounds.Height+30;
if LItem.Height<60 then
LItem.Height:=70;
end;

Inserting CrossReference to word via Delphi XE5

Bonjour, Hello,
I'm making this delphi application that I use to create word documents. I'm done with basic word operations (create/save, text, tables..etc).
What I need to do is to insert Page Numbers of headings as Cross Reference in the text. Something like :
"... and the process works as explained on page 23..."
where page number is a hyperlink to a heading. When I recorded a Macros in word it looks like:
Selection.InsertCrossReference ReferenceType:="Heading", _
ReferenceKind:=wdPageNumber, ReferenceItem:="49", InsertAsHyperlink:=True _
, IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
What would be the equivalent in Delphi please?
Thanks in advance!
Arjun.
Even when you're using Late Binding you still need to provide all of the parameters in the same order as the original declaration.
expression.InsertCrossReference(ReferenceType, ReferenceKind, ReferenceItem,
InsertAsHyperlink, IncludePosition, SeparateNumbers, SeparatorString)
If you aren't using a parameter then you can replace it with EmptyParam.
So I think your code will be:
Selection.InsertCrossReference('Heading', 7, '49', True, False, False, ' ');
(I think that wdPageNumber's value is 7).

Best way of storing an "array of records" at design-time

I have a set of data that I need to store at design-time to construct the contents of a group of components at run-time.
Something like this:
type
TVulnerabilityData = record
Vulnerability: TVulnerability;
Name: string;
Description: string;
ErrorMessage: string;
end;
What's the best way of storing this data at design-time for later retrieval at run-time? I'll have about 20 records for which I know all the contents of each "record" but I'm stuck on what's the best way of storing the data.
The only semi-elegant idea I've come up with is "construct" each record on the unit's initialization like this:
var
VulnerabilityData: array[Low(TVulnerability)..High(TVulnerability)] of TVulnerabilityData;
....
initialization
VulnerabilityData[0].Vulnerability := vVulnerability1;
VulnerabilityData[0].Name := 'Name of Vulnerability1';
VulnerabilityData[0].Description := 'Description of Vulnerability1';
VulnerabilityData[0].ErrorMessage := 'Error Message of Vulnerability1';
VulnerabilityData[1]......
.....
VulnerabilityData[20]......
Is there a better and/or more elegant solution than this?
Thanks for reading and for any insights you might provide.
You can also declare your array as consts and initialize it...
const
VulnerabilityData: array[Low(TVulnerability)..High(TVulnerability)] of TVulnerabilityData =
(
(Vulnerability : vVulnerability1; Name : Name1; Description : Description1; ErrorMessage : ErrorMessage1),
(Vulnerability : vVulnerability2; Name : Name2; Description : Description2; ErrorMessage : ErrorMessage2),
[...]
(Vulnerability : vVulnerabilityX; Name : NameX; Description : DescriptionX; ErrorMessage : ErrorMessageX)
)
);
I don't have an IDE on this computer to double check the syntax... might be a comma or two missing. But this is how you should do it I think.
not an answer but may be a clue: design-time controls can have images and other binary data associated with it, why not write your data to a resource file and read from there? iterating of course, to make it simpler, extensible and more elegant
The typical way would be a file, either properties style (a=b\n on each line) cdf, xml, yaml (preferred if you have a parser for it) or a database.
If you must specify it in code as in your example, you should start by putting it in something you can parse into a simple format then iterate over it. For instance, in Java I'd instantiate an array:
String[] vals=new String[]{
"Name of Vulnerability1", "Description of Vulnerability1", "Error Message of Vulnerability1",
"Name of Vulnerability2", ...
}
This puts all your data into one place and the loop that reads it can easily be changed to read it from a file.
I use this pattern all the time to create menus and for other string-intensive initialization.
Don't forget that you can throw some logic in there too! For instance, with menus I will sometimes create them using data like this:
"^File", "Open", "Close", "^Edit", "Copy", "Paste"
As I'm reading this in I scan for the ^ which tells the code to make this entry a top level item. I also use "+Item" to create a sub-group and "-Item" to go back up to the previous group.
Since you are completely specifying the format you can add power later. For instance, if you coded menus using the above system, you might decide at first that you could use the first letter of each item as an accelerator key. Later you find out that File/Close conflicts with another "C" item, you can just change the protocol to allow "Close*e" to specify that E should be the accelerator. You could even include ctrl-x with a different character. (If you do shorthand data entry tricks like this, document it with comments!)
Don't be afraid to write little tools like this, in the long run they will help you immensely, and I can turn out a parser like this and copy/paste the values into my code faster than you can mold a text file to fit your example.

Resources