Example #1
0
from config.settings import Config
from peewee import MySQLDatabase, Model, PostgresqlDatabase

setting = Config()

if setting.DATABASE_DRIVER == 'mysql':
    database = MySQLDatabase(setting.DB_DATABASE,
                             user=setting.USER_DATABASE,
                             password=setting.DATABASE_PASS,
                             host=setting.DATABASE_HOST,
                             port=setting.DATABASE_PORT)
else:
    database = PostgresqlDatabase(setting.DB_DATABASE,
                                  user=setting.USER_DATABASE,
                                  password=setting.DATABASE_PASS,
                                  host=setting.DATABASE_HOST,
                                  port=setting.DATABASE_PORT)


class BaseModel(Model):
    class Meta:
        database = database
Example #2
0
    def __init__(self):
        super(MainWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)

        self.set_title('bareFTP')
        self.connect("delete_event", self._on_delete)
        self.connect_after('destroy', self._on_delete)
        self.set_default_size(1200, 800)
        self.progresslist = ProgressList()
        self.xferman = XferManager()
        self.xferman.progresslist = self.progresslist
        vbox = Gtk.VBox()
        self.add(vbox)

        action_entries = (
            # name, stock id, label, accelerator, tooltip
            ("FileMenu", None, _("_File")),
            ("HelpMenu", None, _("_Help")),
            ("EditMenu", None, _("_Edit")),
            ("BookmarkMenu", None, _("Bookmarks")),
            ("Bookmarks", Gtk.STOCK_DIRECTORY, _("Bookmarks")),
            ("AddBookmark", Gtk.STOCK_ADD, _("Add bookmark")),
            ("EditBookmarks", Gtk.STOCK_EDIT, _("Edit bookmarks")),
            ("Preferences", Gtk.STOCK_PREFERENCES, _("Preferences"), None,
             None, self.open_prefs),
            ("About", Gtk.STOCK_ABOUT, _("_About"), None, None, self.about_cb),
            ("Quit", Gtk.STOCK_QUIT, _("_Quit"), "<control>Q", None,
             self._quit),
        )

        action_group = Gtk.ActionGroup(name='AppWindowActions')
        action_group.add_actions(action_entries)

        merge = Gtk.UIManager()
        merge.insert_action_group(action_group, 0)
        self.add_accel_group(merge.get_accel_group())

        # Add the top menu bar
        merge.add_ui_from_string(self.get_menu_xml())
        bar = merge.get_widget('/MenuBar')
        vbox.pack_start(bar, False, False, 0)
        #bar.show()

        hbox = Gtk.HBox(False, 6)
        vbox.pack_start(hbox, False, False, 4)

        icon = Gtk.Image.new_from_icon_name(Gtk.STOCK_DIRECTORY,
                                            Gtk.IconSize.MENU)
        bookmarkbtn = BookmarkMenuButton(icon, _('Bookmarks'))

        bu = BookmarkUtils()
        bu.connect('bookmark_clicked', self.activate_bookmark)
        bu.menubar = bar
        bu.build_menus()

        bookmarkbtn.set_menu(bu.get_bookmarks_menu())

        hbox.pack_start(bookmarkbtn, False, False, 0)
        hbox.pack_start(Gtk.Label(_('Host:')), False, False, 0)
        self.entry_host = Gtk.Entry()
        hbox.pack_start(self.entry_host, False, False, 0)
        hbox.pack_start(Gtk.Label(_('Port:')), False, False, 0)
        self.entry_port = Gtk.Entry()
        self.entry_port.set_width_chars(4)
        hbox.pack_start(self.entry_port, False, False, 0)
        hbox.pack_start(Gtk.Label(_('Username:'******'Password:'******'Connect')
        self.btn_connect.connect('clicked', self.conn_clicked)
        hbox.pack_start(self.btn_connect, False, False, 0)

        self.vpaned = Gtk.VPaned()

        self.hpaned = Gtk.HPaned()
        self.vpaned.add(self.hpaned)

        vbox.pack_start(self.vpaned, True, True, 0)

        self.liststore = BareFTPListStore()
        self.fileview = BareFTPFileView(True)
        self.fileview.conn_manager.type = 'LOCAL'
        self.fileview.conn_manager.side = 'LEFT'
        self.liststore2 = BareFTPListStore()
        self.fileview2 = BareFTPFileView(True)
        self.fileview2.conn_manager.type = 'FTP'
        self.fileview2.conn_manager.side = 'RIGHT'
        #fileview.set_model(liststore)

        _hbox = Gtk.HBox()
        _hbox.pack_start(self.fileview, True, True, 0)

        b1 = Gtk.Button()
        b1.props.relief = Gtk.ReliefStyle.NONE
        b2 = Gtk.Button()
        b2.props.relief = Gtk.ReliefStyle.NONE

        img1 = Gtk.Image()
        img1.set_from_pixbuf(lib.icon_loader.load_icon('stock_right'))

        b1.add(img1)
        b1.props.label = None
        b1.connect('clicked', self.upload_click)

        img2 = Gtk.Image()
        img2.set_from_pixbuf(lib.icon_loader.load_icon('stock_left'))

        b2.add(img2)
        b2.props.label = None
        b2.connect('clicked', self.download_click)
        _vbox = Gtk.VBox(True, 12)
        _vbox2 = Gtk.VBox(True, 12)
        _vbox2.pack_start(b1, False, False, 6)
        _vbox2.pack_start(b2, False, False, 6)
        _vbox.pack_start(_vbox2, False, False, 0)
        _vbox.reorder_child(_vbox2, 1)
        _hbox.pack_start(_vbox, False, False, 4)
        self.hpaned.pack1(_hbox, True, True)
        self.hpaned.pack2(self.fileview2, True, True)

        notebook = Gtk.Notebook()
        notebook.props.tab_pos = Gtk.PositionType.BOTTOM

        sw_xfer = Gtk.ScrolledWindow()
        sw_xfer.props.shadow_type = Gtk.ShadowType.ETCHED_IN
        sw_xfer.add(self.progresslist)
        notebook.append_page(sw_xfer, Gtk.Label(_('Transfers')))

        _sw2 = Gtk.ScrolledWindow()
        #_sw2.props.vscrollbar_policy = Gtk.GTK_POLICY_AUTOMATIC
        #_sw2.props.hscrollbar_policy = Gtk.GTK_POLICY_AUTOMATIC

        self.log = Gtk.TextView()

        tag = Gtk.TextTag.new("default")
        tag.props.font = 'Monospace 8'
        self.log.props.buffer.props.tag_table.add(tag)

        tag = Gtk.TextTag.new("welcome")
        tag.props.foreground = "dark green"
        tag.props.font = 'Monospace 8'
        self.log.props.buffer.props.tag_table.add(tag)

        tag = Gtk.TextTag.new("error")
        tag.props.foreground = "red"
        tag.props.font = 'Monospace 8'
        self.log.props.buffer.props.tag_table.add(tag)

        tag = Gtk.TextTag.new("client")
        tag.props.foreground = "dark blue"
        tag.props.font = 'Monospace 8'
        self.log.props.buffer.props.tag_table.add(tag)

        _sw2.add(self.log)
        self.fileview.log = self.log
        self.fileview2.log = self.log
        notebook.append_page(_sw2, Gtk.Label(_('Messages')))

        self.vpaned.add(notebook)
        self.statusbar = Gtk.Statusbar()
        vbox.pack_start(self.statusbar, False, False, 0)

        self.settings = Config()
        self.vpaned.set_position(self.settings.get_vpaned_pos())
        self.hpaned.set_position(self.settings.get_hpaned_pos())

        #self.connect('exposeevent', self.winexposed)
        self.fileview.init()
        self.show_all()