What is the code for each click on a button makes the image 2 times smaller in livecode? - livecode

I need an easy code for a push button that makes an image 2 times smaller with each click in livecode
the image is 300 width 300 height

Lets say the name of your image is myImage
set the width of image "myImage" to the width of image "myImage" /2
set the height of image "myImage" to the height of image "myImage" /2

Here is one way you could do it. Create a custom command handler in your card or stack script:
command resizeImage pImgName, pResizeFactor
set the resizeQuality of image pImgName to "good"
set the width of image pImgName to the width of image pImgName * pResizeFactor
set the height of image pImgName to the height of image pImgName * pResizeFactor
end resizeImage
In a button, or even in the image object script, write a mouseUp handler:
on mouseUp
resizeImage "imageNameHere", .5
end mouseUp
Of course you would put the actual name of the image in place of "imageNameHere".

I've checked out the older anwers and I think they forget to make sure that the image stays in the same location. I'm also adding a lock screen command. You may omit this if you think it slows down the button too much.
You can put the mouseUp handler into script of the button and the resizeImage handler anywhere higher up the message hierarchy or in the script of the button itself.
on mouseUp
lock screen
resizeImage the long id of img 1
unlock screen
end mouseUp
on resizeImage theImg
put the loc of theImg into myLoc
set the width of theImg to the width of theImg / 2
set the height of theImg to the height of theImg / 2
set the loc of theImg to myLoc
end resizeName
You need to adjust the long id of img 1 to make sure it changed the size of the correct image, for instance use the long id of img id 69456 if the short id is 69456 or the long id of img "my image" if the name of the image is "my image".

Related

Tkinter Button not working when inserting an image

I am trying to add buttons with custom bg or image so like 3d color. But it gives a white unclickable button as result. I tried many other ways but failed, the code i gave below its a code which lets us to select the weight and height we want for the button that's why i choosed it otherwise if other things like the .zoom or making a function to make the image fit the button were working i would be using them, they are all not working and i have no idea, i know i must be doing something wrong but wellas you see i am new in python, i learned everything myself so really i am 0 x). I Resized the image aswell, it has the same weight height with the button:
root.geometry(geo)
image = ImageTk.PhotoImage(file='background.png')
label = Label(root, image=image)
label.pack(fill='both', expand=True)
label.image = image
myWidth = 150
myHeight = 82
img4=Image.open('button.png')
image4=img4.resize((myWidth,myHeight))
useImg4=ImageTk.PhotoImage(image4)
quitBtn = Button(label, image=useImg4,command=lambda: root.destroy())
quitBtn.pack()
do you know why its not working?
The result:

Get Dimensions of Cell Comment Background Image (.Shape.Fill.UserPicture)

How do I get the dimensions of a cell comment background image?
I have created a comment composed solely of a background image using,
ActiveCell.Comment.Shape.Fill.UserPicture l_strFullPathOfImagePNG
I would like to be able to,
Select the cell.
Run a macro that resizes the comment so the background image is not fuzzy, but rather sized exactly pixel for pixel.
To do this I need to know the dimensions of the background image.
If I know the full path of the image file that created the background image, I can resize the cell comment to achieve what I want:
Sub CommentResizeToFitBackgroundImage()
Dim l_strFullPathOfImagePNG As String
Dim l_lImageWidth_pixels As Long, _
l_lImageHeight_pixels As Long
l_strFullPathOfImagePNG = "C:\……\BackgroundImage.png"
'Get the width and height in pixels of the image to be inserted
GetPNGDimensions _
l_strFullPathOfImagePNG, _
l_lImageWidth_pixels, _
l_lImageHeight_pixels
With ActiveCell.Comment.Shape
'0.75 scale factor was arrived at empirically
'and probably true only for my machine
.Width = l_lImageWidth_pixels * 0.75
.Height = l_lImageHeight_pixels * 0.75
End With
End Sub
However, I would like to do this to existing comments that no longer have a valid image file to read, so I need to get the dimensions of the background image.
.Comment.Shape.ScaleHeight 1, msoTrue looks promising, but fails with the error "The RelativeToOriginalSize argument applies only to a picture or an OLE object".
.Comment.Shape.Fill.Type = MsoFillType.msoFillPicture; so I do indeed have a picture, and not a solid background, gradient, pattern, or texture; so I don't know what the compiler is complaining about.
Lastly, evidently, .Comment.Shape.Fill.PictureEffects doesn't work for comments.

How to fix variable line height in data grid with SQLite database when using callbacks

