How to organize photos within data in a text field? - livecode

Currently I am able to load all of the photos onto the page, however, they all load in the center of the app on top of one another. I want to have the images display before the data it belongs with.
For example:
[photo]
Name:
Sex:
Age:
[photo]
Name:
Sex:
Age:
...
This is my code currently (data loaded from xml url) and I have tried to look at rect and other properties, but I have not been able to have any luck.
repeat for each line tChild in tChildren
add 1 to x
put revXMLChildNames( tInfo, "ArrayOfXmlNode/"&tChild&backslash, return, "adoptableSearch", true) into tAdoptable
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Photo") into tURL
put url tUrl into tPhoto
if the result is empty then
set the text of img x to tPhoto
else
beep
end if
put "Name: " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Name") & return after tData
...
end repeat
Thank you in advance for any help!

As you have no creation of the images in your code I assume that you have created them before the repeat loop, then you will need to lock the size and position of the image.
My other suggestion is to create a template group with an image and one or more fields (name, sex, age etc). You can then create a nice layout for each part. When done you can lock everything within the group but still easily set the location for the complete group. Finally you can then move the template group outside the card or hide it.
put 50 into tTop
put 20 into tLeft
put the width of group "templateGroup" into tTempGW
put the height of group "templateGroup" into tTempGH
put 0 into tCount
repeat for each line tChild in tChildren
copy group "templateGroup" to this card
put it into tGroupID # It holds the long id after a copy operation
put url tUrl into tPhoto
if the result is empty then
set the text of img 1 of tGroupID to tPhoto
else
beep
end if
# Position the new group
set the topLeft of tGroupID to tLeft,tTop
add tTempGW to tLeft
if tLeft + tTempGW > the width of this stack then
# Next item will be partly outside so we move down
add tTempGH to tTop
put 20 into tLeft
end if
# Set some proper name
add 1 to tCount
set the name of tGroupID to ("Person" && tCount)
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Name") into field "name" of tGroupID
...
end repeat
You can of course use other values for top and left. I usually use an empty group to hold all other groups then you use the boundaries for that group as top, left, right.

Related

Tkinter both 'sticky' and 'rowconfigure' did not fill the empty space

I have 2 frames inside root which called "header_frame" and "activity_frame" both are in the same column which is "column=0". I want both frames to be resizeable matching its root parent filling all empty space like this :
I have tried all grid config possibilities including setting 'rowconfigure' on 'root', set activity_frame to stick on "North" which is header_frame, last but not least I've also tried to stick header_frame to south which is the result I do not want because those frame share same size (I hope header_frame has 'maxsize' attribute but sadly it didn't have). so this is the code that I've tried :
self.root = root
self.column = ""
self.search = ""
self.root.minsize(500,480)
self.comboboxValue = None
self.root.title("CUCI (CSV Unique Column Identifier)")
self.root.configure(background="powder blue")
self.root.grid_columnconfigure(0,weight=1)
self.root.grid_rowconfigure(0,weight=1)
self.root.grid_rowconfigure(1,weight=1)
#header frame
self.header_frame = tk.Frame(self.root)
self.header_frame.grid(row=0, column=0,sticky="NEW")
self.header_frame.grid_columnconfigure(0,weight=1)
self.header_frame.grid_rowconfigure(0,weight=1)
self.header_frame.configure(background="grey")
#activity Frame
self.activity_frame = tk.Frame(self.root)
self.activity_frame.grid(row=1, column=0,sticky="NEWS")
self.activity_frame.grid_columnconfigure(0,weight=1)
self.activity_frame.grid_rowconfigure(0,weight=1)
self.activity_frame.configure(background="grey",pady=1)
Here's the layout result from my code which I do not expect:
The point is that I want to fill those empty spaces with activity_frame to be stick-ed on 'header_frame'.Please I do not wish to use pack(self.activity_frame.pack(fill=tk.X)). I just want to use grid because it's easy to use
The reason for the gap is because you don't have the header frame stick to the bottom of the space it was given. If you change the sticky attribute for the header to be "nsew" you'll see that the header fills the extra space.
self.header_frame.grid(row=0, column=0,sticky="nesw")
I'm guessing you don't want the header frame to be so tall. If that is the case, give row 0 a weight of 0 instead of 1. That way all extra unallocated space will be given to row 1.
self.root.grid_rowconfigure(0,weight=0)
After doing so, and after adding a couple of other widgets to simulate your screen, this is what it looks like:

