2024-05-19 19:05:03 -06:00
# -*- coding: utf-8 -*-
2022-11-10 17:54:38 -06:00
import wx
2026-01-11 02:49:46 -06:00
import wx.adv
import datetime
2022-11-10 17:54:38 -06:00
2022-11-16 13:28:45 -06:00
class Post ( wx . Dialog ):
2024-12-31 18:48:27 -06:00
def __init__ ( self , caption = _ ( "Post" ), text = "" , languages = [], * args , ** kwds ):
2022-11-16 13:28:45 -06:00
super ( Post , self ) . __init__ ( parent = None , id = wx . ID_ANY , * args , ** kwds )
2022-11-11 15:51:16 -06:00
main_sizer = wx . BoxSizer ( wx . VERTICAL )
2022-11-16 13:28:45 -06:00
post_sizer = wx . WrapSizer ( wx . VERTICAL )
main_sizer . Add ( post_sizer , 1 , wx . EXPAND , 0 )
post_label = wx . StaticText ( self , wx . ID_ANY , caption )
post_sizer . Add ( post_label , 0 , 0 , 0 )
2022-11-11 15:51:16 -06:00
self . text = wx . TextCtrl ( self , wx . ID_ANY , text , style = wx . TE_MULTILINE )
2022-11-11 17:32:31 -06:00
self . Bind ( wx . EVT_CHAR_HOOK , self . handle_keys , self . text )
2022-11-11 15:51:16 -06:00
self . text . SetMinSize (( 350 , - 1 ))
2022-11-16 13:28:45 -06:00
post_sizer . Add ( self . text , 0 , 0 , 0 )
2022-11-11 15:51:16 -06:00
lists_sizer = wx . BoxSizer ( wx . HORIZONTAL )
main_sizer . Add ( lists_sizer , 1 , wx . EXPAND , 0 )
attachments_sizer = wx . WrapSizer ( wx . VERTICAL )
lists_sizer . Add ( attachments_sizer , 1 , wx . EXPAND , 0 )
attachments_label = wx . StaticText ( self , wx . ID_ANY , _ ( "Attachments" ))
attachments_sizer . Add ( attachments_label , 0 , 0 , 0 )
self . attachments = wx . ListCtrl ( self , wx . ID_ANY , style = wx . LC_HRULES | wx . LC_REPORT | wx . LC_SINGLE_SEL | wx . LC_VRULES )
self . attachments . Enable ( False )
self . attachments . AppendColumn ( _ ( "File" ), format = wx . LIST_FORMAT_LEFT , width =- 1 )
self . attachments . AppendColumn ( _ ( "Type" ), format = wx . LIST_FORMAT_LEFT , width =- 1 )
self . attachments . AppendColumn ( _ ( "Description" ), format = wx . LIST_FORMAT_LEFT , width =- 1 )
attachments_sizer . Add ( self . attachments , 1 , wx . EXPAND , 0 )
self . remove_attachment = wx . Button ( self , wx . ID_ANY , _ ( "Remove Attachment" ))
self . remove_attachment . Enable ( False )
attachments_sizer . Add ( self . remove_attachment , 0 , 0 , 0 )
2022-11-16 13:28:45 -06:00
posts_sizer = wx . WrapSizer ( wx . VERTICAL )
lists_sizer . Add ( posts_sizer , 1 , wx . EXPAND , 0 )
posts_label = wx . StaticText ( self , wx . ID_ANY , _ ( "Post in the thread" ))
posts_sizer . Add ( posts_label , 0 , 0 , 0 )
self . posts = wx . ListCtrl ( self , wx . ID_ANY , style = wx . LC_HRULES | wx . LC_REPORT | wx . LC_SINGLE_SEL | wx . LC_VRULES )
self . posts . Enable ( False )
self . posts . AppendColumn ( _ ( "Text" ), format = wx . LIST_FORMAT_LEFT , width =- 1 )
self . posts . AppendColumn ( _ ( "Attachments" ), format = wx . LIST_FORMAT_LEFT , width =- 1 )
posts_sizer . Add ( self . posts , 1 , wx . EXPAND , 0 )
self . remove_post = wx . Button ( self , wx . ID_ANY , _ ( "Remove post" ))
self . remove_post . Enable ( False )
posts_sizer . Add ( self . remove_post , 0 , 0 , 0 )
post_actions_sizer = wx . BoxSizer ( wx . HORIZONTAL )
main_sizer . Add ( post_actions_sizer , 1 , wx . EXPAND , 0 )
2022-11-11 15:51:16 -06:00
visibility_sizer = wx . BoxSizer ( wx . HORIZONTAL )
2022-11-16 13:28:45 -06:00
post_actions_sizer . Add ( visibility_sizer , 1 , wx . EXPAND , 0 )
2022-12-29 04:17:58 -05:00
label_1 = wx . StaticText ( self , wx . ID_ANY , _ ( "&Visibility" ))
2022-11-11 15:51:16 -06:00
visibility_sizer . Add ( label_1 , 0 , 0 , 0 )
2022-11-12 15:16:53 -06:00
self . visibility = wx . ComboBox ( self , wx . ID_ANY , choices = [ _ ( "Public" ), _ ( "Not listed" ), _ ( "Followers only" ), _ ( "Direct" )], style = wx . CB_DROPDOWN | wx . CB_READONLY | wx . CB_SIMPLE )
2022-11-11 15:51:16 -06:00
self . visibility . SetSelection ( 0 )
visibility_sizer . Add ( self . visibility , 0 , 0 , 0 )
2024-12-31 18:48:27 -06:00
language_sizer = wx . BoxSizer ( wx . HORIZONTAL )
post_actions_sizer . Add ( language_sizer , 0 , wx . RIGHT , 20 )
2025-10-02 13:17:43 -04:00
lang_label = wx . StaticText ( self , wx . ID_ANY , _ ( "&Language" ))
2024-12-31 18:48:27 -06:00
language_sizer . Add ( lang_label , 0 , wx . ALIGN_CENTER_VERTICAL | wx . RIGHT , 5 )
self . language = wx . ComboBox ( self , wx . ID_ANY , choices = languages , style = wx . CB_DROPDOWN | wx . CB_READONLY )
language_sizer . Add ( self . language , 0 , wx . ALIGN_CENTER_VERTICAL , 0 )
2022-11-11 15:51:16 -06:00
self . add = wx . Button ( self , wx . ID_ANY , _ ( "A&dd" ))
2022-12-29 04:17:58 -05:00
self . sensitive = wx . CheckBox ( self , wx . ID_ANY , _ ( "S&ensitive content" ))
2022-11-11 16:21:15 -06:00
self . sensitive . SetValue ( False )
self . sensitive . Bind ( wx . EVT_CHECKBOX , self . on_sensitivity_changed )
main_sizer . Add ( self . sensitive , 0 , wx . ALL , 5 )
2026-01-11 02:49:46 -06:00
# Scheduled post section
scheduled_box = wx . BoxSizer ( wx . HORIZONTAL )
self . scheduled = wx . CheckBox ( self , wx . ID_ANY , _ ( "Schedule &post" ))
self . scheduled . SetValue ( False )
self . scheduled . Bind ( wx . EVT_CHECKBOX , self . on_schedule_changed )
scheduled_box . Add ( self . scheduled , 0 , wx . ALL , 5 )
# Default to now + 6 minutes to be safe for the 5 minute minimum
future_dt = wx . DateTime . Now ()
future_dt . Add ( wx . TimeSpan ( 0 , 6 , 0 , 0 ))
self . date_picker = wx . adv . DatePickerCtrl ( self , wx . ID_ANY , dt = future_dt , style = wx . adv . DP_DROPDOWN | wx . adv . DP_SHOWCENTURY )
self . date_picker . Enable ( False )
scheduled_box . Add ( self . date_picker , 0 , wx . ALL , 5 )
self . time_picker = wx . adv . TimePickerCtrl ( self , wx . ID_ANY , dt = future_dt )
self . time_picker . Enable ( False )
scheduled_box . Add ( self . time_picker , 0 , wx . ALL , 5 )
main_sizer . Add ( scheduled_box , 0 , wx . ALL , 5 )
2022-11-11 16:21:15 -06:00
spoiler_box = wx . BoxSizer ( wx . HORIZONTAL )
spoiler_label = wx . StaticText ( self , wx . ID_ANY , _ ( "Content warning" ))
self . spoiler = wx . TextCtrl ( self , wx . ID_ANY )
self . spoiler . Enable ( False )
spoiler_box . Add ( spoiler_label , 0 , wx . ALL , 5 )
spoiler_box . Add ( self . spoiler , 0 , wx . ALL , 10 )
main_sizer . Add ( spoiler_box , 0 , wx . ALL , 5 )
2022-11-16 13:28:45 -06:00
post_actions_sizer . Add ( self . add , 0 , 0 , 0 )
self . add_post = wx . Button ( self , wx . ID_ANY , _ ( "Add p&ost" ))
post_actions_sizer . Add ( self . add_post , 0 , 0 , 0 )
2022-11-11 15:51:16 -06:00
text_actions_sizer = wx . BoxSizer ( wx . HORIZONTAL )
main_sizer . Add ( text_actions_sizer , 1 , wx . EXPAND , 0 )
self . autocomplete_users = wx . Button ( self , wx . ID_ANY , _ ( "Auto&complete users" ))
text_actions_sizer . Add ( self . autocomplete_users , 0 , 0 , 0 )
self . spellcheck = wx . Button ( self , wx . ID_ANY , _ ( "Check &spelling" ))
text_actions_sizer . Add ( self . spellcheck , 0 , 0 , 0 )
self . translate = wx . Button ( self , wx . ID_ANY , _ ( "&Translate" ))
text_actions_sizer . Add ( self . translate , 0 , 0 , 0 )
btn_sizer = wx . StdDialogButtonSizer ()
main_sizer . Add ( btn_sizer , 0 , wx . ALIGN_RIGHT | wx . ALL , 4 )
2026-01-11 02:49:46 -06:00
self . send = wx . Button ( self , wx . ID_ANY , _ ( "&Send" ))
2022-11-11 15:51:16 -06:00
self . send . SetDefault ()
2026-01-11 02:49:46 -06:00
self . send . Bind ( wx . EVT_BUTTON , self . validate_and_send )
2022-11-11 15:51:16 -06:00
btn_sizer . AddButton ( self . send )
self . close = wx . Button ( self , wx . ID_CLOSE , "" )
btn_sizer . AddButton ( self . close )
btn_sizer . Realize ()
self . SetSizer ( main_sizer )
main_sizer . Fit ( self )
self . SetEscapeId ( self . close . GetId ())
self . Layout ()
2022-11-11 17:32:31 -06:00
def handle_keys ( self , event : wx . Event , * args , ** kwargs ) -> None :
""" Allows to react to certain keyboard events from the text control. """
shift = event . ShiftDown ()
if event . GetKeyCode () == wx . WXK_RETURN and shift == False and hasattr ( self , 'send' ):
2026-01-11 02:49:46 -06:00
self . validate_and_send ()
2022-11-11 17:32:31 -06:00
else :
event . Skip ()
2026-01-11 02:49:46 -06:00
def validate_and_send ( self , event = None ):
scheduled_at = self . get_scheduled_at ()
if scheduled_at :
min_time = datetime . datetime . now () + datetime . timedelta ( minutes = 5 )
if scheduled_at < min_time :
wx . MessageDialog ( self ,
_ ( "Scheduled posts must be set at least 5 minutes in the future. Please adjust the time." ),
_ ( "Invalid scheduled time" ),
wx . ICON_ERROR | wx . OK ) . ShowModal ()
return
self . EndModal ( wx . ID_OK )
2022-11-11 16:21:15 -06:00
def on_sensitivity_changed ( self , * args , ** kwargs ):
self . spoiler . Enable ( self . sensitive . GetValue ())
2026-01-11 02:49:46 -06:00
def on_schedule_changed ( self , * args , ** kwargs ):
enabled = self . scheduled . GetValue ()
self . date_picker . Enable ( enabled )
self . time_picker . Enable ( enabled )
def get_scheduled_at ( self ):
if not self . scheduled . GetValue ():
return None
# Get date from date picker
wx_date = self . date_picker . GetValue ()
# Get time from time picker
wx_time = self . time_picker . GetValue ()
# Combine into a python datetime object
dt = datetime . datetime (
wx_date . GetYear (),
wx_date . GetMonth () + 1 , # wx.DateTime months are 0-11
wx_date . GetDay (),
wx_time . GetHour (),
wx_time . GetMinute (),
wx_time . GetSecond ()
)
return dt
2022-11-11 15:51:16 -06:00
def set_title ( self , chars ):
2022-11-16 13:28:45 -06:00
self . SetTitle ( _ ( "Post - {} characters" ) . format ( chars ))
2022-11-11 15:51:16 -06:00
def reset_controls ( self ):
self . text . ChangeValue ( "" )
self . attachments . DeleteAllItems ()
def add_item ( self , list_type = "attachment" , item = []):
if list_type == "attachment" :
self . attachments . Append ( item )
else :
2022-11-16 13:28:45 -06:00
self . posts . Append ( item )
2022-11-11 15:51:16 -06:00
def remove_item ( self , list_type = "attachment" ):
if list_type == "attachment" :
item = self . attachments . GetFocusedItem ()
if item > - 1 :
self . attachments . DeleteItem ( item )
else :
2022-11-16 13:28:45 -06:00
item = self . posts . GetFocusedItem ()
2022-11-11 15:51:16 -06:00
if item > - 1 :
2022-11-16 13:28:45 -06:00
self . posts . DeleteItem ( item )
2022-11-11 15:51:16 -06:00
def attach_menu ( self , event = None , enabled = True , * args , ** kwargs ):
menu = wx . Menu ()
self . add_image = menu . Append ( wx . ID_ANY , _ ( "Image" ))
self . add_image . Enable ( enabled )
self . add_video = menu . Append ( wx . ID_ANY , _ ( "Video" ))
self . add_video . Enable ( enabled )
self . add_audio = menu . Append ( wx . ID_ANY , _ ( "Audio" ))
self . add_audio . Enable ( enabled )
self . add_poll = menu . Append ( wx . ID_ANY , _ ( "Poll" ))
self . add_poll . Enable ( enabled )
return menu
def ask_description ( self ):
dlg = wx . TextEntryDialog ( self , _ ( u "please provide a description" ), _ ( u "Description" ))
dlg . ShowModal ()
result = dlg . GetValue ()
dlg . Destroy ()
return result
def get_image ( self ):
openFileDialog = wx . FileDialog ( self , _ ( u "Select the picture to be uploaded" ), "" , "" , _ ( "Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif" ), wx . FD_OPEN | wx . FD_FILE_MUST_EXIST )
if openFileDialog . ShowModal () == wx . ID_CANCEL :
return ( None , None )
dsc = self . ask_description ()
return ( openFileDialog . GetPath (), dsc )
def get_video ( self ):
openFileDialog = wx . FileDialog ( self , _ ( "Select the video to be uploaded" ), "" , "" , _ ( "Video files (*.mp4, *.mov, *.m4v, *.webm)| *.mp4; *.m4v; *.mov; *.webm" ), wx . FD_OPEN | wx . FD_FILE_MUST_EXIST )
if openFileDialog . ShowModal () == wx . ID_CANCEL :
2023-02-10 01:01:25 -06:00
return ( None , None )
dsc = self . ask_description ()
return ( openFileDialog . GetPath (), dsc )
2022-11-11 15:51:16 -06:00
def get_audio ( self ):
openFileDialog = wx . FileDialog ( self , _ ( "Select the audio file to be uploaded" ), "" , "" , _ ( "Audio files (*.mp3, *.ogg, *.wav, *.flac, *.opus, *.aac, *.m4a, *.3gp)|*.mp3; *.ogg; *.wav; *.flac; *.opus; *.aac; *.m4a; *.3gp" ), wx . FD_OPEN | wx . FD_FILE_MUST_EXIST )
if openFileDialog . ShowModal () == wx . ID_CANCEL :
2023-02-10 01:01:25 -06:00
return ( None , None )
dsc = self . ask_description ()
return ( openFileDialog . GetPath (), dsc )
2022-11-11 15:51:16 -06:00
def unable_to_attach_file ( self , * args , ** kwargs ):
2022-11-16 13:28:45 -06:00
return wx . MessageDialog ( self , _ ( "It is not possible to add more attachments. Please take into account that You can add only a maximum of 4 images, or one audio, video or poll per post. Please remove other attachments before continuing." ), _ ( "Error adding attachment" ), wx . ICON_ERROR ) . ShowModal ()
2022-11-11 15:51:16 -06:00
def unable_to_attach_poll ( self , * args , ** kwargs ):
return wx . MessageDialog ( self , _ ( "You can add a poll or media files. In order to add your poll, please remove other attachments first." ), _ ( "Error adding poll" ), wx . ICON_ERROR ) . ShowModal ()
2024-05-17 13:58:54 -06:00
2022-11-16 13:28:45 -06:00
class viewPost ( wx . Dialog ):
2024-05-17 13:58:54 -06:00
def set_title ( self , length ):
self . SetTitle ( _ ( "Post - %i characters " ) % length )
2022-11-10 17:54:38 -06:00
def __init__ ( self , text = "" , boosts_count = 0 , favs_count = 0 , source = "" , date = "" , privacy = "" , * args , ** kwargs ):
2024-05-17 13:58:54 -06:00
super ( viewPost , self ) . __init__ ( parent = None , id = wx . ID_ANY , size = ( 850 , 850 ))
self . init_ui ( text , boosts_count , favs_count , source , date , privacy )
def init_ui ( self , text , boosts_count , favs_count , source , date , privacy ):
2022-11-10 17:54:38 -06:00
panel = wx . Panel ( self )
2024-05-17 13:58:54 -06:00
main_sizer = wx . BoxSizer ( wx . VERTICAL )
main_sizer . Add ( self . create_text_section ( panel , text ), 1 , wx . EXPAND | wx . ALL , 5 )
main_sizer . Add ( self . create_image_description_section ( panel ), 1 , wx . EXPAND | wx . ALL , 5 )
main_sizer . Add ( self . create_info_section ( panel , privacy , boosts_count , favs_count , source , date ), 0 , wx . EXPAND | wx . ALL , 5 )
main_sizer . Add ( self . create_buttons_section ( panel ), 0 , wx . ALIGN_RIGHT | wx . ALL , 5 )
panel . SetSizer ( main_sizer )
self . SetClientSize ( main_sizer . CalcMin ())
def create_text_section ( self , panel , text ):
sizer = wx . StaticBoxSizer ( wx . StaticBox ( panel , wx . ID_ANY , _ ( "Post" )), wx . VERTICAL )
self . text = wx . TextCtrl ( panel , - 1 , text , style = wx . TE_READONLY | wx . TE_MULTILINE )
sizer . Add ( self . text , 1 , wx . EXPAND | wx . ALL , 5 )
return sizer
def create_image_description_section ( self , panel ):
sizer = wx . StaticBoxSizer ( wx . StaticBox ( panel , wx . ID_ANY , _ ( "Image description" )), wx . VERTICAL )
self . image_description = wx . TextCtrl ( panel , - 1 , style = wx . TE_READONLY | wx . TE_MULTILINE )
2022-11-10 17:54:38 -06:00
self . image_description . Enable ( False )
2024-05-17 13:58:54 -06:00
sizer . Add ( self . image_description , 1 , wx . EXPAND | wx . ALL , 5 )
return sizer
def create_info_section ( self , panel , privacy , boosts_count , favs_count , source , date ):
sizer = wx . StaticBoxSizer ( wx . StaticBox ( panel , wx . ID_ANY , _ ( "Information" )), wx . VERTICAL )
flex_sizer = wx . FlexGridSizer ( cols = 3 , hgap = 10 , vgap = 10 )
flex_sizer . AddGrowableCol ( 1 )
flex_sizer . Add ( wx . StaticText ( panel , - 1 , _ ( "Privacy" )), 0 , wx . ALIGN_CENTER_VERTICAL )
flex_sizer . Add ( wx . TextCtrl ( panel , - 1 , privacy , style = wx . TE_READONLY | wx . TE_MULTILINE ), 1 , wx . EXPAND )
flex_sizer . Add ( self . create_boosts_section ( panel , boosts_count ), 1 , wx . EXPAND | wx . ALL , 5 )
flex_sizer . Add ( self . create_favorites_section ( panel , favs_count ), 1 , wx . EXPAND | wx . ALL , 5 )
flex_sizer . Add ( wx . StaticText ( panel , - 1 , _ ( "Source" )), 0 , wx . ALIGN_CENTER_VERTICAL )
flex_sizer . Add ( wx . TextCtrl ( panel , - 1 , source , style = wx . TE_READONLY | wx . TE_MULTILINE ), 1 , wx . EXPAND )
flex_sizer . Add ( wx . StaticText ( panel , - 1 , _ ( "Date" )), 0 , wx . ALIGN_CENTER_VERTICAL )
flex_sizer . Add ( wx . TextCtrl ( panel , - 1 , date , style = wx . TE_READONLY | wx . TE_MULTILINE ), 1 , wx . EXPAND )
sizer . Add ( flex_sizer , 1 , wx . EXPAND | wx . ALL , 5 )
return sizer
def create_boosts_section ( self , panel , boosts_count ):
sizer = wx . StaticBoxSizer ( wx . StaticBox ( panel , wx . ID_ANY , _ ( "Boosts" )), wx . VERTICAL )
self . boosts_button = wx . Button ( panel , - 1 , str ( boosts_count ))
self . boosts_button . SetToolTip ( _ ( "View users who boosted this post" ))
sizer . Add ( self . boosts_button , 1 , wx . EXPAND | wx . ALL , 5 )
return sizer
def create_favorites_section ( self , panel , favs_count ):
sizer = wx . StaticBoxSizer ( wx . StaticBox ( panel , wx . ID_ANY , _ ( "Favorites" )), wx . VERTICAL )
self . favorites_button = wx . Button ( panel , - 1 , str ( favs_count ))
self . favorites_button . SetToolTip ( _ ( "View users who favorited this post" ))
sizer . Add ( self . favorites_button , 1 , wx . EXPAND | wx . ALL , 5 )
return sizer
def create_buttons_section ( self , panel ):
sizer = wx . BoxSizer ( wx . HORIZONTAL )
2025-10-02 13:17:43 -04:00
self . mute = wx . Button ( panel , wx . ID_ANY , _ ( "&Mute conversation" ))
2024-05-17 16:38:26 -06:00
self . mute . Enable ( False )
2025-10-02 13:17:43 -04:00
self . share = wx . Button ( panel , wx . ID_ANY , _ ( "&Copy link to clipboard" ))
2022-11-10 17:54:38 -06:00
self . share . Enable ( False )
2024-05-17 13:58:54 -06:00
self . spellcheck = wx . Button ( panel , wx . ID_ANY , _ ( "Check &spelling..." ))
self . translateButton = wx . Button ( panel , wx . ID_ANY , _ ( "&Translate..." ))
cancelButton = wx . Button ( panel , wx . ID_CANCEL , _ ( "C&lose" ))
2022-11-10 17:54:38 -06:00
cancelButton . SetDefault ()
2024-05-17 16:38:26 -06:00
sizer . Add ( self . mute , 0 , wx . ALL , 5 )
2024-05-17 13:58:54 -06:00
sizer . Add ( self . share , 0 , wx . ALL , 5 )
sizer . Add ( self . spellcheck , 0 , wx . ALL , 5 )
sizer . Add ( self . translateButton , 0 , wx . ALL , 5 )
sizer . Add ( cancelButton , 0 , wx . ALL , 5 )
return sizer
2022-11-10 17:54:38 -06:00
def set_text ( self , text ):
self . text . ChangeValue ( text )
def get_text ( self ):
return self . text . GetValue ()
def text_focus ( self ):
self . text . SetFocus ()
def onSelect ( self , ev ):
self . text . SelectAll ()
def enable_button ( self , buttonName ):
if hasattr ( self , buttonName ):
return getattr ( self , buttonName ) . Enable ()
2022-11-11 15:51:16 -06:00
2023-04-05 12:57:37 -06:00
class viewText ( wx . Dialog ):
def __init__ ( self , title = "" , text = "" , * args , ** kwargs ):
super ( viewText , self ) . __init__ ( parent = None , id = wx . ID_ANY , size = ( 850 , 850 ), title = title )
panel = wx . Panel ( self )
label = wx . StaticText ( panel , - 1 , _ ( "Text" ))
self . text = wx . TextCtrl ( panel , - 1 , text , style = wx . TE_READONLY | wx . TE_MULTILINE , size = ( 250 , 180 ))
self . text . SetFocus ()
textBox = wx . BoxSizer ( wx . HORIZONTAL )
textBox . Add ( label , 0 , wx . ALL , 5 )
textBox . Add ( self . text , 1 , wx . EXPAND , 5 )
mainBox = wx . BoxSizer ( wx . VERTICAL )
mainBox . Add ( textBox , 0 , wx . ALL , 5 )
self . spellcheck = wx . Button ( panel , - 1 , _ ( "Check &spelling..." ), size = wx . DefaultSize )
self . translateButton = wx . Button ( panel , - 1 , _ ( u "&Translate..." ), size = wx . DefaultSize )
cancelButton = wx . Button ( panel , wx . ID_CANCEL , _ ( u "C&lose" ), size = wx . DefaultSize )
cancelButton . SetDefault ()
buttonsBox = wx . BoxSizer ( wx . HORIZONTAL )
buttonsBox . Add ( self . spellcheck , 0 , wx . ALL , 5 )
buttonsBox . Add ( self . translateButton , 0 , wx . ALL , 5 )
buttonsBox . Add ( cancelButton , 0 , wx . ALL , 5 )
mainBox . Add ( buttonsBox , 0 , wx . ALL , 5 )
panel . SetSizer ( mainBox )
self . SetClientSize ( mainBox . CalcMin ())
2022-11-11 15:51:16 -06:00
class poll ( wx . Dialog ):
def __init__ ( self , * args , ** kwds ):
super ( poll , self ) . __init__ ( parent = None , id = wx . NewId (), title = _ ( "Add a poll" ))
sizer_1 = wx . BoxSizer ( wx . VERTICAL )
period_sizer = wx . BoxSizer ( wx . HORIZONTAL )
sizer_1 . Add ( period_sizer , 1 , wx . EXPAND , 0 )
2025-10-02 13:17:43 -04:00
label_period = wx . StaticText ( self , wx . ID_ANY , _ ( "&Participation time" ))
2022-11-11 15:51:16 -06:00
period_sizer . Add ( label_period , 0 , 0 , 0 )
self . period = wx . ComboBox ( self , wx . ID_ANY , choices = [ _ ( "5 minutes" ), _ ( "30 minutes" ), _ ( "1 hour" ), _ ( "6 hours" ), _ ( "1 day" ), _ ( "2 days" ), _ ( "3 days" ), _ ( "4 days" ), _ ( "5 days" ), _ ( "6 days" ), _ ( "7 days" )], style = wx . CB_DROPDOWN | wx . CB_READONLY | wx . CB_SIMPLE )
self . period . SetFocus ()
self . period . SetSelection ( 0 )
period_sizer . Add ( self . period , 0 , 0 , 0 )
sizer_2 = wx . StaticBoxSizer ( wx . StaticBox ( self , wx . ID_ANY , _ ( "Choices" )), wx . VERTICAL )
sizer_1 . Add ( sizer_2 , 1 , wx . EXPAND , 0 )
option1_sizer = wx . BoxSizer ( wx . HORIZONTAL )
sizer_2 . Add ( option1_sizer , 1 , wx . EXPAND , 0 )
2025-10-02 13:17:43 -04:00
label_2 = wx . StaticText ( self , wx . ID_ANY , _ ( "Option &1" ))
2022-11-11 15:51:16 -06:00
option1_sizer . Add ( label_2 , 0 , 0 , 0 )
self . option1 = wx . TextCtrl ( self , wx . ID_ANY , "" )
self . option1 . SetMaxLength ( 25 )
option1_sizer . Add ( self . option1 , 0 , 0 , 0 )
option2_sizer = wx . BoxSizer ( wx . HORIZONTAL )
sizer_2 . Add ( option2_sizer , 1 , wx . EXPAND , 0 )
2025-10-02 13:17:43 -04:00
label_3 = wx . StaticText ( self , wx . ID_ANY , _ ( "Option &2" ))
2022-11-11 15:51:16 -06:00
option2_sizer . Add ( label_3 , 0 , 0 , 0 )
self . option2 = wx . TextCtrl ( self , wx . ID_ANY , "" )
self . option2 . SetMaxLength ( 25 )
option2_sizer . Add ( self . option2 , 0 , 0 , 0 )
option3_sizer = wx . BoxSizer ( wx . HORIZONTAL )
sizer_2 . Add ( option3_sizer , 1 , wx . EXPAND , 0 )
2025-10-02 13:17:43 -04:00
label_4 = wx . StaticText ( self , wx . ID_ANY , _ ( "Option &3" ))
2022-11-11 15:51:16 -06:00
option3_sizer . Add ( label_4 , 0 , 0 , 0 )
self . option3 = wx . TextCtrl ( self , wx . ID_ANY , "" )
self . option3 . SetMaxLength ( 25 )
option3_sizer . Add ( self . option3 , 0 , 0 , 0 )
option4_sizer = wx . BoxSizer ( wx . HORIZONTAL )
sizer_2 . Add ( option4_sizer , 1 , wx . EXPAND , 0 )
2025-10-02 13:17:43 -04:00
label_5 = wx . StaticText ( self , wx . ID_ANY , _ ( "Option &4" ))
2022-11-11 15:51:16 -06:00
option4_sizer . Add ( label_5 , 0 , 0 , 0 )
self . option4 = wx . TextCtrl ( self , wx . ID_ANY , "" )
self . option4 . SetMaxLength ( 25 )
option4_sizer . Add ( self . option4 , 0 , 0 , 0 )
2025-10-02 13:17:43 -04:00
self . multiple = wx . CheckBox ( self , wx . ID_ANY , _ ( "&Allow multiple choices per user" ))
2022-11-11 15:51:16 -06:00
self . multiple . SetValue ( False )
sizer_1 . Add ( self . multiple , 0 , wx . ALL , 5 )
2025-10-02 13:17:43 -04:00
self . hide_votes = wx . CheckBox ( self , wx . ID_ANY , _ ( "&Hide votes count until the poll expires" ))
2022-11-11 15:51:16 -06:00
self . hide_votes . SetValue ( False )
sizer_1 . Add ( self . hide_votes , 0 , wx . ALL , 5 )
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 ()
self . button_OK . Bind ( wx . EVT_BUTTON , self . validate_data )
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_options ( self ):
controls = [ self . option1 , self . option2 , self . option3 , self . option4 ]
options = [ option . GetValue () for option in controls if option . GetValue () != "" ]
return options
def validate_data ( self , * args , ** kwargs ):
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 ()
2023-02-17 23:19:34 -06:00
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
2023-04-05 12:57:37 -06:00