0
1
00:00:04,880 --> 00:00:06,810
<v ->Hello again, in previous lecture, what we did,</v>
1

2
00:00:06,810 --> 00:00:09,390
let me run our application first.
2

3
00:00:09,390 --> 00:00:11,960
Here we created our file.
3

4
00:00:11,960 --> 00:00:15,230
And also, open a menu item of function, right.
4

5
00:00:15,230 --> 00:00:16,820
And in this lesson, what I want to do,
5

6
00:00:16,820 --> 00:00:21,220
I want to create function for this, save menu item.
6

7
00:00:21,220 --> 00:00:23,530
What I need to do, now before I need to go to
7

8
00:00:23,530 --> 00:00:26,560
find my menu item, it's main menu
8

9
00:00:26,560 --> 00:00:28,820
and here, right, save.
9

10
00:00:28,820 --> 00:00:32,060
Here, I will say comma and I will create
10

11
00:00:32,060 --> 00:00:35,010
command property for this menu item.
11

12
00:00:35,010 --> 00:00:40,010
And I will say self.parent.saveFile.
12

13
00:00:40,240 --> 00:00:42,310
Okay, and here, what I need to do,
13

14
00:00:42,310 --> 00:00:45,410
I need to create this definition.
14

15
00:00:45,410 --> 00:00:49,220
I will go to do here main application
15

16
00:00:49,220 --> 00:00:51,480
and before, open file.
16

17
00:00:51,480 --> 00:00:56,480
Here I will say def saveFile and first argument
17

18
00:00:57,260 --> 00:01:01,590
will be self and other one will be asterisk args, right.
18

19
00:01:01,590 --> 00:01:04,290
And before creating our function,
19

20
00:01:04,290 --> 00:01:06,160
I want to show you something here.
20

21
00:01:06,160 --> 00:01:10,970
I will open original notepad application.
21

22
00:01:10,970 --> 00:01:13,270
Now, this is not bad application, right.
22

23
00:01:13,270 --> 00:01:15,480
We have here two choices, okay.
23

24
00:01:15,480 --> 00:01:17,740
The first one is, for example, if I,
24

25
00:01:17,740 --> 00:01:19,680
let's click file new f--
25

26
00:01:19,680 --> 00:01:21,660
okay, this is a new file.
26

27
00:01:21,660 --> 00:01:25,010
That means this file doesn't have URL, okay.
27

28
00:01:25,010 --> 00:01:26,940
And we didn't save this file.
28

29
00:01:26,940 --> 00:01:29,820
For example, if I change content,
29

30
00:01:29,820 --> 00:01:31,360
content of this file and after that,
30

31
00:01:31,360 --> 00:01:34,580
if I say save, you see, what,
31

32
00:01:34,580 --> 00:01:38,130
what I need to do now here we have dialogue window, right.
32

33
00:01:38,130 --> 00:01:41,500
And we need to save our, our file
33

34
00:01:41,500 --> 00:01:44,940
because this, this file doesn't have URL, right.
34

35
00:01:44,940 --> 00:01:46,290
And I will say cancel.
35

36
00:01:46,290 --> 00:01:49,410
After that, here, I want to open a file
36

37
00:01:49,410 --> 00:01:52,630
from my computer here.
37

38
00:01:52,630 --> 00:01:54,500
Let's say cancel, sorry.
38

39
00:01:54,500 --> 00:01:55,893
And, here,
39

40
00:01:57,380 --> 00:01:58,370
delete this guy.
40

41
00:01:58,370 --> 00:02:01,310
And here, let me say, open, okay.
41

42
00:02:01,310 --> 00:02:04,660
And I will open an existing file from my computer.
42

43
00:02:04,660 --> 00:02:06,750
For example, that one, okay.
43

44
00:02:06,750 --> 00:02:09,750
And let's change this content, okay.
44

45
00:02:09,750 --> 00:02:10,583
This...
45

46
00:02:11,480 --> 00:02:12,500
Something like that, okay.
46

47
00:02:12,500 --> 00:02:15,040
And after that, I will say save.
47

48
00:02:15,040 --> 00:02:18,373
Now, you see, nothing happens and I don't see here
48

49
00:02:18,373 --> 00:02:19,820
a dialogue window.
49

50
00:02:19,820 --> 00:02:20,653
Why's it like that?
50

51
00:02:20,653 --> 00:02:25,653
Because this file is, this file has already a URL.
51

52
00:02:26,120 --> 00:02:29,650
Okay, that's why we don't need to see here dialogue window.
52

53
00:02:29,650 --> 00:02:32,440
Okay, so, what I need to do now here,
53

