def __init__(self, db):
		"""
		Constructor.

		@param db The object, data is handled in as database.DBVoc
		@see database.DBVoc.DBVoc
		"""

		titleWindow = config.getDisplayString('WindowMainTitle')
		titleQuery  = config.getDisplayString('TabQueryTitle')
		titleEdit   = config.getDisplayString('TabEditTitle')
		titleDB     = config.getDisplayString('TabDBTitle')


		Gtk.Window.__init__(self, title = titleWindow)

		db        = db
		self.__db = db
		vocInOut  = VocInOut(db.getColumnMapping())

		vocInOut.setTypeList(db.getTypeList())

		boxOuter = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
		notebook = Gtk.Notebook()

		tabQuery = TabQuery(db, vocInOut)
		tabEdit  = TabEdit (db, vocInOut)
		tabDB    = TabDB   (db, vocInOut)

		pages = {}

		page1 = notebook.append_page(tabQuery, Gtk.Label(titleQuery))
		page2 = notebook.append_page(tabEdit,  Gtk.Label(titleEdit))
		page3 = notebook.append_page(tabDB,    Gtk.Label(titleDB))

		pages[page1] = tabQuery
		pages[page2] = tabEdit
		pages[page3] = tabDB

		self.__pages = pages

		notebook.set_current_page(page1)
		tabQuery.setActive()

		boxOuter.pack_start(vocInOut, True,  True,  0)
		boxOuter.pack_start(notebook, False, False, 0)

		self.add(boxOuter)

		self.connect    ('destroy',self.__handlerDestroy)
		notebook.connect('switch-page',self.__handlerPageChanged)

		(winWidth, winHeight) = self.get_size()
		self.resize(winWidth + 250, winHeight + 75)
Example #2
0
    def __init__(self, path):
        """
		Constructor.

		@param path The Path to the database file to use
		"""
        path = str(path)

        self.__connection = sqlite3.connect(path)
        self.__cursor = self.__connection.cursor()

        self.__cursor.execute(
            """
			CREATE TABLE IF NOT EXISTS Vocabulary(Lang1 TEXT, Lang2 TEXT, Special TEXT, Type TEXT, Info TEXT, Level INTEGER, Timestamp INTEGER);
			"""
        )
        self.__cursor.execute(
            """
			CREATE TABLE IF NOT EXISTS Info(Column TEXT, Title TEXT);
			"""
        )

        self.__cursor.execute(
            """
			SELECT COUNT(*) FROM Info;
			"""
        )

        amount = self.__cursor.fetchone()

        if amount[0] <= 0:
            for (i_column, i_title) in (
                ("Lang1", config.getDisplayString("DBLang1")),
                ("Lang2", config.getDisplayString("DBLang2")),
                ("Special", config.getDisplayString("DBSpecial")),
                ("Type", config.getDisplayString("DBType")),
                ("Info", config.getDisplayString("DBInfo")),
            ):

                self.__cursor.execute(
                    """
					INSERT INTO Info VALUES(?, ?);
					""",
                    (i_column, i_title),
                )

        self.__connection.commit()
Example #3
0
	def __handlerShuffleCurrent(self, widget, data=None):
		amount = self.__db.shuffleCurrent()

		messageText = config.getDisplayString('TDBDiaShuffleInfo') % (amount,)
		dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.INFO, buttons=Gtk.ButtonsType.OK, message_format=messageText)

		dialog.run()
		dialog.destroy()
Example #4
0
	def __handlerExportDB(self, widget, data=None):
		dialog  = Gtk.FileChooserDialog(config.getDisplayString('TDBFCExport'), None, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.OK))
		ffilter = Gtk.FileFilter()
		ffilter.set_name(config.getDisplayString('TDBFFCSV'))
		ffilter.add_pattern('*.csv')
		dialog.set_filter(ffilter)
		dialog.set_filename('vocabDB.csv')

		response = dialog.run()

		if response != Gtk.ResponseType.OK:
			dialog.destroy()
			return

		filename = dialog.get_filename()
		dialog.destroy()

		self.__db.exportToFile(filename)
