5858from .html_parser import *
5959from .memo import DialogMemo
6060from .report_codes import DialogReportCodes # for isInstance()
61+ from .ris import Ris
6162from .select_items import DialogSelectItems
6263from .view_av import DialogViewAV , DialogCodeAV # for isinstance update files
6364from .view_image import DialogViewImage , DialogCodeImage # for isinstance update files
@@ -306,6 +307,7 @@ def table_menu(self, position):
306307 item_text = self .ui .tableWidget .item (row , col ).text ()
307308 # Use these next few lines to use for moving a linked file into or an internal file out of the project folder
308309 mediapath = None
310+ risid = None
309311 try :
310312 id_ = int (self .ui .tableWidget .item (row , self .ID_COLUMN ).text ())
311313 except AttributeError :
@@ -314,6 +316,7 @@ def table_menu(self, position):
314316 for s in self .source :
315317 if s ['id' ] == id_ :
316318 mediapath = s ['mediapath' ]
319+ risid = s ['risid' ]
317320 # Action cannot be None otherwise may default to one of the actions below depending on column clicked
318321 menu = QtWidgets .QMenu ()
319322 menu .setStyleSheet ("QMenu {font-size:" + str (self .app .settings ['fontsize' ]) + "pt} " )
@@ -343,6 +346,8 @@ def table_menu(self, position):
343346 action_order_by_value_asc = None
344347 action_order_by_value_desc = None
345348 action_date_picker = None
349+ action_ref_apa = None
350+ action_ref_vancouver = None
346351 if col > self .CASE_COLUMN :
347352 action_order_by_value_asc = menu .addAction (_ ("Order ascending" ))
348353 action_order_by_value_desc = menu .addAction (_ ("Order descending" ))
@@ -355,6 +360,9 @@ def table_menu(self, position):
355360 result = cur .fetchone ()
356361 if result is not None and result [0 ] == "character" :
357362 action_date_picker = menu .addAction (_ ("Enter date" ))
363+ if self .header_labels [col ] in ("Ref_Authors" , "Ref_Title" , "Ref_Journal" , "Ref_Type" , "Ref_Year" ):
364+ action_ref_apa = menu .addAction (_ ("Copy reference to clipboard. APA" ))
365+ action_ref_vancouver = menu .addAction (_ ("Copy reference to clipboard. Vancouver" ))
358366 action_rename = None
359367 action_export = None
360368 action_delete = None
@@ -438,15 +446,31 @@ def table_menu(self, position):
438446 if action == action_url :
439447 webbrowser .open (item_text )
440448 if action == action_date_picker :
441- ui = DialogMemo (self .app , "Date selector" , "" , "hide" )
442- ui .ui .textEdit .hide ()
449+ ui_memo = DialogMemo (self .app , "Date selector" , "" , "hide" )
450+ ui_memo .ui .textEdit .hide ()
443451 calendar = QtWidgets .QCalendarWidget ()
444- ui .ui .gridLayout .addWidget (calendar , 0 , 0 , 1 , 1 )
445- ok = ui .exec ()
452+ ui_memo .ui .gridLayout .addWidget (calendar , 0 , 0 , 1 , 1 )
453+ ok = ui_memo .exec ()
446454 if ok :
447455 selected_date = calendar .selectedDate ().toString ("yyyy-MM-dd" )
448456 self .ui .tableWidget .setItem (row , col , QtWidgets .QTableWidgetItem (selected_date ))
449457 return
458+ if action == action_ref_apa :
459+ ris_obj = Ris (self .app )
460+ ris_obj .get_references (selected_ris = risid )
461+ apa = ris_obj .refs
462+ if not apa :
463+ return
464+ cb = QtWidgets .QApplication .clipboard ()
465+ cb .setText (apa [0 ]['apa' ].replace ("\n " , " " ))
466+ if action == action_ref_vancouver :
467+ ris_obj = Ris (self .app )
468+ ris_obj .get_references (selected_ris = risid )
469+ vancouver = ris_obj .refs
470+ if not vancouver :
471+ return
472+ cb = QtWidgets .QApplication .clipboard ()
473+ cb .setText (vancouver [0 ]['vancouver' ].replace ("\n " , " " ))
450474
451475 def view_original_text_file (self , mediapath ):
452476 """ View original text file.
@@ -773,14 +797,14 @@ def load_file_data(self, order_by=""):
773797 self .source = []
774798 cur = self .app .conn .cursor ()
775799 placeholders = None
776- # default alphabetic order
777- sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id from source order by upper(name)"
800+ # Default alphabetic order
801+ sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id, risid from source order by upper(name)"
778802 if order_by == "filename desc" :
779803 sql += " desc"
780804 if order_by == "date" :
781- sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id from source order by date, upper(name)"
805+ sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id, risid from source order by date, upper(name)"
782806 if order_by == "filetype" :
783- sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id from source order by mediapath"
807+ sql = "select name, id, fulltext, mediapath, ifnull(memo,''), owner, date, av_text_id, risid from source order by mediapath"
784808 if order_by == "casename" :
785809 sql = "select distinct source.name, source.id, source.fulltext, source.mediapath, ifnull(source.memo,''), "
786810 sql += "source.owner, source.date, av_text_id "
@@ -790,11 +814,11 @@ def load_file_data(self, order_by=""):
790814
791815 if order_by [:14 ] == "attribute asc:" :
792816 attribute_name = order_by [14 :]
793- # two types of ordering character or numeric
817+ # Two types of ordering character or numeric
794818 cur .execute ("select valuetype from attribute_type where name=?" , [attribute_name ])
795819 attr_type = cur .fetchone ()[0 ]
796820 sql = "select source.name, source.id, fulltext, mediapath, ifnull(source.memo,''), source.owner, "
797- sql += "source.date, av_text_id from source join attribute on attribute.id = source.id "
821+ sql += "source.date, av_text_id, risid from source join attribute on attribute.id = source.id "
798822 sql += " where attribute.attr_type = 'file' and attribute.name=? "
799823 if attr_type == "character" :
800824 sql += "order by lower(attribute.value) asc "
@@ -808,7 +832,7 @@ def load_file_data(self, order_by=""):
808832 cur .execute ("select valuetype from attribute_type where name=?" , [attribute_name ])
809833 attr_type = cur .fetchone ()[0 ]
810834 sql = "select source.name, source.id, fulltext, mediapath, ifnull(source.memo,''), source.owner, "
811- sql += "source.date, av_text_id from source join attribute on attribute.id = source.id "
835+ sql += "source.date, av_text_id, risid from source join attribute on attribute.id = source.id "
812836 sql += " where attribute.attr_type = 'file' and attribute.name=? "
813837 if attr_type == "character" :
814838 sql += "order by lower(attribute.value) desc "
@@ -825,7 +849,7 @@ def load_file_data(self, order_by=""):
825849 icon , metadata = self .get_icon_and_metadata (row [1 ])
826850 self .source .append ({'name' : row [0 ], 'id' : row [1 ], 'fulltext' : row [2 ],
827851 'mediapath' : row [3 ], 'memo' : row [4 ], 'owner' : row [5 ], 'date' : row [6 ],
828- 'av_text_id' : row [7 ], 'metadata' : metadata , 'icon' : icon ,
852+ 'av_text_id' : row [7 ], 'risid' : row [ 8 ], ' metadata' : metadata , 'icon' : icon ,
829853 'case' : self .get_cases_by_filename (row [0 ]),
830854 'attributes' : []})
831855
@@ -852,6 +876,9 @@ def load_file_data(self, order_by=""):
852876 if att_name == "Ref_authors" :
853877 tmp = tmp .replace (";" , "\n " )
854878 s ['attributes' ].append (tmp )
879+ # Get reference for file, Vancouver and APA style
880+ # TODO
881+
855882 self .fill_table ()
856883
857884 def get_icon_and_metadata (self , id_ ):
@@ -998,18 +1025,17 @@ def add_attribute(self):
9981025 Then get the attribute type through a dialog.
9991026 AddAttribute dialog checks for duplicate attribute name.
10001027 New attribute is added to the model and database.
1001- Reserved attribute words - usef for imported references:
1028+ Reserved attribute words - used for imported references:
10021029 Ref_Type (Type of Reference) – character variable
10031030 Ref_Author (authors list) – character
10041031 Ref_Title – character
10051032 Ref_Year (of publication) – numeric
1033+ Ref_Journal - character
10061034 """
10071035
10081036 if self .av_dialog_open is not None :
10091037 self .av_dialog_open .mediaplayer .stop ()
10101038 self .av_dialog_open = None
1011- '''check_names = self.attribute_names + [{'name': 'Ref_Type'}, {'name': 'Ref_Author'}, {'name': 'Ref_Title'},
1012- {'name':'Ref_Year'}]'''
10131039 ui = DialogAddAttribute (self .app )
10141040 ok = ui .exec ()
10151041 if not ok :
@@ -2049,7 +2075,7 @@ def fill_table(self):
20492075 for offset , attribute in enumerate (data ['attributes' ]):
20502076 item = QtWidgets .QTableWidgetItem (attribute )
20512077 self .ui .tableWidget .setItem (row , self .ATTRIBUTE_START_COLUMN + offset , item )
2052- if self .attribute_labels_ordered [offset ] in ("Ref_Authors" , "Ref_Title" , "Ref_Type" , "Ref_Year" ):
2078+ if self .attribute_labels_ordered [offset ] in ("Ref_Authors" , "Ref_Title" , "Ref_Type" , "Ref_Year" , "Ref_Journal" ):
20532079 item .setFlags (item .flags () ^ QtCore .Qt .ItemFlag .ItemIsEditable )
20542080 # Resize columns and rows
20552081 self .ui .tableWidget .hideColumn (self .ID_COLUMN )
0 commit comments