/
Preferences.py
251 lines (236 loc) · 8.83 KB
/
Preferences.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
"""
Preferences.py
Created by SharpDevelop.
User: Stonepaw
"""
import clr
clr.AddReference("System.Drawing")
import System.Drawing
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms
from System.Drawing import *
from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon, Form, DialogResult
import Progress
from inputbox import InputBox
class Preferences(Form):
def __init__(self, settings, clist):
self.settings = settings
self.ComicList = clist
self.InitializeComponent()
self._backWorker = System.ComponentModel.BackgroundWorker()
#
# backWorker
#
self._backWorker.DoWork += self.BackWorkerDoWork
self._backWorker.RunWorkerCompleted += self.BackWorkerCompleted
#
#Putting this stuff here since otherwise Sharpdevelop's form designer doesn't work
self._displayCovers.Checked = self.settings.DisplayCovers
self._downloadCovers.Checked = self.settings.DownloadCovers
self._displayPublisher.Checked = self.settings.DisplayPublisher
self._displayPrice.Checked = self.settings.DisplayPrice
for listitem in self.settings.BlackList:
self._blacklistdisplay.Items.Add(listitem)
def InitializeComponent(self):
self._groupBox1 = System.Windows.Forms.GroupBox()
self._downloadCovers = System.Windows.Forms.CheckBox()
self._displayCovers = System.Windows.Forms.CheckBox()
self._blacklistdisplay = System.Windows.Forms.ListBox()
self._blacklist = System.Windows.Forms.GroupBox()
self._Add = System.Windows.Forms.Button()
self._remove = System.Windows.Forms.Button()
self._Data = System.Windows.Forms.GroupBox()
self._deletealldata = System.Windows.Forms.Button()
self._apply = System.Windows.Forms.Button()
self._displayPrice = System.Windows.Forms.CheckBox()
self._displayPublisher = System.Windows.Forms.CheckBox()
self._groupBox1.SuspendLayout()
self._blacklist.SuspendLayout()
self._Data.SuspendLayout()
self.SuspendLayout()
#
# groupBox1
#
self._groupBox1.Controls.Add(self._displayPublisher)
self._groupBox1.Controls.Add(self._displayPrice)
self._groupBox1.Controls.Add(self._displayCovers)
self._groupBox1.Controls.Add(self._downloadCovers)
self._groupBox1.Location = System.Drawing.Point(12, 12)
self._groupBox1.Name = "groupBox1"
self._groupBox1.Size = System.Drawing.Size(374, 88)
self._groupBox1.TabIndex = 0
self._groupBox1.TabStop = False
self._groupBox1.Text = "Cover Images"
#
# downloadCovers
#
self._downloadCovers.AutoSize = True
self._downloadCovers.Location = System.Drawing.Point(6, 36)
self._downloadCovers.Name = "downloadCovers"
self._downloadCovers.Size = System.Drawing.Size(110, 17)
self._downloadCovers.TabIndex = 0
self._downloadCovers.Text = "Download Covers"
self._downloadCovers.UseVisualStyleBackColor = True
#
# displayCovers
#
self._displayCovers.Location = System.Drawing.Point(138, 19)
self._displayCovers.Name = "displayCovers"
self._displayCovers.Size = System.Drawing.Size(104, 24)
self._displayCovers.TabIndex = 1
self._displayCovers.Text = "Display Covers"
self._displayCovers.UseVisualStyleBackColor = True
#
# blacklistdisplay
#
self._blacklistdisplay.FormattingEnabled = True
self._blacklistdisplay.Location = System.Drawing.Point(6, 19)
self._blacklistdisplay.Name = "blacklistdisplay"
self._blacklistdisplay.Size = System.Drawing.Size(260, 186)
self._blacklistdisplay.Sorted = True
self._blacklistdisplay.TabIndex = 1
self._blacklistdisplay.MouseDoubleClick += self.RemoveItem
#
# blacklist
#
self._blacklist.Controls.Add(self._remove)
self._blacklist.Controls.Add(self._Add)
self._blacklist.Controls.Add(self._blacklistdisplay)
self._blacklist.ForeColor = System.Drawing.SystemColors.ControlText
self._blacklist.Location = System.Drawing.Point(12, 107)
self._blacklist.Name = "blacklist"
self._blacklist.Size = System.Drawing.Size(374, 216)
self._blacklist.TabIndex = 2
self._blacklist.TabStop = False
self._blacklist.Text = "Blacklist"
#
# Add
#
self._Add.Location = System.Drawing.Point(283, 49)
self._Add.Name = "Add"
self._Add.Size = System.Drawing.Size(75, 23)
self._Add.TabIndex = 2
self._Add.Text = "Add"
self._Add.UseVisualStyleBackColor = True
self._Add.Click += self.AddItem
#
# remove
#
self._remove.Location = System.Drawing.Point(283, 149)
self._remove.Name = "remove"
self._remove.Size = System.Drawing.Size(75, 23)
self._remove.TabIndex = 3
self._remove.Text = "Remove"
self._remove.UseVisualStyleBackColor = True
self._remove.MouseClick += self.RemoveItem
#
# Data
#
self._Data.Controls.Add(self._deletealldata)
self._Data.Location = System.Drawing.Point(13, 330)
self._Data.Name = "Data"
self._Data.Size = System.Drawing.Size(373, 57)
self._Data.TabIndex = 3
self._Data.TabStop = False
self._Data.Text = "Data"
#
# deletealldata
#
self._deletealldata.AutoSize = True
self._deletealldata.ForeColor = System.Drawing.Color.Red
self._deletealldata.Location = System.Drawing.Point(111, 17)
self._deletealldata.Name = "deletealldata"
self._deletealldata.Size = System.Drawing.Size(151, 23)
self._deletealldata.TabIndex = 0
self._deletealldata.Text = "Delete All Downloaded Data"
self._deletealldata.UseVisualStyleBackColor = True
self._deletealldata.Click += self.DeletealldataClick
#
# apply
#
self._apply.DialogResult = System.Windows.Forms.DialogResult.OK
self._apply.Location = System.Drawing.Point(311, 402)
self._apply.Name = "apply"
self._apply.Size = System.Drawing.Size(75, 23)
self._apply.TabIndex = 4
self._apply.Text = "Done"
self._apply.UseVisualStyleBackColor = True
self._apply.Click += self.ApplyClick
#
# displayPrice
#
self._displayPrice.Location = System.Drawing.Point(264, 19)
self._displayPrice.Name = "displayPrice"
self._displayPrice.Size = System.Drawing.Size(104, 24)
self._displayPrice.TabIndex = 2
self._displayPrice.Text = "Display Price"
self._displayPrice.UseVisualStyleBackColor = True
#
# displayPublisher
#
self._displayPublisher.AutoSize = True
self._displayPublisher.Location = System.Drawing.Point(138, 57)
self._displayPublisher.Name = "displayPublisher"
self._displayPublisher.Size = System.Drawing.Size(106, 17)
self._displayPublisher.TabIndex = 3
self._displayPublisher.Text = "Display Publisher"
self._displayPublisher.UseVisualStyleBackColor = True
#
# Preferences
#
self.AcceptButton = self._apply
self.ClientSize = System.Drawing.Size(397, 437)
self.Controls.Add(self._apply)
self.Controls.Add(self._Data)
self.Controls.Add(self._blacklist)
self.Controls.Add(self._groupBox1)
self.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
self.Name = "Preferences"
self.ShowIcon = False
self.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
self.Text = "Preferences"
self._groupBox1.ResumeLayout(False)
self._groupBox1.PerformLayout()
self._blacklist.ResumeLayout(False)
self._Data.ResumeLayout(False)
self._Data.PerformLayout()
self.ResumeLayout(False)
def DeletealldataClick(self, sender, e):
result = MessageBox.Show("Are you absolutely sure you want to delete all the downloaded data?", "Delete all data", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
if result == DialogResult.Yes:
#MessageBox.Show("Not yet implemented")
#print self.Owner
self.p = Progress.Progress()
self.p.Text = "Deleting all downloaded data. Please wait...."
self.p.Show()
self._backWorker.RunWorkerAsync()
def ApplyClick(self, sender, e):
self.settings.DisplayCovers = self._displayCovers.Checked
self.settings.DownloadCovers = self._downloadCovers.Checked
self.settings.BlackList = list(self._blacklistdisplay.Items)
self.settings.DisplayPrice = self._displayPrice.Checked
self.settings.DisplayPublisher = self._displayPublisher.Checked
print self.settings.BlackList
def RemoveItem(self, sender, e):
if not self._blacklistdisplay.SelectedIndex == -1:
self._blacklistdisplay.Items.RemoveAt(self._blacklistdisplay.SelectedIndex)
def AddItem(self, sender, e):
input = InputBox()
result = input.ShowDialog()
if result == DialogResult.OK:
text = input._textBox.Text
if text:
mesgresult = MessageBox.Show(text + " will be added to the BlackList.\n\nWould you also like to remove any occurences of this publisher from the already downloaded data?\n\n(Clicking Cancel will not add this publisher to the BlackList)", "Delete existing?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
if mesgresult == DialogResult.Yes:
self._blacklistdisplay.Items.Add(text)
self.ComicList.RemovePublisher(text)
elif mesgresult == DialogResult.No:
self._blacklistdisplay.Items.Add(text)
input.Dispose()
#print input
#MessageBox.Show("Not yet implemented")
def BackWorkerDoWork(self, sender, e):
self.ComicList.DeleteAll()
def BackWorkerCompleted(self, sender, e):
self.p.Close()
self.p.Dispose()