How can I read and set the paper style (aka papername) in Firemonkey MacOS - macos

Working in Delphi Firemonkey for Mac OS64.
Trying to read and then set the variable Apple calls the "paperName", which is the paper type (letter, legal, envelope, etc.) I know that it is accessed through NSPrinter.PaperName? but I do not understand how to code FMX to access it.
I'm using cookbooked code to get the paper rectangle:
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMGetAdjustedPaperRect(FPrintInfo.PMPageFormat, #PaperRect);
FPrintInfo.release;
but I'm not experienced at all with Mac code so my attempts to plug-and-play off of this code to get papername have not been successful.
Thanks for your help.
Dave,
Thanks. Sorry, I didn't really give you enough info. The code I provided does work, to get the paper rectangle.
What I am trying to get, in addition, is the paper name, and I can't figure out what function will get me that.
I'm trying to use PMGetPageFormatPaper(FPrintInfo.PMPageFormat, #PaperTypeS); but I think I may not be declaring PaperTypeS correctly.
What I'm trying is:
function getPaperShape: string;
var
FPrintInfo: NSPrintInfo;
PaperRect: PMRect;
paperwidth,paperheight:double;
paperTypeS:string;
begin
FPrintInfo := TNSPrintInfo.Wrap(TNSPrintInfo.OCClass.sharedPrintInfo);
FPrintInfo.retain;
PMGetAdjustedPaperRect(FPrintInfo.PMPageFormat, #PaperRect);
PMGetPageFormatPaper(FPrintInfo.PMPageFormat, #PaperTypeS);
FPrintInfo.release;
paperwidth:= PaperRect.right-PaperRect.left;
paperheight:= PaperRect.bottom-PaperRect.top;
end;
That clearly is not correct, since I get nothing returned in paperTypeS. I've tried declaring paperTypeS as NSPrinter.PaperName, or just as PaperName, or as PMPaperName, but clearly I'm just guessing here and none of those are recognized by FMX as valid types.
Does that make more sense?
Again, thanks.
Scott

Related

AHK: Using RandomBezier Function

I'm trying to use RandomBezier.ahk (https://github.com/MasterFocus/AutoHotkey/tree/master/Functions/RandomBezier) to randomize the mouse path to click on things in game.
The Example.ahk in that github works for me, but when trying to use it in my own program, it doesn't work when calling the RandomBezier function.
I have the files in the same local directory.
Any help on getting this function to work?
Thanks
#SingleInstance force
#Include RandomBezier.ahk
^j::
screenWidth := A_ScreenWidth
screenHeight := A_ScreenHeight
//I'm using ratios so that I'm not hardcoding based on a given display resolution
Play_X := floor(0.02604*A_ScreenWidth)
Play_Y := floor(0.37037*A_ScreenHeight)
RandomBezier(0, 0, %Play_X%, %Play_Y%, "T1200 RO RD OT100 OB-100 OL0 OR0 P4-3") //<-- this line doesn't do anything. the mouse doesn't move.
;MouseMove, %Play_X%, %Play_Y%, 10 <--this line works, so I know that the variables Play_X, Play_Y works
Sleep 50
Click
This is a classic mistake of trying to use legacy syntax in a place where it doesn't belong (though I'd argue it no longer belongs anywhere whatsoever).
Function parameters are passed in as expressions, not as legacy text parameters.
So instead of legacy way of referencing a variable
RandomBezier(0, 0, %Play_X%, %Play_Y%,,
you do
RandomBezier(0, 0, Play_X, Play_Y,.
Overall I'd recommend you to try to to get rid of legacy syntax. It's not 2008 anymore.
Reading this page on the documentation is a good start to learning the difference
https://www.autohotkey.com/docs/Language.htm

Change the way an object is displayed in debugger/inspector variable-value table

I would like to know if there is a message I can override in Pharo so that my custom classes display more descriptive information in the inspector/debuger much like simple variable types do, like Integers or Strings. For instance:
Instead of that, I would like it to show a more custom and informative description consisting of its internal variales so as to have a tighter/tidier view of the variables instead of having to click on it and open another chart (therefore losing sight of the information on the previous chart). I know you can increase the amount of charts shown below, but that is not the point of the question. I would like to achieve something like this:
I have browsed the pharo forums and found nothing, I have also tried overriding over 30 methods hoping that one of them changed the output. Only the class message seemed to change the output, but I could only return an instance of Metaclass and besides messing with this message would break a lot of stuff. Finally I tried to reverse engineer the debugger and then the inspector to see at which point is the table constructed and what values are used or which messages are sent to build said values, but it was just too much for me, the callstack kept growing and I couldn't even scratch the surface.
Luckily, doing this in any Smalltalk is very easy. Types inherited from Object are expected to answer to the message printString, and ultimately printOn: aStream. Those messages are expected to give a description of the object. So, you should just override printOn: in your class (printString uses printOn:) and all the browsers and inspectors will automatically use it. There other possibilities in Pharo, if you want to provide more complex information in different tabs, but I think printOn: will suffice for you.
An example would be:
MyPoint>>printOn: aStream
aStream nextPut: ${.
x printOn: aStream.
aStream nextPutAll: ', '
y printOn: aStream.
aStream nextPut: $}
In Smalltalk, every time you observe something you don't like or understand, you ask the question: Which message is doing this?
In your case, the question would be: Which message creates the string a MyPoint that I see everywhere?
Next, to answer your question you need to find a good place for inserting a halt and then debug from there until you find the culprit. To do this just find the simplest expression that would reproduce the issue and debug it. In your case the right-click command in the Playground will do. So,
Write and select (MyPoint on: 14 and: -5) halt in a Playground.
Right-click and issue the Print it command (I'm assuming you already checked that this command produces the string 'a MyPoint').
Debug
Go over the evaluation of #DoIt, which answers the result
Continue this way alternating between Into and Over to make sure you follow the result to where it's being taken
Eventually you will reach the implementation of Object >> #printString. Bingo!
Now you can open a System Browser and take a look at this method, study how it's been implemented in different classes, etc. Your investigation should show you that the most basic message for printing is #printOn:. You may also want to take a look at other implementors so to better understand what people usually do. (Bear in mind that writing good #printOn:s is a minimalist art)
Overriding printOn: will work for simple cases where you want to just change description.
Pharo allows a lot more than that!
Due the extensible (moldable) nature of our inspector, you do not need to override a method to get your own visualisation of the object.
For example, look this array visualisation:
This is obtained adding this method to Collection:
gtInspectorItemsIn: composite
<gtInspectorPresentationOrder: 0>
^ composite fastList
title: 'Items';
display: [ self asOrderedCollection ];
beMultiple;
format: [ :each | GTObjectPrinter asTruncatedTextFrom: each ];
send: [ :result |
result
ifNil: [ nil ]
ifNotNil: [ result size = 1
ifTrue: [ result anyOne ]
ifFalse: [ self species withAll: result ]
]
]
if you browse for senders of gtInspectorPresentationOrder: you will see there are already a lot of special visualisations in the image.
You can take those as an example on how to create your own, adapted exactly to what you need :)

VBScript - RANDOMIZE (Cbyte(Left(Right(Time(),5),2))) throws 500 for ES locales

Using a standard VBScript Randomize statement (below) which works fine -- most of the time.
...RANDOMIZE (Cbyte(Left(Right(Time(),5),2)))
RANDOMIZE...
It took a bit, but in digging thru log files, I've noticed that it throws this 500 error:
Type mismatch: 'Cbyte'
when the users' languages are non-English.
I tried changing the Session.LCID (I'm using Classic ASP) in a test page but no effect.
Any suggestions for fixing or a work-around? Thank you...
It appears you're trying to randomise based on the seconds-within-the-minute value:
12:34:56 AM
|---|
56 AM (right(5))
||
56 (left(2))
Now I have no idea of the top of my head what Time() would return in a Spanish locale, but it may well be something like 12:34:56 de la mañana.
What I do know is that relying on a specific presentation format in a globalised world is a bad idea. In your case, it may involve trying to convert left(right("12:34:56 de la mañana",5),2), or "añ", into a numeric value, something it's not going to be happy with.
If you want a true root cause analysis, I'd suggest catching the conversion error and actually logging what Time() is presenting itself as when it errors.
If you just want to fix it, find a way to get the seconds that doesn't depend on locale, for example:
secs = Second(Time())
As an aside, I'm not sure why you think this is even needed. The documentation for the VBScript Randomise function states that, if an argument is not given, the value returned by the system timer is used as the new seed value. Hence it's already based on the current time.

Generate code in code_128 format from another code

I have a list of the following codes and their corresponding codes in format code_128. I want to given a string, be able to generate the corresponging code in CODE_128 format. Based on this list, how could I generate a code_128 number to the string A4Y9387VY34, for example?
code code in code_128
A4Y9387VY34 ????
ADN38Y644YT7 9611019020018632869509
AXCW99QYTD34 9622019021500078083444
A9YQC44W9J3K 9611083009710754539701
AT8V7T3G3874 9622083021255845940154
A7K444N4FKB8 9622083033510467186874
AYCHFW448HTQ 9611005019246067403120
AY63CWBMTDCC 9622005028182439033426
ANY7TF46NGQ3 9622005031345848081170
AYY48TBVQ3FH 9611200003793988696055
AT8Q4CF4DQ9Q 9611200021606968867090
A764WYQFJWTT 9622200022706968919275
AC649ND7N8B6 9622148007265209832185
A4VDPTJ99YN4 9611148013412173923039
AHDYK498BD6T 9622148021309216149530
A4YYYNY7C3DJ 9611017021934363499071
AYG6XWVCCQ89 9622017031009914238743
A68YJHGQKCCM 9622017031138587166053
APMB7XG9XQC9 9611021011608391750002
AGP8C44Y8VYK 9622021021608111646113
A7C68B9T69XB 9622021021958603678086
AJYYWKR6BDGN 9611010022528724015883
AKMNVXDT9PYN 9622010027475034102229
AXPXMK9QMDFD 9622010031475028243694
I read a lot about it, but I didn't come to any solution. Thanks in advance!!
Well, this is a pretty open question, I will give you my suggestions:
If it is a finite list, you can use a Hash or a Dictionary, where
the keys are the Codes and map them to the corresponding value, in
your case, Code_128
Some scanners have software installed that allow you to change what
has been read to a new value, format it, etc.
If you need a bigger insight please, give us more detail about the environment you are using.
Hope that helps,
I decided to create a new answer because now I get your point. Well, if you are talking about a GS1-128 Code (please see www.gs1.org) please do not start without visiting Wikipedia info about it. as you can see, there is a thorough explanation about how to work with that type of code. That code is composed by several application identifiers followed by their corresponding values. There is a better way of encoding them by using special characters as parenthesis. Here is other info that may help you.
Hope it helps,

Mac Printing : programatically can not set printQuality, mediaType, paperSource, outputBin

I have a Mac application that supports customising field values programatically for Print dialog. However, I could not find any API in Mac (Cocoa/Carbon) to set the values for:
printQuality (Best/Normal/Low/Draft),
mediaType(Standard/Glossy/Transparent),
paperSource or PaperFeed(Auto/Manual/Casette/Env) and
outputBin(Auto/Bin1/Bin2).
Though I find constants for these fields as:
PMQuality, PMPaperType, PMPaperSource, PMPSTraySwitch
I am not successful in using them to set the values to printer. I couldn't find which object/dictionary/array can contain these keys to be effective.
Can anyone help me?
Basically u mihgt have to redraw another pdf. have a look at this code. this should help
http://svn.r-project.org/R/trunk/src/library/grDevices/src/qdCocoa.m

Resources