54
00:02:32,440 --> 00:02:34,660
I will save it again.
54

55
00:02:34,660 --> 00:02:39,370
And go back to here and I need to know
55

56
00:02:39,370 --> 00:02:44,150
My file already has a URL or doesn't have this URL, okay.
56

57
00:02:44,150 --> 00:02:46,750
To that I will say here global URL.
57

58
00:02:46,750 --> 00:02:49,070
I will use my global URL.
58

59
00:02:49,070 --> 00:02:53,153
After that, here try and except, okay.
59

60
00:02:54,550 --> 00:02:56,713
For except, for now let's say pass.
60

61
00:02:57,579 --> 00:02:59,670
Okay, for try, what I need to do,
61

62
00:02:59,670 --> 00:03:04,670
firstly, I will say if URL not equals empty.
62

63
00:03:05,880 --> 00:03:10,310
That means this file already in,
63

64
00:03:10,310 --> 00:03:11,400
on my computer, okay.
64

65
00:03:11,400 --> 00:03:13,910
This is an existing file, okay.
65

66
00:03:13,910 --> 00:03:16,140
And here, what I need to do, I need to create here
66

67
00:03:16,140 --> 00:03:19,590
a variable, content variable and I will say str
67

68
00:03:20,610 --> 00:03:25,510
self.texteditor.get, I will get all content
68

69
00:03:25,510 --> 00:03:29,450
off my text editor from first character until end.
69

70
00:03:29,450 --> 00:03:32,470
Okay, and after that here, what I need to do,
70

71
00:03:32,470 --> 00:03:37,470
I need to say with open and here I will use URL.
71

72
00:03:41,300 --> 00:03:46,100
And after that, second parameter will be write mode, okay.
72

73
00:03:46,100 --> 00:03:47,640
And also I want to use encoding here.
73

74
00:03:47,640 --> 00:03:52,640
Encoding equals UTF dash eight, okay.
74

75
00:03:54,420 --> 00:03:56,260
And after that, what I need to do here,
75

76
00:03:56,260 --> 00:03:59,710
I need to say, as file, right.
76

77
00:03:59,710 --> 00:04:04,710
And here I will say file.right my content.
77

78
00:04:05,870 --> 00:04:09,293
So, what I'm doing here, let me run our application first.
78

79
00:04:11,960 --> 00:04:14,090
Here, I need to open a file, right,
79

80
00:04:14,090 --> 00:04:18,460
and let me resize my application here.
80

81
00:04:18,460 --> 00:04:19,610
I will open a file.
81

82
00:04:19,610 --> 00:04:20,893
Let's say open.
82

83
00:04:22,190 --> 00:04:23,660
And let's open that one, okay.
83

84
00:04:23,660 --> 00:04:24,850
For example.
84

85
00:04:24,850 --> 00:04:26,890
And this is my file.
85

86
00:04:26,890 --> 00:04:28,380
Now, if I want to save it,
86

87
00:04:28,380 --> 00:04:30,503
what I am doing here, firstly,
87

88
00:04:30,503 --> 00:04:33,740
I will get this content, okay
88

89
00:04:33,740 --> 00:04:37,310
and after that, I will overwrite this file
89

90
00:04:37,310 --> 00:04:39,500
for this URL, okay.
90

91
00:04:39,500 --> 00:04:41,373
And then I say save.
91

92
00:04:42,490 --> 00:04:46,200
Now, my file was aaa.txt, right.
92

93
00:04:46,200 --> 00:04:47,360
If I say, open...
93

94
00:04:50,350 --> 00:04:52,810
You see now, hello, how are you, python.
94

95
00:04:52,810 --> 00:04:54,950
And this is my content, okay.
95

96
00:04:54,950 --> 00:04:59,790
So, this is for if our file has URL
96

97
00:04:59,790 --> 00:05:02,330
and other option was, right,
97

98
00:05:02,330 --> 00:05:05,073
it, I need to say here, else.
98

99
00:05:06,230 --> 00:05:08,550
Else means my file is a new file
99

100
00:05:08,550 --> 00:05:10,780
and doesn't have URL, okay.
100

101
00:05:10,780 --> 00:05:13,440
So, I will say here, URL equals,
101

102
00:05:13,440 --> 00:05:16,170
what I need to do, I need to use file dialogue, right.
102

103
00:05:16,170 --> 00:05:19,509
File dialogue and here I will say,
103

104
00:05:19,509 --> 00:05:22,160
ask save as file, right.
104

105
00:05:22,160 --> 00:05:24,800
And the first parameter will be my mode.
105

106
00:05:24,800 --> 00:05:28,520
Mode will be W mode, writing, okay.
106

