Placeholder Image

字幕列表 影片播放

  • what's going on?

  • Everybody.

  • And welcome to part four of the key V tutorials in this video we're gonna be talking about is scheduling things.

  • So up to this point we've been talking about you know, how you can change screen and how you can have button events and how a button event could change the screen.

  • But they're going to be times where you just simply want to control a changed screen or other things in general.

  • So we know how to use events to make things happen.

  • Now we want to talk about is having to just schedule a thing to happen either one time or on some sort of cycle going into the future.

  • So to do that, we're gonna use the TV clock.

  • So it's just from K v dot clock.

  • We're gonna import clock now.

  • The other thing that we're gonna go ahead and do is take the socket code from the socket tutorial on.

  • Just put that in our directory here.

  • So I'm gonna go ahead and make two new files.

  • One is gonna be socket client dot pie.

  • Yes, and the other is going to be socket server.

  • Don't buy the code for both of these is hosted on python pregnant and that I'll put links in the description.

  • If you want to learn more about sockets again, go to the sockets tutorial because this whole thing is all you know, completely explains.

  • So, like, socket server dot pie.

  • All of this code is just a direct copy and paste from the tutorial code from there.

  • So I'm not gonna go over that twice S o socket server.

  • DuPuy me open that pasta.

  • That and then the stock it client dot pie is pretty much the same.

  • There's a few small changes, but nothing that should be confusing to anybody that's gone through the Siri's anyways.

  • So I'm gonna paste in that.

  • And that's what we're going to use just for handling the socket stuff.

  • Because this is just a key bees tutorial where I'm just trying to show the you and how to do TV stuff.

  • Not really tryingto go over sockets again.

  • So anyway, uh, cool.

  • So we've got that stuff now we want to do is basically when someone connects right now we do this.

  • We show the info screen, and then after the info screen is when we want to eventually change the screen to the actual chat screen unless we throw in there.

  • So we're gonna show the info screen.

  • And then what we want to do is we're going to say, um, clock.

  • Actually, it's camp Lissy clock Don't schedule should June once.

  • And then what's the thing we want to schedule and then, like, how?

  • How many seconds in the future do we want to schedule that?

  • So in this case, that'll be self dot connect, and we'll just do it one second into the future.

  • Cool.

  • Once we've done that, we need to, But one We have to have this connect method that would probably be somewhat useful.

  • So just we're gonna add this connect method literally on the connect page.

  • So it's just a new method runner on ether joined, but him.

  • So we're, say, define connects Thean stints, and then we're going to use an underscore here.

  • The underscore is basically, anytime you schedule something, it's gonna pass to thing's gonna pass the instance.

  • But it's also gonna pass How many seconds has gone by transpired since the schedule.

  • So in this case, it'll be one, and it will always be one because we're scheduling once, but sometimes you're gonna schedule in a cycle.

  • And it might be useful to know how long it's been since that scheduling.

  • Okay, so anyway, that gets passed.

  • We don't need it, though, So underscore to denote it's useless info to us.

  • Now, what we're gonna do is we're gonna set up the values for poor Rypien user name.

  • So port is just gonna be an integer of self dot port dot text.

  • The i p will be self doubt.

  • I p dot text and the user name will be self dot user name dot text and then we wanted to connect.

  • So the first thing I'm gonna d'oh before we do that is come over here and we're going to import socket underscore client.

  • And just for the record, socket client imports the service stuff, so we don't really need to do anything there, Um and actually really, the service's runs.

  • So we're gonna import socket client.

  • Um, and that should run all the socket stuff.

  • So we're never going to really need to touch sockets other than for handle air handling.

  • Rather, um, coming back down here.

  • Where was connect?

  • So now we want to Dio is attempt to connect, but also handle for errors if for whatever reason, we don't connect.

  • So, uh, we're going to say if not socket underscore client dot connects I p poor user name and then show error will be our error method here.

  • So, um, if not, we're just going to simply return.

  • So we actually we scheduled this connection we return if nothing works.

  • So we're done with the connect method and basically show error, we're gonna create that in a man.

  • What that's gonna do is update our info page.

  • So our info page will show the error if, for whatever reason, we're unable to connect, so we return.

  • But if we do, if we are able to connect because this check basically connects us if we are able to connect, what do we want to d'oh?

  • Well, if we are able to connect, then what we're gonna say is chat app dot creek eight shat page doesn't quite yet exist, but we'll make it and then shat app dot screen manager dot current here appearance.

  • There we go equals chat with a capital C.

  • Okay, so now we want to do is we need to create this method to create chat page method inside of our epic app.

  • So we'll just add that down here now.

  • The reason why we don't want to make this like you could build it here.

  • But the problem is when we make our or chat app or chat page, let's see if I could speak this morning or chat.

  • Page is listening for these connections and but until we actually try to connect, right, we can't listen for these connections.

  • So first we have to do this.

  • Then we can do this bit so we only really want toe Add this page for riel once we've connected already.

  • Okay, hopefully that makes sense if it doesn't feel free to ask.

  • But basically, as soon as we initially assumes we create this page, it's gonna be listening for connections which we can't do until we've connected.

  • Cool makes sense to me.

  • Anyways, hopefully you guys understand.

  • So now we want to say is defined.

  • Create shat, uh, Paige self and what we want to do is basically the same stuff that we've done before.

  • So chat Page will equal chat lips Chat page, which we also need to create, but we'll get there.

  • Uh, there were just a screen equals screen.

  • Uh, group's name, name equals chat.

  • Uh, then what we want to say is screen dot ad underscore widget self dot page and then self dot screen manager dot ad widgets screen.

  • So, even though it's kind of, in its own method, its exact same pattern that we've had up here and again, we're just separating it out because we have to connect before we can run this.

  • But as soon as we connect, then we basically run this method that adds it to our list of possible screens.

  • So it's still at this point we could switch to the info or even the connect screen if we wanted, or any other screen that we want to add later.

  • We just need to run this.

  • We can't run this at the same time as we run these unless we connected immediately.

  • But then it wouldn't make sense toe filling the format when we would.

  • You ever do that?

  • Anyway, I think you guys get it.

  • So, uh, info page soldiers add chat page really anywhere.

  • Um, so will call this class.

  • Chat page and chat page will also be a grid lay outs.

  • And for now, let's just you want copy pasta del Cool.

  • Um, I want to do is just add a quick label.

  • So I'm just gonna say, self dot ad widget, uh, label, and we'll throw in some text.

  • Hey, at least it works up to this point.

  • That's always the goal.

  • Okay, so the last thing we need to do is probably error.

  • Yeah, So we need to do the show error.

  • Um, that could just be really anywhere, eh?

  • So I'm just gonna throw that down here, and that's gonna be defined.

  • Show a roar, whatever that their message is, and then chat app dot info info page dot update underscore info.

  • Message.

  • Shat app dot screen underscore ir manager dot Current Just in case it's not on the info page.

  • Uh, at the moment, it should actually be on the info page.

  • Actually, pride, you want those spaces?

  • It should be on the info page, but later something else might happen.

  • Like maybe while you're chatting, you lose internet or something.

  • We We lost the socket.

  • We throw in air.

  • We want to go back to that info page.

  • So we're just kind of making sure we're on that info page.

  • And then, um really, you could hold there, but then there's really nothing for anybody else to do.

  • So what we're gonna say here is clocked on schedule.

  • Underscore Once will do.

  • Assist our exit, and we'll do that in 10 seconds.

  • Uh, do we have sis imported?

  • No.

  • So also for obsess.

  • Great.

  • Okay, that's a lot of code that we've just thrown together.

  • So let's see if it works.

  • Quick guests of how many typos I've made Pedestrian key V at 1234 Come on, we can do it.

  • Okay, so Oh, well, well, first of all, let's go and just try.

  • Right?

  • So we get our error because we're not actually running the server.

  • Okay, so at least we know the air message works.

  • I just hit my escape key.

  • By the way, uh, now we want to do is let's go ahead and run the socket server soap.

  • I dash 37 socket server ID up high, listening for connections on local host.

  • 1234 And let's try to run our TV app whom moss Una vez mas.

  • Anyway, we'll hit join hey at least it worked up to this point.

  • So we made her connection all that.

  • We're on our chat page, and now we just need to simply build out the chat page.

  • So that's what we're gonna be doing in the next two Torrey A ll.

  • Questions, comments, concerns, whatever.

  • Feel free leaving below.

  • If you wantto support the channel, support what I do.

  • You like tutorials like this.

  • Check out that beautiful, beautiful blue join button.

  • Get access to tutorials in advance.

  • Get awesome shadows.

  • Good to hear your awesome from me.

  • All that fun stuff.

  • So, anyways, uh, yeah.

  • Questions, comments, concerns, suggestions, Whatever you're feeling below.

  • Otherwise I'll see you guys in the next video.

what's going on?

字幕與單字

影片操作 你可以在這邊進行「影片」的調整,以及「字幕」的顯示

B1 中級

調度任務/功能/方法 - Kivy移動和桌面應用開發/Python (Scheduling tasks/functions/methods - Kivy Mobile and Desktop App Dev w/ Python)

  • 0 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字