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.
Adding a label to TableViewCell, it's offset by one?...
-
You might consider adding
cell_type
tomake_cell()
:def make_cell(row, cell_type='subtitle'): # None, 'value1', 'value2' are other possibilities cell = ui.TableViewCell(cell_type) [ ... ]
-
@ccc, yes thanks. I am working on something else with tableview at the moment and I did exactly that (I also commented all the params so not to forget them). Only wrote this to convey my issue I was having with tableview. Easy data to convey. Wrote the big blurb about the king, more like a reflex. You live here long enough you assimilate into the culture.
But regardless you are right should be written correctly.
I love the implementation of the tableview, but I think a margin/indent attr would be great, also a virtual mode. I can see it's semi virtual. What I can see is that not all cells are fetched at once. Looks like omz has implemented some fetch routine based on the visible cells plus a read ahead amount of cells.
But if you had a create cell and a draw cell, you could easily have max(int) rows. No real performance hit as long as your data retrieval method was fast enough. In the days when memory was scarce and CPU power was low, and networks slower, we could do some great things with virtual lists. We had to steer away from databases for this to work. Our data files were variable length, but just had index files we could binary search our keys that pointed to a location in the file with a length (for the day they were massive files) I know, not great for updates. We had an update system also. But we replaced all our customers data files monthly. Yeah, the days of cd and dvd distribution:)
Sorry to digress, but some of the old ideas are ok for some problems.Anyway, my 2 cents worth :)
-
I got some grief over the colors I selected for this example from many thai girls ( I didn't select any colors, just used the color name), So then picked the colors with them and made a new list. Is more representative of the colors. Also added another list for the thai words. I was happy it worked so easily, but pretty sure the utf-8 comment up the top helps.
Hmm, I am very new to Unicode etc (we used to call double byte) here on iOS. Even it's just copy paste into a list, it's the first I have done in Pythonista. If you are interested to run the code, I have included a screen shot what the output should look like. I am not sure if it renders correctly on my iPad because of my settings or not.
#coding: utf-8 import ui _days = ['Monday', 'Tuesday', 'Wednesday','Thursday', 'Friday', 'Saturday','Sunday'] # the colors corresponding to days of the week # thai people often wear these colors on the day # of the week. Is related to the Royal Family. # Currently, the most important is yellow, the # The King of Thailand was born on a Monday # He is the longest severing and living monach # in the world. _real_colors = ['gold', 'deeppink', 'green', 'orangered', 'blue', 'purple', 'red'] _colors = ['yellow', 'pink', 'green', 'orange', 'blue', 'purple', 'red'] _thai_script_colors = ['สีเหลือง', 'สีชมพู','สีเขียว','สีส้ม','สีฟ้า', 'สีม่วง', 'สีแดง'] def make_cell(row , cell_type = 'subtitle'): #TableViewCell params None,subtitle,value1,value2 cell = ui.TableViewCell(cell_type) btn = ui.Button() btn.width = btn.height = 28 btn.x, btn.y = 8 , (cell.height / 2) - (btn.height / 2) btn.background_color = _real_colors[row] cell.content_view.add_subview(btn) cell.text_label.text = ' ' * 6 + _days[row] cell.detail_text_label.text = ' ' * 9 + _colors[row].title() if _colors[row] <> _real_colors[row]: cell.detail_text_label.text += ' (' + _real_colors[row] + ')' cell.detail_text_label.text += ' ' + _thai_script_colors[row] return cell class MyTableViewDataSource (object): def tableview_number_of_sections(self, tableview): # Return the number of sections (defaults to 1) return 1 def tableview_number_of_rows(self, tableview, section): # Return the number of rows in the section return len(_days) def tableview_cell_for_row(self, tableview, section, row): # Create and return a cell for the given section/row return make_cell(row) def tableview_title_for_header(self, tableview, section): # Return a title for the given section. # If this is not implemented, no section headers will be shown if section == 0: return 'Week Days' def tableview_can_delete(self, tableview, section, row): # Return True if the user should be able to delete the given row. return False def tableview_can_move(self, tableview, section, row): # Return True if a reordering control should be shown for the given row (in editing mode). return False def tableview_delete(self, tableview, section, row): # Called when the user confirms deletion of the given row. pass def tableview_move_row(self, tableview, from_section, from_row, to_section, to_row): # Called when the user moves a row with the reordering control (in editing mode). pass if __name__ == '__main__': frame = (0,0,540,576) tb = ui.TableView() tb.name = 'Thai Color Chart' tb.frame = frame tb.data_source = MyTableViewDataSource() tb.present('sheet')
Image of the screen rendered with thai text
https://www.dropbox.com/s/td54lkujo6lgnrg/file 12-07-2015 22 29 51.png?dl=0 -
(I'm impressed Firefox can render those characters - on this FORUM.) :-)
-
The thai chars also rendering in safari in the forum. I guess we should not be so surprised, handling of multi byte scripts have come so far (to tell the truth, I can't remember if thai is multi byte or not, I think it has to be though) I was more worried about the python side. Seems you have to me very careful when you start dealing with Unicode scripts in python. No experience, just what I read.
-
Thai characters are double byte:
# coding: utf-8 print('\nunicode, hex, dec') for c in u'สีเหลือง': print('{0}, {0!r}, {1}'.format(c, ord(c)))
http://pyformat.info
is a great source of info on str.format(). -
@phuket2 and I guess my Japanese customers (at least) still use DBCS - with SI and SO etc.
-
@MartinPacker, don't really know what SI and SO is. I have been out of it too long. I haven't commercially coded for around 20 years probably longer than that. I have been retired going on 16 years now. So to say I am out of touch is a huge understatement. But I wish Python had been mainstream when I was programming. I guess even if it was, the processors of the day were just too slow. We could use high level languages for the basic parts of the interface, but had to resort to c for many things. Nothing wrong with c when you are in the groove, we basically released a new app every month, that's scary with c. Well, I thought it was. Most the time we got it right, but not all the time. Also dealing with Japanese, big datasets with our own search routines with input for katakana, kanji and another variant. Sorry, if the names are not exact, but was a long time ago. But imagine implementing a soundX function for something like thai :) ironically enough thai is a tone based language. 5 tones. High, low, rising, falling and mid tones. The first trick is to find out what constitutes a thai word :) thai is written without spaces. A lot of rules to figure out what a word is :) I did a neat trick some years ago when learning thai. I used MS word and vb script to do word breaks for me. So easy in word to iterate over each word and print it out. As a word processor that supports a language it needs these rules, and they do it well.
I know I digress from Pythonista specific things now. But sometimes these simple tools/ideas can help. -
@ccc, very cool code. You never cease to amaze me :) I have been to the site you suggest for formatting, looks great. I know why you mention it to me :) I am never using the format routines in my code. Not that I don't want to. Just my brain gets full pretty quickly. Trying to do an app for a friend at the moment for his personal dvd collection. Sounds simple, but I have to learn about responses, third party APIs for IMDB and a lot of other stuff. I have been writing bits of this and that trying to learn, but this small project, I would like to finish. The code is not going to be beautiful, it's just about time I do something that is real and useful and can be be used by someone other than myself.
-
@MartinPacker, am I on the right track? DBCS - with SI and SO
@Phukett2, Checkout @coomlata1's Search IMDb
-
@ccc, yes, his code is more sophisticated than my code. But I am using the same API as he is using. They just released a poster API also, but have to donate first. It was fine for me. My app is more vertical market. For my friend.
The starting point is a csv export from "movie collector" application on the mac. I call these my raw files. Store them in a predictable directory. I have some code that goes through and cleans the data and writes out a new data file.most importantly the export from movie collector has the IMDB Id were possible. Then I have other functions that use the omdbapi API to recover the JSON object which I save in another directory with the IMDB ID + .txt. I just do a JSON.dump to the file. But once I have that object I have the poster URL which I can then download with response and save to another directory. This code is a batch process, just about updating the different assets. Of course, before any internet call are made, checking to see if the assets are already cached or not. I have done quite a bit of work on it, as I say it's not all that pretty, but I need to try and make a complete app.
When finished for me it will be as complete as I can do, meaning that to deploy it to my friend, I will have to help him a little to get started, but after that he will be able to do his own updates etc..
I am doing all the hard work in the background as one normally does on a normal app. I have not done settings yet. But I will allow a lot of customisation of the displays. But once it's all stable, I will pass it over it to him and try to keep developing and updating him. Try being the operative word.I am still working on it, but I think I have a reasonable and flexible model to improve it.
What it looks like, nothing special, but it will be for my thai friend once I am finished.
Oh, I should mention that I have copied code segments from the fourm here like the function pil_to_ui. And also some other functions from stackflow. I just copied then because I didn't understand them enough to rewrite them myself.there is still some skill in being able to copy code and use it with in your own context until you get your head around it.
https://www.dropbox.com/s/k5w7n1b8ry1z8zk/file 14-07-2015 21 54 09.png?dl=0
https://www.dropbox.com/s/cgmvsxp4aqtk7fa/file 14-07-2015 21 54 49.png?dl=0
https://www.dropbox.com/s/ylkssrw0kkexvma/file 14-07-2015 22 00 38.png?dl=0 -
FYI, you should be able directly post images from Dropbox into the forums if you append
?raw=1
to the end of the url, in place of the?dl=0
example:

-
@JonB, thanks. So many tricks. Is it good a good practice to include them directly into the post? I had 3 pics there. Maybe people get annoyed because of the downloading time. I am not sure. I don't care one way or another.i don't have any extra charges for my internet whether I am on wifi or 3G (yes sadly on 3G here, but limited 4g roll out. ) LTE etc, we don't we think about that here :) but I am going to do a test pic from Dropbox with raw=1. Was a pic of me with make up on last New Year's Eve :) sorry couldn't help myself. Was a fun night and no one beat me up :) I like to push the boundaries
https://www.dropbox.com/s/ne8zjdqrpyue67b/ian_profile_pic.jpg?raw=1 -
Oops, looks like I failed again
-
Not that it really matters, but for correctness, I mentioned a mac app call movie collector above, the app is actually called movie explorer. A great app.
-
Made a new view today for my app. Nothing special, but the languages are funny. Have Klingon Language:)