mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-17 13:46:07 -04:00
Mastodon: Added experimental support for voting in polls
This commit is contained in:
@@ -297,7 +297,7 @@ class poll(wx.Dialog):
|
||||
self.option4 = wx.TextCtrl(self, wx.ID_ANY, "")
|
||||
self.option4.SetMaxLength(25)
|
||||
option4_sizer.Add(self.option4, 0, 0, 0)
|
||||
self.multiple = wx.CheckBox(self, wx.ID_ANY, _("Allow multiple votes per user"))
|
||||
self.multiple = wx.CheckBox(self, wx.ID_ANY, _("Allow multiple choices per user"))
|
||||
self.multiple.SetValue(False)
|
||||
sizer_1.Add(self.multiple, 0, wx.ALL, 5)
|
||||
self.hide_votes = wx.CheckBox(self, wx.ID_ANY, _("Hide votes count until the poll expires"))
|
||||
@@ -327,4 +327,42 @@ class poll(wx.Dialog):
|
||||
options = self.get_options()
|
||||
if len(options) < 2:
|
||||
return wx.MessageDialog(self, _("Please make sure you have provided at least two options for the poll."), _("Not enough information"), wx.ICON_ERROR).ShowModal()
|
||||
self.EndModal(wx.ID_OK)
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
class attachedPoll(wx.Dialog):
|
||||
def __init__(self, poll_options, multiple=False, *args, **kwds):
|
||||
super(attachedPoll, self).__init__(parent=None, id=wx.NewId(), title=_("Vote in this poll"))
|
||||
self.poll_options = poll_options
|
||||
sizer_1 = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer_2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, _("Options")), wx.VERTICAL)
|
||||
sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
|
||||
if multiple == False:
|
||||
for option in range(len(self.poll_options)):
|
||||
if option == 0:
|
||||
setattr(self, "option{}".format(option), wx.RadioButton(self, wx.ID_ANY, poll_options[option], style=wx.RB_GROUP))
|
||||
else:
|
||||
setattr(self, "option{}".format(option), wx.RadioButton(self, wx.ID_ANY, poll_options[option]))
|
||||
else:
|
||||
for option in range(len(self.poll_options)):
|
||||
setattr(self, "option{}".format(option), wx.CheckBox(self, wx.ID_ANY, poll_options[option]))
|
||||
sizer_2.Add(getattr(self, "option{}".format(option)), 1, wx.EXPAND, 0)
|
||||
btn_sizer = wx.StdDialogButtonSizer()
|
||||
sizer_1.Add(btn_sizer, 0, wx.ALIGN_RIGHT | wx.ALL, 4)
|
||||
self.button_OK = wx.Button(self, wx.ID_OK)
|
||||
self.button_OK.SetDefault()
|
||||
btn_sizer.AddButton(self.button_OK)
|
||||
self.button_CANCEL = wx.Button(self, wx.ID_CANCEL, "")
|
||||
btn_sizer.AddButton(self.button_CANCEL)
|
||||
btn_sizer.Realize()
|
||||
self.SetSizer(sizer_1)
|
||||
sizer_1.Fit(self)
|
||||
self.SetAffirmativeId(self.button_OK.GetId())
|
||||
self.SetEscapeId(self.button_CANCEL.GetId())
|
||||
self.Layout()
|
||||
|
||||
def get_selected(self):
|
||||
options = []
|
||||
for option in range(len(self.poll_options)):
|
||||
if getattr(self, "option{}".format(option)).GetValue() == True:
|
||||
options.append(option)
|
||||
return options
|
||||
|
Reference in New Issue
Block a user