Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #7

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
672 changes: 0 additions & 672 deletions CHANGES

This file was deleted.

4,190 changes: 0 additions & 4,190 deletions ChangeLog

This file was deleted.

592 changes: 343 additions & 249 deletions src/gourmand/Undo.py

Large diffs are not rendered by default.

67 changes: 35 additions & 32 deletions src/gourmand/backends/DatabaseChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,33 @@

class DatabaseChooser:
"""This is a simple interface for getting database information from the user."""
def __init__ (self, okcb=lambda x: debug(x,0), modal=True):

def __init__(self, okcb=lambda x: debug(x, 0), modal=True):
self._okcb = okcb
self.modal = modal
self.possible_dbs = ['sqlite','mysql']
self.possible_dbs = ['sqlite', 'mysql']
self.need_connection_info = ['mysql']
self.need_file_info = ['sqlite']
self.default_file_directory = gglobals.gourmanddir
self.default_files = {'sqlite':'recipes.db'
}
self.default_files = {'sqlite':'recipes.db'}
self.ui = Gtk.Builder()
self.ui.add_from_string(get_data('gourmand', 'ui/databaseChooser.ui').decode())
self.connection_widgets = ['hostEntry','userEntry','pwEntry','dbEntry',
'hostLabel','userLabel','pwLabel','dbLabel',
self.ui.add_from_string(
get_data('gourmand', 'ui/databaseChooser.ui').decode())
self.connection_widgets = ['hostEntry', 'userEntry', 'pwEntry', 'dbEntry',
'hostLabel', 'userLabel', 'pwLabel', 'dbLabel',
'pwCheckButton']
self.file_widgets = ['fileEntry','fileButton','fileLabel']
self.file_widgets = ['fileEntry', 'fileButton', 'fileLabel']
self.widgets = self.file_widgets + self.connection_widgets + ['dbComboBox',
'connectionExpander',
'window']
for w in self.widgets:
setattr(self,w,self.ui.get_object(w))
setattr(self, w, self.ui.get_object(w))
self.ui.connect_signals(
{'ok_clicked':self.ok_cb,
'cancel_clicked':self.cancel_cb,
'dbChanged':self.change_db_cb,
'browse_clicked':self.browse_cb}
)
{'ok_clicked': self.ok_cb,
'cancel_clicked': self.cancel_cb,
'dbChanged': self.change_db_cb,
'browse_clicked': self.browse_cb}
)
self.pwEntry.set_visibility(False)
self.dbComboBox.set_active(0)
self.connectionExpander.set_expanded(False)
Expand All @@ -46,41 +47,43 @@ def __init__ (self, okcb=lambda x: debug(x,0), modal=True):
if self.modal:
self.window.set_modal(True)

def run (self):
def run(self):
if self.modal:
Gtk.mainloop()
return self.retdic

def ok_cb (self, *args):
def ok_cb(self, *args):
if not self.current_db:
de.show_message(label='No database selected.',
sublabel='You need to select a database system.')
else:
self.retdic = {'db_backend':self.current_db}
self.retdic = {'db_backend': self.current_db}
if self.current_db in self.need_connection_info:
for e in self.connection_widgets:
if e.find('Entry') >= 0:
self.retdic[e[0:e.find('Entry')]]=getattr(self,e).get_text()
self.retdic['store_pw']=self.pwCheckButton.get_active()
self.retdic[e[0:e.find('Entry')]] = getattr(
self, e).get_text()
self.retdic['store_pw'] = self.pwCheckButton.get_active()
if self.current_db in self.need_file_info:
fi = self.fileEntry.get_text()
if fi and fi.find(os.path.sep) < 0:
fi = os.path.join(self.default_file_directory,fi)
self.retdic['file']=fi
fi = os.path.join(self.default_file_directory, fi)
self.retdic['file'] = fi
self.window.hide()
self.window.destroy()
if self._okcb: self._okcb(self.retdic)
if self._okcb:
self._okcb(self.retdic)
if self.modal:
Gtk.mainquit()
return self.retdic

def cancel_cb (self, *args):
def cancel_cb(self, *args):
self.window.hide()
self.window.destroy()
if self.modal: Gtk.mainquit()

if self.modal:
Gtk.mainquit()

def change_db_cb (self, *args):
def change_db_cb(self, *args):
self.current_db = None
text = cb.cb_get_active_text(self.dbComboBox)
if not text:
Expand All @@ -92,19 +95,19 @@ def change_db_cb (self, *args):
if self.current_db in self.need_connection_info:
self.connectionExpander.set_expanded(True)
for w in self.connection_widgets:
getattr(self,w).show()
getattr(self, w).show()
else:
for w in self.connection_widgets:
getattr(self,w).hide()
getattr(self, w).hide()
for w in self.file_widgets:
if self.current_db in self.need_file_info:
getattr(self,w).show()
getattr(self, w).show()
else:
getattr(self,w).hide()
getattr(self, w).hide()
if self.current_db in self.default_files:
self.fileEntry.set_text(self.default_files[self.current_db])

def browse_cb (self,*args):
def browse_cb(self, *args):
fi = de.select_file(_("Choose Database File"),
filename=self.default_file_directory,
action=Gtk.FileChooserAction.OPEN)
Expand All @@ -113,5 +116,5 @@ def browse_cb (self,*args):


if __name__ == '__main__':
d = DatabaseChooser(None,modal=True)
d = DatabaseChooser(None, modal=True)
print(d.run())
Loading