Example #5
0
	def __handlerResetLevel(self, widget, data=None):
		messageText = config.getDisplayString('TDBDiaResetWarning')
		dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.YES_NO, message_format=messageText)

		response = dialog.run()
		dialog.destroy()

		if response == Gtk.ResponseType.YES:
			self.__db.resetLevel()
Example #6
0
	def addButton(self, buttonId, handler, states=None):
		"""
		Add a button to the BorderBox.

		@param buttonId id of the button string and tooltip
		@param handler Gtk-handler to call when button is clicked
		@param states an array of statenames, the button is sensitive in or None if button is always sensitive
		"""

		caption = config.getDisplayString(buttonId)
		toolTip = config.getTooltipString(buttonId)

		button = Gtk.Button(caption, use_underline=True)

		self.pack_start(button, False, False, 0)

		button.connect('clicked', handler)

		if toolTip:
			button.set_tooltip_text(toolTip)

		self.__addToStates(button, states)
	def __init__(self, db):
		strTitle = config.getDisplayString('DiaStTitle')

		Gtk.Dialog.__init__(self, strTitle, buttons = (Gtk.STOCK_OK, Gtk.ResponseType.OK))

		statistics = db.getStatistics()

		currentAmount = db.getAmountOfCurrentVocab()

		table = Gtk.Table(3, len(statistics) + 6, False)

		labelLeft  = Gtk.Label(config.getDisplayString('DiaStHeadLevel'))
		labelRight = Gtk.Label(config.getDisplayString('DiaStHeadAmount'))

		labelXOpt = Gtk.AttachOptions.FILL

		table.attach(labelLeft,  0, 1, 0, 1, labelXOpt, xpadding=4, ypadding=4)
		table.attach(labelRight, 2, 3, 0, 1, xpadding=4, ypadding=4)

		separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
		table.attach(separator, 0, 3, 1, 2)

		separator = Gtk.Separator(orientation = Gtk.Orientation.VERTICAL)
		table.attach(separator, 1, 2, 0, len(statistics) + 6, labelXOpt)

		vocsum = 0

		for i_val in statistics.values():
			vocsum += i_val

		i = 2

		for i_key in statistics.keys():
			labelLeft   = Gtk.Label(i_key)
			progressbar = Gtk.ProgressBar()
			progressbar.set_text(str(statistics[i_key]))
			progressbar.set_show_text(True)
			progressbar.set_fraction(statistics[i_key]/vocsum)

			table.attach(labelLeft,   0, 1, i, i+1, labelXOpt, xpadding=4, ypadding=4)
			table.attach(progressbar, 2, 3, i, i+1, xpadding=4, ypadding=2)

			i      += 1

		separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
		table.attach(separator, 0, 3, i, i+1)

		i += 1

		labelLeft  = Gtk.Label(config.getDisplayString('DiaStSum'))
		labelRight = Gtk.Label(vocsum)

		table.attach(labelLeft,  0, 1, i, i+1, labelXOpt, xpadding=4, ypadding=4)
		table.attach(labelRight, 2, 3, i, i+1, xpadding=4, ypadding=4)

		i += 1

		separator = Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL)
		table.attach(separator, 0, 3, i, i+1)

		i += 1

		toolTip = config.getTooltipString('DiaStCurAmount')
		labelLeft  = Gtk.Label(config.getDisplayString('DiaStCurAmount'))
		progressbar = Gtk.ProgressBar()
		progressbar.set_text(str(currentAmount))
		progressbar.set_show_text(True)
		progressbar.set_fraction(currentAmount/vocsum)
		if toolTip:
			progressbar.set_tooltip_text(toolTip)
			labelLeft.set_tooltip_text(toolTip)

		table.attach(labelLeft,   0, 1, i, i+1, labelXOpt, xpadding=4, ypadding=4)
		table.attach(progressbar, 2, 3, i, i+1, xpadding=4, ypadding=2)

		table.show_all()

		self.get_content_area().add(table)