Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
ScrollView pythonista-anchors
-
i don't know is it okay to post this Question here....
maybe i need a new Topic ?i Have This MYSQL Code here.
self.cur.execute("SELECT `manufacturer`, SUM(`count`) FROM `datanorm` GROUP BY `manufacturer`") for counterLoop, arrayManufacturerTemp in enumerate(self.cur, start=1): print(f'counterLoop -- {counterLoop}') print(f'arrayManufacturerTemp[0] - manufacturer -- {arrayManufacturerTemp[0]}') print(f'arrayManufacturerTemp[1] - manufacturerCount -- {arrayManufacturerTemp[1]}')
this give me that output:
counterLoop -- 13 arrayManufacturerTemp[0] - manufacturer -- Kaiser GmbH & Co. KG arrayManufacturerTemp[1] - manufacturerCount -- 1
i don't know is it possible to do that about what im thinking..
but here is my example what i want...:counterLoop=13 labelcounterLoop = size_to_fit(ui.Label( text=arrayManufacturerTemp[0], #background_color='white', alignment=ui.ALIGN_LEFT, text_color='white', )) counterLoop=14 labelcounterLoop = size_to_fit(ui.Label( text=arrayManufacturerTemp[1], #background_color='white', alignment=ui.ALIGN_LEFT, text_color='white', )) counterLoop=15 labelcounterLoop = size_to_fit(ui.Label( text=arrayManufacturerTemp[0], #background_color='white', alignment=ui.ALIGN_LEFT, text_color='white', )) counterLoop=16 labelcounterLoop = size_to_fit(ui.Label( text=arrayManufacturerTemp[1], #background_color='white', alignment=ui.ALIGN_LEFT, text_color='white', )) attach(labelcounterLoop).below(labelcounterLoop) attach(labelcounterLoop).right_of(labelcounterLoop) attach(labelcounterLoop).below(labelcounterLoop) attach(labelcounterLoop).right_of(labelcounterLoop)
so my Querry gives me some content what i will display with attach....
the fist Label is my Name (Names are below each other)
the Second Label is my Count (Counts are right_of Names for each other)I dont have an Idea to get this in an For loop.... (see above to MYSQL Query)
i hope you Guys understand what i want to say :D
thanks again and greetings -
for i, name, count in enumerate(self.cur, start=1):
-
@ccc said:
for i, name, count in enumerate(self.cur, start=1):
I think you dont get me Right ?
Or can i use i as Variable ?
i = size_to_fit (xxxxx)
I dont think so...
-
Let's assume that you have the following function to reduce the boilerplate code:
def make_label(text: str) -> ui.Label: return size_to_fit(ui.Label( text=text, #background_color='white', alignment=ui.ALIGN_LEFT, text_color='white', ))
Now, rewrite the rest of your code to use that function and your question will become clearer.
-
@DavinE have you used TableViews before? It really seems like you are trying to make a tableview by yourself by using. Scrollview and labels.
Tableview takes care of most of the hard positioning bits, and you just need to handle each cell.
-
@ccc said:
Let's assume that you have the following function to reduce the boilerplate code:
def make_label(text: str) -> ui.Label: return size_to_fit(ui.Label( text=text, #background_color='white', alignment=ui.ALIGN_LEFT, text_color='white', ))
Now, rewrite the rest of your code to use that function and your question will become clearer.
ahh i think i know what do you mean @ccc but that's not really my issue...
My Issue is how can i combine my code above with the attach Function....
attach need once the Label Name Label1 and for the below() the Label Name above...
and when i use my for Loop from MYSQL.... i don't have fix Variable to call the attach.... that i do not understand right..or im on the wrong way ?
-
It is easier to debug Python code than it is to debug English prose.
-
@JonB said:
@DavinE have you used TableViews before? It really seems like you are trying to make a tableview by yourself by using. Scrollview and labels.
Tableview takes care of most of the hard positioning bits, and you just need to handle each cell.
My ScrollView need i because its a lot of rows....
TabelViews have only one column or ? so far i know.. -
@ccc said:
It is easier to debug Python code than it is to debug English prose.
sry i don't can explain it better......
-
def make_label(text): return f"label({text})" data_from_mysql = (("Acme", 11), ("Bart's", 22), ("Carls's", 33)) labels = [] for name, count in data_from_mysql: labels.append(make_label(name)) labels.append(make_label(count)) print(labels)
['label(Acme)', 'label(11)', "label(Bart's)", 'label(22)', "label(Carls's)", 'label(33)']
OK... So now we have a list of six labels... What is the question?
-
-
it sounds like you don't even need multiple columns, you just need a title and a subtitle. more complex cells you can design yourself, using the content_view.
This example shows the four cell styles -- value1, value2, subtitle, and default. For bonus points, you would have the tableview_cell_for_row , etc, actually look up durectly from your sql database .
import ui,sys PY3 = sys.version_info[0] >= 3 if PY3: basestring = str class DetailTextDataSource(ui.ListDataSource): def __init__(self, items, style): self.style=style ui.ListDataSource.__init__(self,items) def tableview_cell_for_row(self,tv,section,row): item = self.items[row] cell = ui.TableViewCell(self.style) cell.text_label.number_of_lines = self.number_of_lines if isinstance(item, dict): cell.text_label.text = item.get('title', '') try: cell.detail_text_label.text = item.get('subtitle', '') except AttributeError: pass img = item.get('image', None) if img: try: if isinstance(img, basestring): cell.image_view.image = ui.Image.named(img) elif isinstance(img, ui.Image): cell.image_view.image = img except AttributeError: pass accessory = item.get('accessory_type', 'none') cell.accessory_type = accessory elif isinstance(item,tuple): cell.text_label.text = str(item[0]) cell.detail_text_label.text = str(item[1]) else: cell.text_label.text = str(item) if self.text_color: cell.text_label.text_color = self.text_color if self.highlight_color: bg_view = ui.View(background_color=self.highlight_color) cell.selected_background_view = bg_view if self.font: cell.text_label.font = self.font return cell items=[{'title':'Strawberries','subtitle':'3.99','image':'plf:Enemy_Ladybug'}, {'title':'Blueberries','subtitle':'2.99','image':'plf:Enemy_Snail_shell'}, {'title':'Honey','subtitle':'4.50','image':'plf:Enemy_Bee'}, {'title':'Fresh fish','subtitle':'6/lb','image':'plf:Enemy_FishGreen'}, ] mainview=ui.View(frame=(0,0,1024,768)) S1=DetailTextDataSource(items,'value1') t=ui.TableView(frame=(0,0,300,600)) t.data_source=S1 t.delegate=S1 mainview.add_subview(t) S2=DetailTextDataSource(items,'value2') t2=ui.TableView(frame=(310,0,200,600)) t2.data_source=S2 t2.delegate=S2 mainview.add_subview(t2) S3=DetailTextDataSource(items,'subtitle') t3=ui.TableView(frame=(520,0,200,600)) t3.data_source=S3 t3.delegate=S3 mainview.add_subview(t3) S4=DetailTextDataSource(items,'default') t4=ui.TableView(frame=(740,0,200,600)) t4.data_source=S4 t4.delegate=S4 mainview.add_subview(t4) mainview.present()
-