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.
A copy code button here in the forum.
-
@Phuket2
Here's a screenshot. My code is a bit of a jumble yet- I fear sharing it will cause some professional coders to have a panic attack!! hahaAnyway here's a preview: (let's see if I can get that inline image to work haha)
-
Awesome, can't wait
-
@cook, looks nice. I hope something can be done about the RSS limitation. There are some other limitations also. If I search for my user name for example, I don't get all the listings back. I have a feeling connected to the 20 limitation somehow. Frustrating, because I get some good answers sometimes and can't find them. Eg, how to put an inline Dropbox in the forum :)
Still can't figure it out. Still early in the day for me :) will try later, as well as what ccc says, I remember need to use ![] somewhere also.
With your browser, are you storing the posts locally as well? Not sure it exactly makes sense to do so. Could could be nice to mark favourite posts etc for reference, for retiree's like me with a failing memory :)
Also, is the Table you are using a std ui.TableView?
Your ui is looking nice and professional. -
Same code, as above. No fixes for the weird bug yet. As I say as long as the clipboard is valid, works nicely. Even better invoking it from WorkFlow.
I have just updated positioning code into layout, instead of doing a sheet view. Comes up in full screen now and is correct on my iphone 6 and iPad and adjusts with orientation.
I have to start to do this all the time. Just a mind set.# coding: utf-8 # WARNING - HANGS AFTER COPY CODE, THEN RUNNING # AGAIN WITH THE COPIED CODE ON THE CLIPBOARD. # HAVE TO RESTART PYTHONISTA! import ui import clipboard import console class OmzFourmCopy(ui.View): def __init__(self, data_list): self.data = data_list # create copy title btn btn = ui.ButtonItem('Copy Code') btn.action = self.copy_code self.right_button_items = [btn] # create the tableview, set the data_source # and delegate to self. tv = ui.TableView(name = 'tv1') tv.name = 'tv1' tv.data_source = self tv.border_width = .5 tv.delegate = self #create textview txtv = ui.TextView(name = 'txtv') txtv.font = ('Courier', 14) # select the first code block tv.selected_row = 0 txtv.text = self.data[0] self.add_subview(txtv) self.add_subview(tv) def copy_code(self, sender): if self['txtv'].text: code = self.data[self['tv1'].selected_row[0]] #clipboard.set(self['txtv'].text) clipboard.set(code) console.hud_alert('Copied', duration = .5) self.close() def layout(self): self.frame = self.bounds tv = self['tv1'] tv.frame = (0,0,self.width * .20, self.height) self['txtv'].frame = (tv.width, 0, self.width - tv.width, self.height) def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell() cell.text_label.text = 'Code {}'.format(row + 1) return cell def tableview_number_of_rows(self, tableview, section): # Return the number of rows in the section return len(self.data) def tableview_did_select(self, tableview, section, row): self['txtv'].text = self.data[row] use_appex = False try: # appex is only available in 1.6 beta, fail gracefully when running in 1.5 import appex use_appex = appex.is_running_extension() except: pass def main(): lst = [] if use_appex: url = appex.get_url() else: url = clipboard.get() if 'omz-forums' not in url or len(url.splitlines()) > 1: #print 'No forum URL' lst.append('-1') # i know this is crappy. return lst import requests import bs4 html = requests.get(url).text soup = bs4.BeautifulSoup(html) pre_tags = soup.find_all('pre') if pre_tags: text = '' #text = ('\n#%s\n\n' % ('=' * 30)).join([p.get_text() for p in pre_tags]) for p in pre_tags: lst.append(p.get_text()) #clipboard.set(text) #print 'Code copied (%i lines)' % (len(text.splitlines())) else: #print 'No code found' pass return lst if __name__ == '__main__': lst = main() if len(lst) == 0: console.alert('No code found') elif lst[0] == '-1': console.alert('omz-forums, not in url') else: x = OmzFourmCopy(lst) x.present()
-
I hope something can be done about the RSS limitation. There are some other limitations also. If I search for my user name for example, I don't get all the listings back. I have a feeling connected to the 20 limitation somehow. Frustrating, because I get some good answers sometimes and can't find them.
I see that too. Limited response from the server.
how to put an inline Dropbox in the forum
Markdown format for inline image is like this: <code>! [some text] (image url)</code>
For dropbox image you need to modify the url:
<code>https://www.dropbox.com/s/00e5iys2alnuzxs/forumspreview.png?dl=0</code>
minus "dl=0" plus "raw=1" equals this:<code>https://www.dropbox.com/s/00e5iys2alnuzxs/forumspreview.png?raw=1</code>
Then finally in markdown:
<code>! [my picture] (https://www.dropbox.com/s/00e5iys2alnuzxs/forumspreview.png?raw=1)</code>
Just no spaces in between!With your browser, are you storing the posts locally as well? Not sure it exactly makes sense to do so. Could could be nice to mark favourite posts etc for reference, for retiree's like me with a failing memory :)
Plan to. I want to include a 'following thread' type of thing - for threads that are interesting to you and may or may not be active in the RSS feed. I also thought about including a kind of bookmark feature for posts/threads that you just want to keep around for reference' sake.
Also, is the Table you are using a std ui.TableView?
Yes. The tableviewcells include a few different textviews. It took me a long time to get it this way. I also experimented with webview inside the tableviewcell - it was okay but the selection highlighting didn't work out. I'd have to change the background of the html - which is possible but a pain I think.
-
@cook, the bookmark and follow thread ideas sound great. There really is such a wealth of info on the forum.
Note to @omz (would be great if all searches yielded all results. Of course newbies will keep asking the same questions if they search the forum and no results come back. I am sure many of the questions I have asked before have been answered, but I don't find any reference to them when I search).
@cook, I am not sure that the @ is put to any use in the forum currently. Not to say it won't be, but another possibility for indexing.
For the local data store are you thinking about SQLite or something simpler like pickled dicts?Thanks, finally got the inline Dropbox pics posting worked out :) i will ask you, I have asked here before, but no answers. On iOS what do you use to save titbits of info relating to Python and Pythonista? I can't find a decent if any snippet manager. I have dash, can't save snippets in it directly, I have Evernote, OneNote and many others. None really do it for me. I have tried using textexpander in pythonista, but it's a hit and miss thing (unless there is a magic setting I missed). Anyway, if you use something to help you remember all the stuff you are learning, I would be great full to hear about it.
Yes, I also found out about the magic tableview cells :) subtitle, Value1, Value2. Is nice what you can do, I also had problems with the hilighting once I started added my own objects to the content_view of the cell. It was not important at the time, but will be soon. Not sure you know or are interested, but you are called back often to create cells. I thought it was being all buffered internally, asked to create the cell once. I was doing so tests yesterday with sections and printing out the section,row when I was called to make a cell. It's a good thing, I just didn't think it worked that way.
Again, if I can help in my limited capacity , please let me know.For now, I will continue with the interface around omz scraping code. It's very different from what you are doing. I am using it all the time here now. I will add a create new file also to a particular directory rather than just the copy to clipboard. The copy to clipboard is almost useless if you can write it straight to a file.
Thanks again for your reply.
-
@Phuket2
I will use SQLite. At first when I was learning I tried pickle, but SQLite is better in many ways! And it's not too difficult!I do have a thought about having data stored externally- and this would give a kind of "buffer" for the RSS data, and perhaps even a method of retrieving other information (like the thread url.) anyway- it would certainly solve the issue of having a limited RSS feed. Alternatively omz could change the feed to have more entries!
I also thought about @name mentions being useful in this thing, but for having 20 entries to read through, it may not be a big deal yet!
I currently don't store any snippets or notes about what I learn. I suppose I should!! There are many times that I'm typing out the same thing- but I guess that helps me remember it better too.
What could be done is an easy action extension that stores snippets (with SQLite) and then pulls them up in a tableview. When selecting a cell it inserts where your curser is. Check out editor module for that bit. You could even make it fancy with some categories!I'm not really sure what you mean about tableviewcell subtitle, value1, value 2....something I haven't seen. Do you have an example.
I just know I can set a simple label like <code>cell.text_label.text = ''</code>
If I could do a subtitle that'd be great!Also, in case you ever forget again- here's an easy way to remember how to put in your Dropbox inline image in markdown. That is- don't remember!!:
<pre><code>
import re
import clipboarda = clipboard.get()
if 'dropbox' in a:
a = '' % re.sub('dl=0','raw=1',a)
clipboard.set(a)
</code></pre>If you're really stuck in the future, you can get shirts printed with the text on it: ?raw=1
Should get some good attention! -
@cook
Yes, sure I agree SQLite is more flexible than pickle. Yes, I think SQLite is pretty easy also. But pickle serves a particular purpose as does a database. In my movie app I am making for my friend, I am just using pickle. Basically static lists of dicts. They are not huge, also they don't need updates , inserts etc. I will need to update his data from time to time, but I will just rewrite the whole file. Is super fast. I will also have a few dynamic files, but again, small and very quick. But of course scalability is an issue also. For the app I am doing, scalability is not an issue with the text data.the @name would be still useful if you are storing post entries. So if nothing was to change with the 20 items returned from the RSS feed, day one you have 20 items, day2 you have day 1 + the additional items and so on.. Hmmm, given you run your code often enough :) but, same as the movie, field of dreams, you build it they will come :) I am sure this will be overcome given the demand is there.
I see what you are saying about the snippets. For some reason, does not turn me on writing my own solution. There must be a app out there that can do it. Thanks for the code for Dropbox. I will copy it into OneNote, which is the latest thing I am trying for note taking about pythonista and python. :(
With the tableview, yes you can do a subtitle. I am not sure if you are using the standard ListDataSource or providing your own data_source. But once you have the hang of it, it's easy. I will follow up this post with an example.
-
@cook, I hope this example makes sense. Again, I am not sure how you are using tableview. This is a stupid example, but just to illustrate. I have copied all the methods into my custom class for the tableview's data_source and delegate. Just to be complete. But 90% of the code is not required for this simple example. Anyway, I hope it helps.
import ui, console class TestTableView(ui.View): def __init__(self): # crap data for the tableview self.data = range(100) #create tableview tv = ui.TableView() tv.name = 'tv' # name param does not work # the data/delagate methods called by # tableview will be called in this class tv.data_source = self tv.delegate = self # add the table self.add_subview(tv) def layout(self): self['tv'].frame = self.bounds # prototype methods copied from pytonista help file 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(self.data) def tableview_cell_for_row(self, tableview, section, row): # Create and return a cell for the given section/row # IMPORTANT # ui.TableViewCell() has 4 params # empty = default # subtitle # value1 # value2 # beware, if you create a cell with no params # the default, cell.detail_text_label does # not exist and will produce an error if # you try and reference it! the other cell # types subtitle, value1, value2 have the # cell.detail_text_label. # you can also mix cell types, if it makes # sense. cell = ui.TableViewCell('subtitle') cell.text_label.text = 'row {}'.format(row) cell.detail_text_label.text = '{}'.format(row * 10) 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. #return 'Some Section' pass 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 # delegate method prototypes, copied from #pythonista help files def tableview_did_select(self, tableview, section, row): # Called when a row was selected. console.hud_alert('Row {} selected'.format(self.data[row]), duration = 1) #pass def tableview_did_deselect(self, tableview, section, row): # Called when a row was de-selected (in multiple selection mode). pass def tableview_title_for_delete_button(self, tableview, section, row): # Return the title for the 'swipe-to-***' button. return 'Delete' if __name__ == '__main__': ttv = TestTableView().present()
-
@cook, same example as above but with all the non required methods taken out. The above looks messy. A lot of comments and methods that don't need to be called.
One great thing I learned from @omz by mistake was setting the data_source and delegate to self in a custom class rather than writing explicit data_source and delegate objects. I think those with a greater understanding of Python than me would have got that, maybe you did also. I didn't. But makes supporting a tableview very simple. It's not to say to create those objects are difficult, but you end up passing data around and the more code you get, it seems more complicated. In actual fact, I don't think it is, just it feels that way. I don't know how many files you have in your project now, but is it getting overwhelming ? My projects have been overwhelming me. But, it's more about my approach and understanding. Long ago, I have written very big projects. Mixture of languages. We were not great at it, but for the times we were ok. Now i am struggling to keep everything together with very small apps. But as each day passes, learn more and more.
I find python very difficult in a sense. In c, you Learn to do things in a certain way and get used to it. Granted, the biggest problem can be that's it's hard to impossible for other programmers to read your code. I loved pointers in c, never used subscripts unless I had to. Python seems so powerful, at so many levels. But the felixibily of Python is somewhat scary. Maybe it sounds strange, given it calls c Libs, but I think python would scare a lot of c programmers at first. Well, that's what I think anyway.
import ui, console class TestTableView(ui.View): def __init__(self): # crap data for the tableview self.data = range(100) #create tableview tv = ui.TableView() tv.name = 'tv' # name param does not work # the data/delagate methods called by # tableview will be called in this class tv.data_source = self tv.delegate = self # add the table self.add_subview(tv) def layout(self): self['tv'].frame = self.bounds def tableview_number_of_rows(self, tableview, section): return len(self.data) def tableview_cell_for_row(self, tableview, section, row): cell = ui.TableViewCell('subtitle') cell.text_label.text = 'row {}'.format(row) cell.detail_text_label.text = '{}'.format(row * 10) return cell def tableview_did_select(self, tableview, section, row): console.hud_alert('Row {} selected'.format(self.data[row]), duration = 1) if __name__ == '__main__': ttv = TestTableView().present('sheet')