def action_save_handler(self):
     if self._code_from_file and self._is_dirty:
         content = CodeComposer.compose(self.ui.txtGlobalExp.toPlainText(), self.ui.txtFieldExp.toPlainText())
         with codecs.open(self._code_from_file, 'w', encoding='utf-8') as content_file:
             content_file.write(content)
         self._is_dirty = False
         self.update_btn_status()
 def action_save_as_handler(self):
     file_name = QFileDialog.getSaveFileName(self, self.tr('Save code to file...'), filter=self._filter)
     if file_name:
         content = CodeComposer.compose(self.ui.txtGlobalExp.toPlainText(), self.ui.txtFieldExp.toPlainText())
         with codecs.open(file_name, 'w', encoding='utf-8') as content_file:
             content_file.write(content)
             self._code_from_file = file_name
             self._is_dirty = False
             self.update_btn_status()
 def action_open_handler(self):
     #TODO: Add _is_dirty flag check
     file_name = QFileDialog.getOpenFileName(self, self.tr('Open file with code...'), filter=self._filter)
     if file_name:
         if path.exists(file_name):
             with codecs.open(file_name, 'r', encoding='utf-8') as content_file:
                 content = content_file.read()
             glob_code, local_code = CodeComposer.decompose(content)
             self.ui.txtGlobalExp.setText(glob_code)
             self.ui.txtFieldExp.setText(local_code)
             if glob_code:
                 self.ui.grpGlobalExpression.setChecked(True)
             else:
                 self.ui.grpGlobalExpression.setChecked(False)
             self._code_from_file = file_name
             self._is_dirty = False
             self.update_btn_status()
         else:
             QMessageBox.warning(self, self.tr('FieldPyculator warning'), self.tr('No such file: ') + file_name)