łň Š_Fc@s dZdefd„ƒYZdS(sî This module documents a class that implements paragraph operations. @author: Lateef Alabi-Oki @organization: The Scribes Project @copyright: Copyright Š 2007 Lateef Alabi-Oki @license: GNU GPLv2 or Later @contact: mystilleef@gmail.com tManagercBs×eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z e d „Z d „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s/ This class implements paragraph operations. cCs:|i|ƒddkl}l}||id|ƒdS(s˝ Initialize object. @param self: Reference to the Manager instance. @type self: A Manager object. @param editor: Reference to the text editor. @type editor: An Editor object. i˙˙˙˙(tidle_addt PRIORITY_LOWtpriorityN(t_Manager__init_attributestgobjectRRt_Manager__precompile_methods(tselfteditorRR((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__init__$s cCs1||_|i|_|i|_|i|_dS(s˝ Initialize object. @param self: Reference to the Manager instance. @type self: A Manager object. @param editor: Reference to the text editor. @type editor: An Editor object. N(t_Manager__editort gconf_clientt_Manager__clientt textbuffert_Manager__buffertfeedbackt_Manager__feedback(RR((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__init_attributes2s    c Cs |iiƒ}|iƒ}ddkl}l}yz||dƒo t‚n|i|ƒ}||d ƒo t ‚n|i |ƒddk l }|i i|ddƒWnXtj o-ddk l}|i i|ddƒn!t j o|i dƒnXd S( s{ Move cursor to previous paragraph. @param self: Reference to the Manager instance. @type self: A Manager object. i˙˙˙˙(teqtis_i(tmsg0003tyesi(tmsg0004twarningN(R tget_cursor_iteratortget_linetoperatorRRt RuntimeErrort_Manager__find_empty_linetNonet ValueErrort_Manager__jump_to_lineti18nRRtupdate_status_messageR(Rtcursor_iteratort current_lineRRtlineRR((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pytprevious_paragraphHs   c Cs$|iiƒ}|iiƒ}|iƒ}ddkl}l}y|||dƒo t‚n|i |t ƒ}||d ƒo t ‚n|i |ƒddkl}|ii|ddƒWn\tj o-ddkl}|ii|ddƒn%t j o|i |dƒnXd S( sw Move cursor to next paragraph. @param self: Reference to the Manager instance. @type self: A Manager object. i˙˙˙˙(RRi(tmsg0005Ri(tmsg0006RN(Rtget_line_countR RRRRRRRtFalseRRRR R&RR!R'( Rtnumber_of_linesR"R#RRR$R&R'((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pytnext_paragraph`s"  cCsyO|iƒ\}}|ii||ƒddkl}|ii|ddƒWn9tj o-ddkl}|ii|ddƒnXdS(sl Select a paragraph. @param self: Reference to the Manager instance. @type self: A Manager object. i˙˙˙˙(tmsg0007Ri(tmsg0001RN( t _Manager__get_paragraph_positionRt select_rangeR R,RR!RR-(RtbegintendR,R-((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pytselect_paragraphysc Cs:|iƒodSny|iƒ\}}Wn=tj o1ddkl}|ii|ddƒdSnX|i|ƒ}y|i|ƒ}Wn=tj o1ddkl }|ii|ddƒdSnX|i i ƒ|i i ||ƒ|i i |ƒ|i iƒddkl}|}|ii|ddƒdS( s‰ Reflow paragraph based on right margin position. @param self: Reference to the Manager instance. @type self: A Manager object. Ni˙˙˙˙(R-Ri(tmsg0002(tmsg0009R(t_Manager__is_readonlyR.RR R-RR!tget_textt_Manager__reflow_textR3Rtbegin_user_actiontdeletetinsert_at_cursortend_user_actionR4(RtstartR1R-ttextR3R4tmessage((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pytreflow_paragraphŠs,    cCs|ii|ƒ~d}dS(sh Destroy object. @param self: Reference to the Manager instance. @type self: A Manager object. N(R tdelete_attributesR(R((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pytdestroy¨scCs|iƒ}|iƒo|iƒo t‚n|i|ƒo t‚n|i|ƒ}|djo|iiƒ\}}n|ii |ƒ}|i ƒ|i|t ƒ}|djo|iiƒ\}}n'|ii |ƒ}|i ƒ|i ƒ||fS(s Get start and end paragraph positions. @param self: Reference to the Manager instance. @type self: A Manager object. @return: The position of a paragraph. @rtype: A Tuple object. N(t#_Manager__get_current_line_iteratortis_starttis_endRt_Manager__is_empty_lineRRRt get_boundstget_iter_at_linet forward_lineR)t backward_linetforward_to_line_end(Rtiteratortfirst_paragraph_lineR0R1tsecond_paragraph_lineR<((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__get_paragraph_positionşs $     cCs@|iiƒ}|iƒo|Sn|iƒ}|ii|ƒS(sÚ Get iterator at start of current line. @param self: Reference to the Manager instance. @type self: A Manager object. @return: Return the iterator at start of current line. @rtype: A gtk.TextIter object. (R Rt starts_lineRRRG(RRKR$((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__get_current_line_iteratorÖs  cCs‚ddkl}xktoc|o||iƒƒodSq[n||iƒƒodSn|i|ƒo|iƒSqqWdS(s Search backwards for empty lines. @param self: Reference to the Manager instance. @type self: A Manager object. @param iterator: The cursor position @type iterator: A gtk.TextIter object. @return: Line number of empty line or None @rtype: An Integer or None object. i˙˙˙˙(tnot_N(RRQtTrueRIRRHRER(RRKt backwardsRQ((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__find_empty_lineĺs  #cCsx|iƒotSn|iƒ}|iƒ|i|ƒ}ddkl}||ƒotSn|iƒotSntS(s Whether or not a line is empty. @param self: Reference to the Manager instance. @type self: A Manager object. @param iterator: Reference a position in the buffer. @type iterator: A gtk.TextIter object. @return: True if line is empty. @rtype: A Boolean object. i˙˙˙˙(RQ( t ends_lineRRtcopyRJR6RRQtisspaceR)(RRKttemporary_iteratorR=RQ((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__is_empty_lineűs   cCsF|ii|ƒ}|ii|ƒddkl}||iiƒdS(sş Move cursor to a specific line. @param self: Reference to the Manager instance. @type self: A Manager object. @param line: Line to jump to. @type line: An Integer object. i˙˙˙˙(tmove_view_to_cursorN(RRGt place_cursortSCRIBES.cursorRZR ttextview(RR$RKRZ((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__jump_to_lines c Csrddkl}l}l}||ƒp |iƒo t‚n|idƒ}|i|dƒ}|i|ƒ}g}d} di |ƒ} | i ddƒ} | i ƒ} |i | ƒ} |t | ƒ|ƒo_xitoP|i| |ƒ\} } |i| ƒ|t | ƒ|ƒoPn| i ƒ} qŇWn|i| ƒ| o|i| ƒn|i||ƒ} di | ƒS(s% Realign lines in text such that is line is not more than a specified character long. @param self: Reference to the Manager instance. @type self: A Manager object. @param text: Text to reflow. @type text: A String object. @return: Realigned text. @rtype: A String object. i˙˙˙˙(RQtgttles itt s (RRQR_R`RWRtsplitt_Manager__get_indentationt_Manager__calculate_wrap_widthtjointreplacetstript_Manager__respace_linetlenRRt_Manager__shorten_linetappendt_Manager__indent_lines( RR=RQR_R`t text_linest indentationt wrap_widthtreflowed_linest remainderR$tnew_linetindented_reflowed_lines((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt __reflow_text's*$    cCsjddkl}|iƒ}|||dtdtƒ}|d}di|dƒ}|iƒ|iƒfS(s Shorten a line to a specified wrap width. @param self: Reference to the Manager instance. @type self: A Manager object. @param line: Line to shorten. @type line: A String object. @param wrap_width: How long the line should be. @type wrap_width: An Integer object. @return: The shortened line and other strings that exceed the specified wrap width. @rtype: A Tuple object. i˙˙˙˙(twrapt expand_tabstreplace_whitespaceiRbi(ttextwrapRvRhR)Rf(RR$RpRvt new_linesRsRr((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__shorten_lineLs   csPddkl}|t|ƒdƒo|Sn‡fd†}t||ƒ}|S(s} Perform automatic indentation on each line, if necessary. Automatic indentation is based on the indentation of the first line. @param self: Reference to the Manager instance. @type self: A Manager object. @param reflowed_lines: Realigned lines for indentation. @type reflowed_lines: A List object. @return: A list of indented lines. @rtype: A List object. i˙˙˙˙(tlticsˆ|iƒS((Rh(tx(Ro(s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pytvs(RR|Rjtmap(RRqRoR|t indent_linetindented_lines((Ros=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__indent_linesds cCshg}ddkl}l}x<|D]4}||ddg|ƒƒoPn|i|ƒq#Wdi|ƒS(sÍ Determine the indentation of a line. @param self: Reference to the Manager instance. @type self: A Manager object. @param line: A line to check for indentation. @type line: A String object. i˙˙˙˙(tcontainsRQRbs Ra(RRƒRQRlRf(RR$tindentation_listRƒRQtchar((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__get_indentationzs !cCsS|idƒ}x4to,y|idƒWqtj oPqXqWdi|ƒS(s Remove duplicate spaces in a line. @param self: Reference to the Manager instance. @type self: A Manager object. @param line: A line to remove duplicate spaces from. @type line: A String object. @return: A new line with single spaces. @rtype: A String object. RbRa(RcRRtremoveRRf(RR$((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__respace_line‹s   cCsw|iƒ}ddkl}l}||ƒo|Sn|iƒ}|idƒ}|idƒ}||||}|S(sP Determine wrap width. This function calculates the wrap width paying attention to automatic indentation. @param self: Reference to the Manager instance. @type self: A Manager object. @param indentation: An indentation strings. @type indentation: A String object. @return: wrap width. @rtype: An Integer object. i˙˙˙˙(RQtnes Rb(t _Manager__get_right_margin_widthRRQR‰t_Manager__get_tab_widthtcount(RRotwidthRQR‰t tab_widthtnumber_of_tab_charstnumber_of_space_chars((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__calculate_wrap_width s  cCs3d}|iidƒo|iidƒ}n|S(sŚ Get tab width from GConf. @param self: Reference to the Manager instance. @type self: A Manager object. @return: Tab width. @rtype: An Integer object. is/apps/scribes/tab(R tgettget_int(RRŽ((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__get_tab_widthšs cCsXddkl}||iiƒotSnddkl}|iii|ddƒt S(sÍ Check if editor is in readonly mode. @param self: Reference to the Manager instance. @type self: A Manager object. @return: True if editor is in readonly mode. @rtype: A Boolean object. i˙˙˙˙(RQ(tmsg0010Ri( RRQR t is_readonlyR)R R•RR!RR(RRQR•((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt __is_readonlyČs cCs3d}|iidƒo|iidƒ}n|S(sš Get margin or wrap width from Gconf. @param self: Reference to the Manager instance. @type self: A Manager object. @return: Margin/wrap width. @rtype: An Integer object. iHs/apps/scribes/margin_position(R R’R“(Rtmargin_position((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__get_right_margin_widthŘs cCsäyĘddkl}||iƒ||iƒ||iƒ||iƒ||iƒ||iƒ||iƒ||i ƒ||i ƒ||i ƒ||i ƒ||i ƒ||iƒ||iƒWntj onXtS(sv Optimize methods using Psyco. @param self: Reference to the Manager instance. @type self: A Manager object. i˙˙˙˙(tbind(tpsycoRšR?R+R%R2R7RkRiRmReR.RBRRERt ImportErrorR)(RRš((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyt__precompile_methodsçs&             (t__name__t __module__t__doc__R RR%R+R2R?RAR.RBRRRRERR7RkRmRdRiReR‹R5RŠR(((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyRs.             %        N(R tobjectR(((s=/home/goldenmyst/.gnome2/scribes/plugins/Paragraph/Manager.pyss