I am trying to put some text in the PDF location I want. But it is not in the right position

Pdf.setFillColorRGB(0,1,0)
Pdf.setFont('Arial',Left_Font_Pt*inch)
# print('Word_List_Height',Word_List_Height)
Pdf.drawString((width-(Word_List_Width+5)),(Word_List_Height*len(List_Word)-0.1),text = List_Word[0])
for i in range(1,len(List_Word)) :
Pdf.drawString((width-(Word_List_Width+5)),(Word_List_Height*(len(List_Word)-i)-0.1),text = List_Word[i])
I want to put List_Word to Bottom right but it will exceed the Border

How to limit the items in popup?

How to limit the items in the popup. "Sar" array contains lot of words, with respect to the selection. if my first popup contains 15 items and did the change. when going to the next popup, if it contains 10 items, the remains 5 items from the first also added to the second popup options.
How to kill that buffer in popup menu items? Iam using this code
global jar,myjar,sam,mySam,Dic,Sar
on mouseUp pMouseButton
put the selectedText of field "MytextField" into Ftext
if pMouseButton = 3 then
put the number of lines of (the keys of sam) into mySam
repeat with i = 1 to mySam
if sam[i] contains Ftext then
put sam[i] into Sar
split Sar by comma
end if
end repeat
put the text of button "M" into tText
put the number of words of (the keys of Sar) into mylength
repeat with x = 1 to mylength
put Sar[x] into line x of tText
end repeat
put mylength into kk---now iam using this code for delete the buffer
----repeat with j = kk to 100
---put "" into line j of tText
---end repeat
set the text of button "M" to tText
popup button "M" at the clickLoc
else
--popup button "M" at the clickLoc
-- do other stuff here
end if
end mouseUp
Is any option for limit the items in popup. Example:- if popup contains 15 items, i want to see only 10 items, remaining 5 could be see only clicking the bottom button in the popup
You are using globals which might not be what you want.
Try emptying the global with put empty into Sar before adding some new values or use locals which will be emptied after your code is done.

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

Trying to get the start and end point of each line within a text pane

Trying to get the start and end point of each line within a text pane:
The text pane contains (note target is the end of each line not including the blank space line):
(blank space line)
MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDKVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtarget
MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDVFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKAAAEEQNKEALQDVEDENQtarget
MVESMKKVAGMDVELTVEERN000TAQEGDHGSHVYTKQKEENKGGEDKLKMIREYRQMVETELKLICCDILDVLDKHDDDDDDDFYYKMKGDYHRYLAEFATGNDRKEAAENSLVAYKAASDIAMTELPPTHPIRLGLALNFSVFYYEILNSPDRACRLAKAAFDDAIAELDTLSEESYKDS00000VQVGQQRSDMQGDGKKKDDDDDDDEEQNKEALQDVEDENQtarget
//This is what I have
Element root = jTextPane1.getDocument().getDefaultRootElement();
Element one = root.getElement(0);
while (one !=null){
int one1 = one.getStartOffset();
int two1 = one.getEndOffset();
System.out.println(one1);
System.out.println(two1);
one = root.getElement(two1);
}
This is what I get (1st and 2nd element) and then hangs:
0
1
1
232
You mix model and view. Document is just model but amount of rows depends on view (width of content).
Use javax.swing.text.Utilities.getRowStart()/getRowEnd()
See an example of the code usage http://java-sl.com/tip_row_column.html

Resources