I'm working with the data grid with SQLite database using a feature called callbacks as described in this lesson: displaying-large-amounts-of-data
I'd like to make some changes to the sample stack included in that lesson (you can download the stack from the link on the top of that page).
I'd like to display the 'plot' text in the DG instead of the 'Title' of the movie and the plot text should have variable line heights as described in this lesson: how-do-i-create-a-form-with-variable-line-heights
In the sample stack I made these changes:
in the Row Template:
renamed field "Title" to "plot", set the dontWrap to false and changed fixedLineHeight to false
renamed field "ReleaseDate" to "nr"
added:
set the text of field "nr" of me to pDataArray["id"]
in the Row Behavior:
## changed the layoutControl to make space for wrapping of field "plot"
on LayoutControl pControlRect
local theFieldRect
put the rect of me into theFieldRect
set the right of button "Genre" of me to item 3 of theFieldRect
set the right of field "LblGenre" of me to the left of button "Genre" of me
set the right of field "nr" of me to item 3 of theFieldRect
## Expand field "plot"
put the rect of field "plot" of me into theFieldRect
put item 3 of pControlRect - 180 into item 3 of theFieldRect
set the rect of field "plot" of me to theFieldRect
##Now resize field to fit content
put item 2 of theFieldRect \
+ the formattedheight of field "plot" of me - \
the bottommargin of field "plot" of me \
into item 4 of theFieldRect
set the rect of field "plot" of me to theFieldRect
## Now update the bounding rect to match total height you
## want this row to have
put item 4 of theFieldRect into item 4 of pControlRect
set the rect of graphic "Background" of me to pControlRect
end LayoutControl
In the lesson on setting variable line heights it says to turn off the "fixed control height" of the data grid. However when I do that nothing gets displayed and I'm getting a scrip error.
The stack with my changes is here: Databases-callbacks-variable-line-height.zip
(just replace the original stack from the lesson with it; the SQLite database is the same and should be placed in the same folder as the stack).
How to fix this so that the variable line height will work?
I located the problem with fixed control height turned off. The data grid behavior isn't setting the GetDataForLine pLine parameter properly when caching the height for each row. I'll provide a modification you can make to the data grid behavior until a fix is included in LiveCode, but you should probably reconsider your approach. When fixed line height is turned off the data grid has to compute the height of every line prior to displaying the data grid. This takes a loooooong time for the 50,000 record example you are working with.
First, edit the script of the data grid behavior:
edit script of btn "data grid" of stack "revdatagridlibrary"
Next, go to line 3097. Below 3097 add the following line of code:
add 1 to theSequence
The code should now look like this:
repeat for each key theIndex in sDataArray
add 1 to theSequence
## Get height
if sDataArray[theIndex] is NULL then
Save the script. This will save the change in your current version of LiveCode. Be aware that the next time you update LiveCode the change will be lost. I submitted the fix to RunRev, however, so it should be fixed in the next release.
Also, your code that sets the rect of graphic "Background" needs a small change. Right now it won't work if the bottom of the field is higher than the bottom of the "Genre" button. The code should probably be something like this:
put max(item 4 of theFieldRect, the bottom of button "Genre" of me + 4) into item 4 of pControlRect

Manipulate pixels in QGraphcisPixmapItem

I am using PyQt to build a small application for viewing images. When I click on the image I would like to alter the color of the pixels I have clicked:
Schematically my current code looks like this:
scene = QtGui.QGraphicsScene()
view = QtGui.QGraphicsView( scene )
image = QtGui.QImage( "image.png" )
pixmap = QtGui.QGraphicsPixmapItem( QtGui.QPixMap.fromImage( image ))
scene.addItem( pixmap )
...
...
def mousePressEvent(self , event):
print "Click on pixmap recorded - setting Pixel to red"
image.setPixel( event.pos() , RED.rgb())
The code 'works' in the sense that the mousePressEvent() method is called, and the image.setPixel() method does not give any errors, but nothing happens on the screen. Any tips on how to get the updated pixels to be displayed?
Joakim
To make changes appear, you need to reload image
self.image.setPixel(event.pos(), RED.rgb())
self.pixmap.setPixmap(QtGui.QPixmap.fromImage(self.image))
But I'm not sure that it's a good way. If you don't need to save modified image, I'd add some circles (e.g. addEllipse) instead modifying pixels.
Also, don't forget to map window coordinates to image.

How to get screen height in LWUIT out of height reserved for MenuBar and TitleBar?

I want to get the height and width of the screen which I could draw objects on. It's the space which is other than the the MenuBar (the footer containing commands) and other than the TitleBar.
TIP: I know that Display.getInstance().getDisplayHeight() returns the height of the screen but this is for the full sceen. So how could I, at least, know the height of the MenuBar and TitleBar to substract them from this height ?
I found the answer for those who are interested:
To get the height of TitleBar: Form.getTitleComponent().getPreferredH()
To get the height of AddressBar: Form.getSoftButton(0).getParent().getPreferredH()
So the answer of my question is:
Display.getInstance().getDisplayHeight()
- form.getTitleComponent().getPreferredH()
- (getSoftbuttonCount() < 1) ? 0 : form.getSoftButton(0).getParent().getPreferredH()

Resources