omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. meleyz

    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.


    • Profile
    • Following 1
    • Followers 0
    • Topics 1
    • Posts 11
    • Best 1
    • Controversial 0
    • Groups 0

    meleyz

    @meleyz

    1
    Reputation
    678
    Profile views
    11
    Posts
    0
    Followers
    1
    Following
    Joined Last Online

    meleyz Unfollow Follow

    Best posts made by meleyz

    • RE: Not able to output datetime to text view in Ui.

      @Phuket2

      I found the Arrow module to be much easier to use and the documentation was very helpful. I have updated my code using it. Thanks!

      def oTime():
      	return arrow.now().format('MMMM DD, YYYY, h:m:s a')
      
      posted in Pythonista
      meleyz
      meleyz

    Latest posts made by meleyz

    • RE: Not able to output datetime to text view in Ui.

      @JonB
      @Phuket2

      Thank you both for explaining. It has become clear that I misunderstood some of the documentation and have since spent time rereading those documents. I have the code working the way I need it to now however, I have one last question. I was getting the error ‘’str’ object has no attribute ‘superview’’ until I deleted and re added the switch in the ui designer. Was that just a random bug or does that happen frequently with the ui designer? Thanks again for all the help.

      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @Phuket2

      Can you see any obvious reason why the switch isn’t working? I believe I have everything written right (as much as I can see anyways) and the function name is in the ui switch, yet nothing happens when I tap the switch. It only returns b_fmt2 and I can’t figure out why. I’m sure it’s something I should’ve seen by now but anyways, here is my current code.

      import ui
      import arrow
      import appex
      
      # import the proper modules needed to run script
      
      timecard = []
      
      a_fmt1 = 'MMMM DD,YYYY, h:m:s a'
      b_fmt2 = 'MMMM DD, YYYY, HH:mm:ss A'
      
      def switch_1(fmt):
      	while fmt:
      		return arrow.now().format(a_fmt1)
      	else:
      			return arrow.now().format(b_fmt2)
      
      
      
      def clock(sender):
      		v['textview1'].text = v['textview1'].text + 'Time ' + sender.title + ': ' + str(switch_1('')) + '\n'
      
      
      v = ui.load_view()
      v.present('sheet')
      
      # load the UI
      
      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @Phuket2

      I think you answered one of my questions before I even had a chance to ask it. And no it is not over the top it is exactly the type of information I am looking for so thank you! I am trying to add a switch to the UI to change between 24 hour format and regular format however I am getting a type error ‘must be str not function ‘ and I am a little confused. Perhaps I am calling the function incorrectly of I have not used the proper statement. I have tried a for statement as well as a while loop and am seeing 2 different errors. The one I just described and a positional argument error on the oTime function. I will comment in the code which line is returning the type error.

      import ui
      import arrow
      import appex
      import ui
      
      # import the proper modules needed to run script
      
      
      a = arrow.now().format('MMMM DD,YYYY, h:m:s a')
      b = arrow.now().format('MMMM DD, YYYY, HH:mm:ss A')
      
      
      def oTime(self):
      	while oTime(self):
      		return (a)
      	else:
      			return (b)
      		
      
      
      timecard = []
      
      # define a funtion to return the current time and create a container (list) to store current time when buttons are tapped
      
      
      def clock_in(sender):
      	timecard.append(oTime)
      	timecard.append('Clock in successful.')
      	updateTextView()
      
      
      def clock_out(sender):
      	timecard.append(oTime)
      	timecard.append('Clock out successful.')
      	updateTextView()
      
      
      # define funtions for button actions. Note that the funtion call to 'oTime'
      
      
      def updateTextView():
      	t = ''
      	for line in timecard:
      		t = t + line + '\n' # this line is returning the type error must be str not function
      	v['textview1'].text = t
      
      
      # update the textview with the container created in the first function
      
      v = ui.load_view()
      v.present('sheet')
      
      # load the UI
      
      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @Phuket2

      I found the Arrow module to be much easier to use and the documentation was very helpful. I have updated my code using it. Thanks!

      def oTime():
      	return arrow.now().format('MMMM DD, YYYY, h:m:s a')
      
      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @Phuket2
      @cvp

      Thanks! I was actually wondering that myself, about shortening the code that is. And thank you @Phuket2 for the information and documentation link. I have been trying to absorb as much of the documentation as I can and not just assume that it doesn’t explain things. I’ve noticed several posters mention that the documentation falls short however I have noticed that the documentation is actually quite thorough if you take the time to read and really try to comprehend what it is saying. I will definitely take your advice on the functionality aspect and I am also trying to build good habits when writing code (such as proper format and leaving myself comments to remember what I am doing). This is how the code looks now and I am currently researching how to change the datetime output format to improve user friendliness. @cvp I will shorten the codes on the button functions when I get home from work. Thanks again.

      import ui
      import datetime
      import appex
      import ui
      
      # import the proper modules needed to run script
      
      
      def oTime():
      	return format(datetime.datetime.now())
      
      
      timecard = []
      
      # define a funtion to return the current time and create a container (list) to store current time when buttons are tapped
      
      
      def clock_in(sender):
      	timecard.append(oTime())
      	timecard.append('Clock in successful.')
      	updateTextView()
      
      
      def clock_out(sender):
      	timecard.append(oTime())
      	timecard.append('Clock out successful.')
      	updateTextView()
      
      
      # define funtions for button actions. Note that the funtion call to 'oTime'
      
      
      def updateTextView():
      	t = ''
      	for line in timecard:
      		t = t + line + '\n'
      	v['textview1'].text = t
      
      
      # update the textview with the container created in the first function
      
      v = ui.load_view()
      v.present('sheet')
      
      # load the UI
      
      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @cvp

      Wow! Exactly! I have to say that this forum has become my new favorite place. Thank you for being so helpful. I can tell I still have much to learn just by looking at how you wrote the same script that I was trying to write only much more tidy (and it actually works). If I may ask, how long have you been writing code and can you offer any advice as far as a newbie such as myself learning code? I am trying to start with the basics but I find some concepts to be slightly confusing (such as trying to understand the concept of everything being an object). I have always been ‘computer savvy’ but Pythonista is the first and only coding experience I have ever had and I am really enjoying it thus far. I appreciate all the effort that has gone into building such a wonderful support system. Thank you again.

      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @cvp

      I didn’t even notice, thank you! Still no luck however.

      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      @JonB

      Forgive my lack of understanding here as I have only been learning python for about a week now, but you said I was using 2 different variables to define ‘timecard’ but wouldn’t a list be an object and not a variable? Anyways, I’m pretty much dead in the water here because I get what I am looking for in the console however the actual text view itself isnt displaying anything. This is the code I have right now.

      import datetime
      import appex, ui
      
      oTime = datetime.datetime.now()
      timecard = []
      
      def clock_in(sender):
      	timecard.append(oTime)
      	timecard.append('Clock in successful.')
      	
      def clock_out(sender):
      	timecard.append(oTime)
      	timecard.append('Clock out successful.')
      
      def updateTextView(sender):
      	v = sender.superview
      	v['textview1'] = timecard(0,len)
      	print (sender.text)
      	
      v = ui.load_view()
      v.present('sheet')
      
      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      Still no luck getting a result on the text view. This is where I’m at.

      import datetime
      import appex, ui
      
      oTime = datetime.datetime.now()
      timecard = []
      
      def clock_in(sender):
      	timecard.append(oTime)
      	timecard.append('Clock in successful.')
      	
      def clock_out(sender):
      	timecard.append(oTime)
      	timecard.append('Clock out successful.')
      
      def updateTextView():
      	v = sender.superview
      	timecard = v['textview1']
      	timecard.text += ''
      	
      v = ui.load_view()
      v.present('sheet')
      
      posted in Pythonista
      meleyz
      meleyz
    • RE: Not able to output datetime to text view in Ui.

      Ok cool. I will try this out as soon as I can. Thank you. I will post again after my lunch break and let you know if I have any success.

      posted in Pythonista
      meleyz
      meleyz