diff --git a/src/controller/attach.py b/src/controller/attach.py index f272844..b0cceea 100644 --- a/src/controller/attach.py +++ b/src/controller/attach.py @@ -8,6 +8,7 @@ class attach(object): self.attachments = list() self.dialog = gui.attachDialog() widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.upload_image) + widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment) self.dialog.get_response() def upload_image(self, *args, **kwargs): @@ -15,4 +16,16 @@ class attach(object): if image != None: self.attachments.append({"type": "photo", "file": image, "description": os.path.basename(image)}) info = [_(u"Photo"), os.path.basename(image)] - self.dialog.attachments.insert_item(False, *info) \ No newline at end of file + self.dialog.attachments.insert_item(False, *info) + self.dialog.remove.Enable(True) + + def remove_attachment(self, *args, **kwargs): + current_item = self.dialog.attachments.get_selected() + if current_item == -1: current_item = 0 + self.attachments.pop(current_item) + self.dialog.attachments.remove_item(current_item) + self.check_remove_status() + + def check_remove_status(self): + if len(self.attachments) == 0 and self.dialog.attachments.get_count() == 0: + self.dialog.remove.Enable(False) diff --git a/src/wxUI/dialogs/attach.py b/src/wxUI/dialogs/attach.py index 1a758cf..eee7ed8 100644 --- a/src/wxUI/dialogs/attach.py +++ b/src/wxUI/dialogs/attach.py @@ -15,6 +15,8 @@ class attachDialog(widgetUtils.BaseDialog): sizer.Add(box, 0, wx.ALL, 5) static = wx.StaticBox(panel, label=_(u"Add attachments")) self.photo = wx.Button(panel, wx.NewId(), _(u"&Photo")) + self.remove = wx.Button(panel, wx.NewId(), _(u"Remove attachment")) + self.remove.Enable(False) btnsizer = wx.StaticBoxSizer(static, wx.HORIZONTAL) btnsizer.Add(self.photo, 0, wx.ALL, 5) sizer.Add(btnsizer, 0, wx.ALL, 5)