107
00:05:28,520 --> 00:05:31,203
And after, after that, the other one
107

108
00:05:31,203 --> 00:05:35,760
will be default extension, okay.
108

109
00:05:35,760 --> 00:05:38,080
The default extension is going to be
109

110
00:05:39,770 --> 00:05:42,790
dot txt, okay?
110

111
00:05:42,790 --> 00:05:44,907
And after that, what I'm doing here,
111

112
00:05:44,907 --> 00:05:48,710
I will say comma and I will press enter here.
112

113
00:05:48,710 --> 00:05:53,710
And I will say file types, types
113

114
00:05:53,740 --> 00:05:56,700
equals, here I will use parentheses.
114

115
00:05:56,700 --> 00:05:59,640
Okay, and the first one is going
115

116
00:05:59,640 --> 00:06:01,840
to be my text file extension.
116

117
00:06:01,840 --> 00:06:06,803
Here, I will say, quote text file,
117

118
00:06:08,700 --> 00:06:11,623
for text file, I will use, of course,
118

119
00:06:12,770 --> 00:06:16,560
asterisk dot txt, this is my extension.
119

120
00:06:16,560 --> 00:06:18,153
And second one will be,
120

121
00:06:20,040 --> 00:06:22,220
here I will use another parentheses
121

122
00:06:22,220 --> 00:06:24,933
and quotes all files, okay.
122

123
00:06:26,070 --> 00:06:28,720
And here, what I will do here, again,
123

124
00:06:28,720 --> 00:06:33,720
comma and quotes, I will say, asterisk dot asterisk.
124

125
00:06:35,423 --> 00:06:36,256
Okay.
125

126
00:06:36,256 --> 00:06:39,210
What I need to do now, here after that,
126

127
00:06:39,210 --> 00:06:42,083
I will come to here and I will create another content.
127

128
00:06:43,769 --> 00:06:47,686
Content2 is going to be str self.texteditor.get
128

129
00:06:55,960 --> 00:06:59,600
from first until end, okay.
129

130
00:06:59,600 --> 00:07:03,723
And here, I need to say URL.right
130

131
00:07:05,890 --> 00:07:10,550
my content2, okay and also after that,
131

132
00:07:10,550 --> 00:07:15,360
I need to say URL.close, okay.
132

133
00:07:15,360 --> 00:07:18,230
Now, here also for except, what I need to do,
133

134
00:07:18,230 --> 00:07:23,230
if user doesn't select a file, I will say here,
134

135
00:07:23,370 --> 00:07:25,090
simply return, okay.
135

136
00:07:25,090 --> 00:07:28,280
Like before here, we also used return, remember.
136

137
00:07:28,280 --> 00:07:30,143
Now, if I run my application,
137

138
00:07:31,718 --> 00:07:34,850
we already checked for existing files, right.
138

139
00:07:34,850 --> 00:07:36,350
Now, I will create a new file.
139

140
00:07:36,350 --> 00:07:37,910
Actually, this is also a new file.
140

141
00:07:37,910 --> 00:07:39,050
It doesn't have URL.
141

142
00:07:39,050 --> 00:07:41,200
But also, let's create a new one.
142

143
00:07:41,200 --> 00:07:43,030
So, this is a new one.
143

144
00:07:43,030 --> 00:07:46,263
And, even, let's say something like,
144

145
00:07:47,560 --> 00:07:50,893
hi, how are you today?
145

146
00:07:51,980 --> 00:07:53,370
Something like that, okay.
146

147
00:07:53,370 --> 00:07:54,930
Now, I will save it.
147

148
00:07:54,930 --> 00:07:56,560
Save file.
148

149
00:07:56,560 --> 00:07:59,120
And after that save, right,
149

150
00:07:59,120 --> 00:08:01,130
you see this is our dialogue window?
150

151
00:08:01,130 --> 00:08:05,270
And now I will name it and lets say new file.
151

152
00:08:06,650 --> 00:08:08,240
Something like that, okay.
152

153
00:08:08,240 --> 00:08:11,890
And now I saved it and let's go to open it now.
153

154
00:08:11,890 --> 00:08:12,723
Open.
154

155
00:08:14,010 --> 00:08:16,700
New file, right, it was new file.
155

156
00:08:16,700 --> 00:08:20,420
As you see now, it said, hi, how are you today?
156

157
00:08:20,420 --> 00:08:23,910
This is how we can use save file dialogue for our files.
157

158
00:08:23,910 --> 00:08:25,570
for now, that's all.
158

159
00:08:25,570 --> 00:08:26,563
See you next.
