Adding a label to TableViewCell, it's offset by one?...
I assume this is a bug, if it is so be it... I hope not....
But I am adding a label to a TableViewCell. And magically it's offset by one. I guess it's something to do with section. I have tried and tried to fix it, but can not. The other problem is that the view is Cell is not being doubled buffered correctly (or whatever you call it) if you pull down on my list you will see that the labels I created are no longer drawn. I tried both ways. Adding my ui.Label to cell.content_view as stated in the docs and I tried also cell.add_subview. Same results.
Any advice appreciated
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. _colors = ['yellow', 'pink', 'green', 'orange', 'blue', 'purple', 'red'] 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 cell = ui.TableViewCell() cell.text_label.text = _days[row] # create a label inside the cell # the documentation says to add it to the # content view lb = ui.Label() lb.x , lb.y = 15, 30 lb.width = cell.width - lb.x lb.text_color = _colors[row] lb.text = _colors[row] cell.content_view.add_subview(lb) cell.add_subview(lb) return cell 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 True 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 True 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) v = ui.View() tb = ui.TableView() tb.frame = frame v.add_subview(tb) tb.data_source = MyTableViewDataSource() v.present('sheet')
@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.
@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=1to the end of the url, in place of the
@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
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:)