Exemple #1
0
 public static void SpeakWord(Word w)
 {
     if (!WavFilePlayer(w))
     {
         EspeakTTS(w, "eo", false);
     }
 }
        public EditCardWindow(Word current_word)
        {
            this.current_word = current_word;
            InitializeComponent();

            QuestionBox.Text = current_word.question;
            AnswerBox.Text = current_word.answer;
            ExampleBox.Text = current_word.example;
            StudiedBox.IsChecked = current_word.studied;
            WavFileBox.Text = current_word.wav_file_loc;
            ImageFileBox.Text = current_word.image_file_location;
        }
Exemple #3
0
        public static bool EspeakTTS(Word w, string lang, bool _generate_wav)
        {
            string espeak_binary_location = PamyaSettings.Instance.GetSetting("espeakbin");
            Dictionary<string, string> eo_string_replace_dict = new Dictionary<string, string>();
            eo_string_replace_dict.Add("Ĝ", "Gx"); //FIXME
            eo_string_replace_dict.Add("ĝ", "gx");
            eo_string_replace_dict.Add("Ĥ", "Hx");
            eo_string_replace_dict.Add("ĥ", "hx");
            eo_string_replace_dict.Add("Ĵ", "Jx");
            eo_string_replace_dict.Add("ĵ", "jx");
            eo_string_replace_dict.Add("Ŝ", "Sx");
            eo_string_replace_dict.Add("ŝ", "sx");
            eo_string_replace_dict.Add("Ĉ", "Cx");
            eo_string_replace_dict.Add("ĉ", "cx");
            eo_string_replace_dict.Add("Ŭ", "Ux");
            eo_string_replace_dict.Add("ŭ", "ux");
            eo_string_replace_dict.Add("-", "_");
            eo_string_replace_dict.Add(" ", "_");
            eo_string_replace_dict.Add("!", "_");
            eo_string_replace_dict.Add(",", "_");
            var text = eo_string_replace_dict.Aggregate(w.Target, (current, value) =>
                current.Replace(value.Key, value.Value));
            if (File.Exists(espeak_binary_location) && (! _generate_wav))
            {
                //ugly stuff for now

                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = espeak_binary_location;
                startInfo.Arguments = "-v " + lang + " \"" + text + "\"";
                process.StartInfo = startInfo;
                process.Start();
                return true;
            }
            else if (File.Exists(espeak_binary_location) && _generate_wav)
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = espeak_binary_location;
                startInfo.Arguments = "-w " + text + ".wav " + "-v " + lang + " \"" + text + "\"";
                startInfo.WorkingDirectory = PamyaDeck.Instance.CurrentDeckFolder;
                process.StartInfo = startInfo;
                process.Start();
                w.SoundFileLocation = text + ".wav ";
                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #4
0
 private static bool WavFilePlayer(Word w)
 {
     var wav_file_loc = PamyaDeck.Instance.CurrentDeckFolder + @"\" + w.SoundFileLocation;
     if (File.Exists(wav_file_loc))
     {
         SoundPlayer my_wave_file = new SoundPlayer(wav_file_loc);
         my_wave_file.Play();
         return true;
     }
     else
     {
         return false;
     }
 }
Exemple #5
0
 public void fillDeckFromString(string s)
 {
     dc = new List<Word>();
     int id = 0;
     foreach (string l in s.Split('\n'))
     {
         string[] ws = l.Split('|');
         id++;
         string guid = new Guid().ToString();
         Word word = new Word(ws[0].Trim(), ws[1].Trim());
         word.id = id;
         word.guid = guid;
         dc.Add(word);
     }
 }
        public EditCardDialog(Word ToEditWord)
        {
            CurrentWord = ToEditWord.Clone();

            Translations = new BindingList<StringWrapper>((from s in CurrentWord.Translations select new StringWrapper { Value = s }).ToList());
            Examples = new BindingList<StringWrapper>((from s in CurrentWord.Examples select new StringWrapper { Value = s }).ToList());

            if (Translations.Count == 0) { Translations.Add(new StringWrapper { Value = "" }); }
            if (Examples.Count == 0) { Examples.Add(new StringWrapper { Value = "" }); }

            InitializeComponent();

            Translations.ListChanged += TranslationsListChanged;
            Examples.ListChanged += ExamplesListChanged;

            _DisplayDesc();
            bCanDo = true;
            //_DisplayImage();
        }
        private void Save_Button_Click(object sender, RoutedEventArgs e)
        {
            current_word.question = QuestionBox.Text;
            current_word.answer = AnswerBox.Text;
            current_word.example = ExampleBox.Text;
            current_word.studied = (bool)StudiedBox.IsChecked;
            current_word.wav_file_loc = WavFileBox.Text;
            current_word.image_file_location = ImageFileBox.Text;

            if ((bool)ResetWordBox.IsChecked)
            {
                Word w = new Word("", "");
                current_word.I = w.I;
                current_word.EF = w.EF;
                current_word.n = w.n;
                current_word.studied = w.studied;
                current_word.time_due = w.time_due;
            }

            this.Close();
        }
Exemple #8
0
 public string FindWordPageTranslationOnly(Word word)
 {
     //Word word = PamyaDeck.Instance.CurrentDeck.Words.Find(w => w.sGuid == sGuid);
     var translationText = string.Join(", ", word.Translations);
     var translations = FormatTranslationsFirst(word);
     var rootElement =
         new XElement("content", translations);
     return rootElement.ToString();
 }
Exemple #9
0
 public void AddWord(Word w)
 {
     dc.Add(w);
 }
Exemple #10
0
        public Queue<Word> RandomWords(int amount, Word exclude)
        {
            Queue<Word> ws = new Queue<Word>();
            dc.Shuffle();
            int offset = 0;
            bool bExclude = dc.Count > 1;
            if (dc.Count == 0)
            {
                for (int i = 0; i < amount + 1; i++)
                {
                    ws.Enqueue(new Word("TOO", "TOO SHORT"));
                }
            }
            else
            {
                for (int i = 0; i < amount + 1; )
                {
                    if (i + offset == dc.Count)
                    {
                        i = 0;
                        offset = 0;
                    }
                    if (bExclude && dc[i + offset].question == exclude.question)
                    {
                        offset++;
                    }
                    else
                    {
                        ws.Enqueue(dc[i + offset]);

                        i++;
                    }
                }
            }
            return ws;
        }
Exemple #11
0
 private XElement FormatTranslationsFirst(Word word)
 {
     var translations = new XElement("paragraph");
     if (word.Translations.Count > 0)
         translations.Add(new XElement("h1", word.Translations[0]));
     if (word.Translations.Count > 1)
     {
         translations.Add(new XElement("br"));
         foreach (var t in word.Translations.GetRange(1, word.Translations.Count - 1))
         {
             var textEl = new XElement("text", t + "    ");
             textEl.SetAttributeValue("Colour", "#333333");
             translations.Add(textEl);
         }
     }
     return translations;
 }
Exemple #12
0
 private XElement FormatTranslationsAfter(Word word)
 {
     var translations = new XElement("paragraph");
     if (word.Translations.Count > 0)
     {
         translations.Add(new XElement("br"));
         foreach (var t in word.Translations)
         {
             var textEl = new XElement("text", t + "    ");
             textEl.SetAttributeValue("Colour", "#333333");
             translations.Add(textEl);
         }
     }
     return translations;
 }
Exemple #13
0
 public List<LinkSpan> GetWordPageSpansTranslationPlusElse(Word w)
 {
     return ParseMarkUp(FindWordPageTranslationPlusElse(w));
 }
        private void _AddCard(object sender, EventArgs e)
        {
            Word word = (Word)DeckDataGrid.SelectedItem;
            int selectedOrder;
            if (word != null)
                selectedOrder = word.OrderId;
            else
                selectedOrder = 1;

            Word newWord = new Word
            {
                Translations = new List<string> { "Verbum" },
                Target = "Novum",
                EF = Word.DEFAULT_EF,
                I = Word.DEFAULT_I,
                n = Word.DEFAULT_N,
                bStudied = false,
                TimeDue = 0,
                SoundFileLocation = "",
                Examples = new List<string> { "" },
                XMLDescription = "",
                sGuid = Guid.NewGuid().ToString(),
                ImageFileLocation = "",
                Id = Words.Max(tw => tw.Id)+1,
                OrderId = selectedOrder,
            };

            foreach (Word w in Words.FindAll(tw => tw.OrderId >= selectedOrder))
            {
                w.OrderId += 1;
            }

            Words.Add(newWord);

            SortView();
        }
        private Word _EditCardDialog(Word word)
        {
            var editCardDialog = new EditCardDialog(word);
            editCardDialog.ShowDialog();

            if (editCardDialog.DialogResult.Value)
            {
                return editCardDialog.CurrentWord;

            }
            return word;
        }
Exemple #16
0
        public string FindWordPage(Word word)
        {
            //Word word = PamyaDeck.Instance.CurrentDeck.Words.Find(w => w.sGuid == sGuid);
            var translations = FormatTranslationsAfter(word);
            var examples = new XElement("paragraph");
            foreach (var example in word.Examples)
            {
                examples.Add(example);
                examples.Add(new XElement("br"));
            }
            var rootElement =
                new XElement("content",
                    new XElement("paragraph",
                        new XElement("h1", word.Target)
                    ),

                //new XElement("h2","Translations"),
                    translations,
                    new XElement("br"),
                    new XElement("paragraph", word.XMLDescription),
                    new XElement("h2", "Examples"),
                    examples
                );
            return rootElement.ToString();
        }
Exemple #17
0
 public void UpdateDeckDB(Word w)
 {
     UpdateDeckDB(new List<Word>() { w });
 }
Exemple #18
0
 public void AddWord(Word w)
 {
     Words.Add(w);
 }
Exemple #19
0
        public Queue<Word> RandomWords(int amount, Word exclude)
        {
            Queue<Word> ws = new Queue<Word>();
            Words.Shuffle(); //Don't do this

            int offset = 0;
            bool bExclude = Words.Count > 1;
            if (Words.Count == 0)
            {
                for (int i = 0; i < amount + 1; i++)
                {
                    ws.Enqueue(new Word("TOO", "TOO SHORT"));
                }
            }
            else
            {
                for (int i = 0; i < amount + 1; )
                {
                    if (i + offset == Words.Count)
                    {
                        i = 0;
                        offset = 0;
                    }
                    if (bExclude && Words[i + offset].sGuid == exclude.sGuid)
                    {
                        offset++;
                    }
                    else
                    {
                        ws.Enqueue(Words[i + offset]);

                        i++;
                    }
                }
            }
            Words = Words.OrderBy(a => a.OrderId).ToList();
            return ws;
        }
Exemple #20
0
        public string FindWordPageTranslationPlusElse(Word word)
        {
            //Word word = PamyaDeck.Instance.CurrentDeck.Words.Find(w => w.sGuid == sGuid);
            var separator = new XElement("br");
            var translationText = string.Join(", ", word.Translations);
            var translations = FormatTranslationsFirst(word);
            XElement image = null;
                if(! string.IsNullOrEmpty(word.ImageFileLocation)) {
                     image = new XElement("paragraph",
                        new XElement("img", word.ImageFileLocation)
                    );
                }

            XElement examples = null;
            if (word.Examples != null)
            {
                examples = new XElement("paragraph");
                word.Examples.RemoveAll(ex => string.IsNullOrEmpty(ex));
                if (word.Examples.Count > 0)
                {
                    examples.Add(new XElement("h2", "Examples"));
                }
                foreach (var example in word.Examples)
                {
                    examples.Add(example);
                    examples.Add(separator);
                }
            }

            XElement desc = null;//, );
            if (! string.IsNullOrEmpty(word.XMLDescription))
            {
                desc = new XElement("paragraph");
                desc.Add(new XElement("h2", "Description"));
                desc.Add(word.XMLDescription);
            }
            var rootElement =
                new XElement("content", translations);
            if (desc != null)
                rootElement.Add(desc);
            if (examples != null)
                rootElement.Add(examples);
            if (image != null)
                rootElement.Add(image);
            //MessageBox.Show(rootElement.ToString(SaveOptions.DisableFormatting));
            return rootElement.ToString(SaveOptions.DisableFormatting);
        }
Exemple #21
0
 public List<LinkSpan> GetWordPageSpans(Word w)
 {
     return ContentMarkupToWPF(FindWordPage(w));
 }
Exemple #22
0
        public void _OpenDeck(string FileName, int GameType)
        {
            //this.Title = "Pamya - " + fname; //FIXME
            CurrentDeckFolder = DecksFolder + @"\" + FileName;
            DeckFile = CurrentDeckFolder + @"\deck.sqlite";

            UserFile = CurrentDeckFolder + @"\userdata.sqlite";

            //I feel like this is too much overhead
            SQLiteConnection deckdbcon;
            deckdbcon =
            new SQLiteConnection("Data Source=" + DeckFile + ";Version=3;");
            deckdbcon.Open();

            SQLiteConnection userdbcon;
            userdbcon =
            new SQLiteConnection("Data Source=" + UserFile + ";Version=3;");
            userdbcon.Open();

            string sql = "SELECT * FROM deck ORDER BY id ASC";
            SQLiteCommand command = new SQLiteCommand(sql, deckdbcon);
            SQLiteDataReader deck_reader = command.ExecuteReader();

            CurrentDeck = new Deck();

            while (deck_reader.Read())
            {
                var word = new Word(deck_reader["question"].ToString(), deck_reader["answer"].ToString());
                word.id = Convert.ToInt32(deck_reader["id"]);
                word.wav_file_loc = deck_reader["wavfileloc"].ToString();
                word.guid = deck_reader["guid"].ToString();
                word.example = deck_reader["example"].ToString();
                word.image_file_location = deck_reader["imagefileloc"].ToString();
                var user_sql = "SELECT * FROM deck WHERE guid='" + deck_reader["guid"].ToString() + "'";
                var user_command = new SQLiteCommand(user_sql, userdbcon);
                try
                {
                    var user_reader = user_command.ExecuteReader();
                    user_reader.Read();
                    word.EF = Convert.ToDouble(user_reader["ef"]);
                    word.I = Convert.ToDouble(user_reader["i"]);
                    word.n = Convert.ToInt32(user_reader["n"]);
                    word.studied = Convert.ToBoolean(user_reader["studied"]);
                    word.time_due = Convert.ToInt32(user_reader["timedue"]);
                    user_reader.Close();
                    CurrentDeck.AddWord(word);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }

            deck_reader.Close();

            userdbcon.Close();
            deckdbcon.Close();

            //TODO
            //FIND OUT WHICH GAME IS PLAYED

            //OPEN THE GAME

            GameChangeDelegates[GameType + 1].DynamicInvoke(); // +1 as 0 is the mainmenu page
        }
Exemple #23
0
        private void _InsertCardAfter(object sender, RoutedEventArgs e)
        {
            if (lvCards.SelectedIndex > -1)
            {
                int index = lvCards.SelectedIndex;
                int id = index + 1;
                foreach (Word w in deck.dc.Where(x => x.id > id))
                {
                    w.id++;
                }
                Word new_word = new Word("Novum", "Verbum");
                new_word.id = id + 1;

                deck.dc.Insert(index + 1, new_word);
            }
            ShowDeck();
        }