Esempio n. 1
0
class FileManager(HPaned):
    HOME_DIR = os.getenv("HOME", "") + "/"
    ICONVIEW = 0
    TREEVIEW = 1

    def __init__(self,
                 dir=HOME_DIR,
                 view_mode=ICONVIEW
                ):
        HPaned.__init__(self)
        self.categorybar = Categorybar([
            (ui_theme.get_pixbuf("filemanager/computer.png"), _("Computer"), None),
            (ui_theme.get_pixbuf("filemanager/user-home.png"), _("Home"), lambda : self.open_dir(self.HOME_DIR)),
            (ui_theme.get_pixbuf("filemanager/user-desktop.png"), _("Desktop"), lambda : self.open_dir(self.HOME_DIR + "Desktop/")),
            (ui_theme.get_pixbuf("filemanager/folder-documents.png"), _("Documents"), lambda : self.open_dir(self.HOME_DIR + "Documents/")),
            (ui_theme.get_pixbuf("filemanager/folder-download.png"), _("Downloads"), lambda : self.open_dir(self.HOME_DIR + "Downloads/")),
            (ui_theme.get_pixbuf("filemanager/folder-music.png"), _("Music"), lambda : self.open_dir(self.HOME_DIR + "Music/")),
            (ui_theme.get_pixbuf("filemanager/folder-pictures.png"), _("Pictures"), lambda : self.open_dir(self.HOME_DIR + "Pictures/")),
            (ui_theme.get_pixbuf("filemanager/folder-videos.png"), _("Videos"), lambda : self.open_dir(self.HOME_DIR + "Videos/")),
            (ui_theme.get_pixbuf("filemanager/user-trash.png"), _("Trash"), lambda : self.open_dir("trash:///"))
            ])
        self.icon_size = 48
        self.iconview = FileIconView()
        self.iconview.add_items(iconview_get_dir_items(dir, self.icon_size))
        self.treeview = TreeView(get_dir_items(dir))
        self.add1(self.categorybar)
        if view_mode == self.ICONVIEW:
            self.add2(self.iconview)
        else:
            self.add2(self.treeview)

    def open_dir(self, dir):
        self.iconview.add_items(iconview_get_dir_items(dir), True)
        self.treeview.add_items(get_dir_items(dir), None, True)
Esempio n. 2
0
 def __init__(self, dir=HOME_DIR, view_mode=ICONVIEW):
     HPaned.__init__(self)
     self.categorybar = Categorybar([
         (ui_theme.get_pixbuf("filemanager/computer.png"), _("Computer"),
          None),
         (ui_theme.get_pixbuf("filemanager/user-home.png"), _("Home"),
          lambda: self.open_dir(self.HOME_DIR)),
         (ui_theme.get_pixbuf("filemanager/user-desktop.png"), _("Desktop"),
          lambda: self.open_dir(self.HOME_DIR + "Desktop/")),
         (ui_theme.get_pixbuf("filemanager/folder-documents.png"),
          _("Documents"),
          lambda: self.open_dir(self.HOME_DIR + "Documents/")),
         (ui_theme.get_pixbuf("filemanager/folder-download.png"),
          _("Downloads"),
          lambda: self.open_dir(self.HOME_DIR + "Downloads/")),
         (ui_theme.get_pixbuf("filemanager/folder-music.png"), _("Music"),
          lambda: self.open_dir(self.HOME_DIR + "Music/")),
         (ui_theme.get_pixbuf("filemanager/folder-pictures.png"),
          _("Pictures"),
          lambda: self.open_dir(self.HOME_DIR + "Pictures/")),
         (ui_theme.get_pixbuf("filemanager/folder-videos.png"), _("Videos"),
          lambda: self.open_dir(self.HOME_DIR + "Videos/")),
         (ui_theme.get_pixbuf("filemanager/user-trash.png"), _("Trash"),
          lambda: self.open_dir("trash:///"))
     ])
     self.icon_size = 48
     self.iconview = FileIconView()
     self.iconview.add_items(iconview_get_dir_items(dir, self.icon_size))
     self.treeview = TreeView(get_dir_items(dir))
     self.add1(self.categorybar)
     if view_mode == self.ICONVIEW:
         self.add2(self.iconview)
     else:
         self.add2(self.treeview)
Esempio n. 3
0
def show_layout(layout, keys):
    from naive import NaiveBST
    from treeview import TreeView

    t = NaiveBST()
    tv = TreeView(t, layout_algorithm=layout)

    for key in keys:
        t.insert(key)
        tv.view()
Esempio n. 4
0
    def __init__(self, parent, rootdir="/"):
        TreeView.__init__(self, parent)
        self.rootdir = rootdir

        imagelist = ImageList(16, 16)
        art = ArtProvider((16, 16))
        imagelist.Add(art.GetBitmap('folder', 'other'), 'folder')
        imagelist.Add(art.GetBitmap('file_open', 'other'), 'folder_open')
        self.SetImageList(imagelist)

        self.MakeRoot()
Esempio n. 5
0
    def __init__(self, parent, rootdir="/"):
        TreeView.__init__(self, parent)
        self.rootdir = rootdir

        imagelist = ImageList(16, 16)
        imagelist.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16,16)), 'folder')
        imagelist.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, (16,16)), 'folder_open')
        self.SetImageList(imagelist)
        # XXX will need to be rewritten once Wax supports the ArtProvider

        self.MakeRoot()
Esempio n. 6
0
    def __init__(self, parent):
        tk.Tk.__init__(self, parent)
        self.parent = parent
        self.resizable(0, 0)

        self.geometry("1200x800")

        self.setting_frame = LabelFrame(self, text="Setting")

        create_btn = Button(self.setting_frame,
                            text="Create",
                            height=1,
                            width=10,
                            command=self.create)
        create_btn.grid(row=0, padx=5, pady=5)
        insert_btn = Button(self.setting_frame,
                            text="Insert",
                            height=1,
                            width=10,
                            command=self.insert)
        insert_btn.grid(row=2, padx=5, pady=5)
        # self.insert_e = Entry(self.setting_frame, height=1, width=10)
        self.insert_e = Entry(self.setting_frame)
        self.insert_e.grid(row=2, column=1, padx=5, pady=5)

        delete_btn = Button(self.setting_frame,
                            text="Delete",
                            height=1,
                            width=10,
                            command=self.delete)
        delete_btn.grid(row=4, padx=5, pady=5)
        # self.delete_e = Entry(self.setting_frame, height=1, width=10)
        self.delete_e = Entry(self.setting_frame)
        self.delete_e.grid(row=4, column=1, padx=5, pady=5)

        search_btn = Button(self.setting_frame,
                            text="Search",
                            height=1,
                            width=10,
                            command=self.search)
        search_btn.grid(row=6, padx=5, pady=5)
        # self.search_e = Entry(self.setting_frame, height=1, width=10)
        self.search_e = Entry(self.setting_frame)
        self.search_e.grid(row=6, column=1, padx=5, pady=5)

        # self.setting_frame.grid(row=1, padx=5, pady=5, sticky=N+S)
        self.setting_frame.pack(padx=5, pady=5, side=LEFT)
        self.drawing_frame = tk.LabelFrame(self, text="Drawing")
        # self.drawing_frame.grid(row=1, column=2, padx=5, pady=5, sticky=N+S)
        self.drawing_frame.pack(padx=5, pady=5, fill=BOTH, expand=1)

        self.tree = NaiveBST()
        self.treeview = TreeView(self.drawing_frame, tree=self.tree)

        def callback():
            if messagebox.askokcancel("Quit", "Do you really wish to quit?"):
                self.destroy()
                self.treeview.end_pause = True

        self.protocol("WM_DELETE_WINDOW", callback)
Esempio n. 7
0
def start_viewfs():
    if args.rebuild or not os.path.exists(config.watch.catalog_path):
        logger.info('building catalog...')
        catalog = Catalog.build(config.watch.collection_root)
        catalog.save(config.watch.catalog_path)
        catalog = None
        gc.collect()

    if args.rebuild:
        sys.exit(0)

    logging.basicConfig(
        level=logging.DEBUG if config.verbose else logging.INFO)

    watch_process = subprocess.Popen(['python3', 'watch.py'])

    logger.info('building tree...')
    catalog = Catalog.load(config.watch.catalog_path,
                           config.watch.collection_root)
    tree_view = TreeView.from_catalog(catalog)
    catalog = None
    gc.collect()

    notifier = SystemNotifier()

    if watch_process.poll() != None:
        # watch crashed
        notifier.stopping()
        sys.exit(2)

    logger.info('mounting filesystem on ' + config.view.view_root)
    filesystem = Filesystem(logger, tree_view)
    notifier.ready()
    filesystem.start()
Esempio n. 8
0
    def __init__(self):
        super(MainWindow, self).__init__()

        widget = QWidget()
        self.setCentralWidget(widget)

        fileMenu = self.menuBar().addMenu("File")
        newRepository = fileMenu.addAction("New Repository")
        openRepository = fileMenu.addAction("Open Repository")
        rollbackRepository = fileMenu.addAction("Discard last commit")

        newRepository.triggered.connect(self.create_new_repository)
        openRepository.triggered.connect(self.open_repository)
        rollbackRepository.triggered.connect(self.discard_last_commit)

        self.button = QPushButton("hello there")

        container = QVBoxLayout()
        menuContainer = QHBoxLayout()
        topContainer = QHBoxLayout()
        bottomContainer = QHBoxLayout()
        self.console = Console(bottomContainer)
        self.tree = TreeView(topContainer)

        container.addLayout(menuContainer, 0)
        container.addLayout(topContainer, 5)
        container.addLayout(bottomContainer, 3)
        self.tabs = TabView(topContainer)

        widget.setLayout(container)
Esempio n. 9
0
    def __init__(self):
        col_names = []
        col_names.append({'index': 0, 'name': 'Interface'})
        col_names.append({'index': 1, 'name': 'IP Address'})
        col_names.append({'index': 2, 'name': 'NetMask'})
        col_names.append({'index': 3, 'name': 'MAC Address'})
        col_names.append({'index': 4, 'name': 'Bytes Recv'})
        col_names.append({'index': 5, 'name': 'Bytes Sent'})
        col_names.append({'index': 6, 'name': 'Packets Recv'})
        col_names.append({'index': 7, 'name': 'Packets Sent'})

        self._iface_iter = []
        cols_type = [str, str, str, str, str, str, str, str]
        TreeView.__init__(self, cols_type, col_names)

        self._dev = NetDevice()
        self.show_all()
        gobject.timeout_add(1500, self._update_data)
Esempio n. 10
0
    def __init__(self):
        col_names = []
        col_names.append({'index': 0, 'name': _('PID')})
        col_names.append({'index': 1, 'name': _('Resource Base')})
        col_names.append({'index': 2, 'name': _('Pixmap Bytes')})
        col_names.append({'index': 3, 'name': _('Other')})
        col_names.append({'index': 4, 'name': _('Total')})
        col_names.append({'index': 5, 'name': _('Window Name')})

        self._window_iter = []

        cols_type = [str, str, str, str, str, str]
        TreeView.__init__(self, cols_type, col_names)

        self._proc = ProcInfo()
        self._xres = XRes()
        self._display = self._xres.open_display()
        self.show_all()
        gobject.timeout_add(1500, self._update_data)
Esempio n. 11
0
def text_parse(grammar, sent, trace=2, drawtrees=False, latex=False):
    parser = grammar.earley_parser(trace=trace)
    print parser._grammar
    tokens = sent.split()
    trees = parser.get_parse_list(tokens)
    if drawtrees:
        from treeview import TreeView
        TreeView(trees)
    else:
        for tree in trees:
            if latex: print tree.latex_qtree()
            else: print tree
Esempio n. 12
0
def text_parse(grammar, sent, trace=2, drawtrees=False, latex=False):
    parser = grammar.earley_parser(trace=trace)
    print(parser._grammar)
    tokens = list(tokenize.whitespace(sent))
    trees = parser.get_parse_list(tokens)
    if drawtrees:
        from treeview import TreeView
        TreeView(trees)
    else:
        for tree in trees:
            if latex: print(tree.latex_qtree())
            else: print(tree)
Esempio n. 13
0
def text_parse(grammar, sentence, trace=2, drawtrees=False, latex=False):
    parser = grammar.earley_parser(trace=trace)
    print parser._grammar
    sent = Token(TEXT=sentence)
    WhitespaceTokenizer().tokenize(sent)
    parser.parse_n(sent)
    if drawtrees:
        from treeview import TreeView
        TreeView(sent['TREES'])
    else:
        for tree in sent['TREES']:
            if latex: print tree.latex_qtree()
            else: print tree
Esempio n. 14
0
def main():
    from treeview import TreeView
    from random import shuffle
    from naive import NaiveBST, perfect_inserter

    t = NaiveBST()
    v = TreeView(t)

    keys = list(range(20))
    shuffle(keys)
    print(keys)

    # for i in keys:
    #     t.insert(i)
    perfect_inserter(t, sorted(keys))

    t.view()

    dsw(t, advanced=True)
Esempio n. 15
0
def usage():
    import random
    random.seed(0)  # do always the same for testing

    # tree = NaiveBST()
    # print(tree)
    # print()

    # tree.insert(2)
    # print(tree)
    # print()

    # tree.insert(1)
    # print(tree)
    # print()

    # tree.insert(3)
    # print(tree)
    # print()

    # print("Random insertions")
    # tree = NaiveBST()
    # for i in range(10):
    #   n = random.randint(1,20)
    #   print("insert", n)
    #   tree.insert(n)
    #   print(tree, end="\n\n")

    tree = NaiveBST()
    n = 16
    universe = list(range(n))
    random.shuffle(universe)
    for key in universe:
        tree.insert(key)
    # print(tree)
    # print(tree.preorder())

    node5 = tree.root.left
    node5.rotate()
    print(tree)
    # print(' '.join([str(key) for key in tree.preorder()]))

    from treeview import TreeView
    tv = TreeView(tree)
    tv.view()
    tree.root.right.rotate()
    tv.view()
    print(tree.search_functional(4))
Esempio n. 16
0
def join():
    t = NaiveBST()

    t.insert(7)
    t.insert(4)
    t.insert(2)
    t.insert(6)
    t.insert(1)
    t.insert(3)
    t.insert(5)
    t.insert(9)
    t.insert(8)
    t.insert(10)

    from viewer.treeview import TreeView
    tv = TreeView(t)
    tv.view()

    p = t.root
    p.left.rotate()
    tv.view()
    p.left.rotate()
    tv.view()
Esempio n. 17
0
class SonstigeAusgabenView(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        self._calendarIcon = QIcon("../images/calendar25x25.png")
        self.setWindowTitle(
            "Sonstige Ausgaben: Rechnungen, Abgaben, Gebühren etc.")
        self._gridLayout = QtWidgets.QGridLayout(self)
        self._gridLayout.setObjectName("gridLayout")

        #### save button
        btn = QPushButton()
        btn.clicked.connect(self.onSave)
        btn.setFlat(True)
        btn.setEnabled(False)
        btn.setToolTip("Änderungen dieser View speichern")
        icon = QIcon("../images/save_30.png")
        btn.setIcon(icon)
        size = QSize(30, 30)
        btn.setFixedSize(size)
        iconsize = QSize(30, 30)
        btn.setIconSize(iconsize)
        self._gridLayout.addWidget(btn, 0, 0, 1, 1)
        self._btnSave = btn

        self._cboBuchungsjahr = QtWidgets.QComboBox(self)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self._cboBuchungsjahr.setFont(font)
        self._cboBuchungsjahr.setToolTip(
            "Das hier eingestellte Jahr bestimmt die Rechnungen, die in der Tabelle angezeigt werden."
        )
        self._cboBuchungsjahr.currentIndexChanged.connect(
            self._buchungsjahrChanged)
        self._gridLayout.addWidget(self._cboBuchungsjahr, 1, 0, 1, 1)

        self._ddmmBuchung = QtWidgets.QLineEdit(self)
        self._ddmmBuchung.setToolTip(
            "Buchungstag und -monat. Tag und Monat mit \',\' oder \'.\' trennen."
        )
        self._ddmmBuchung.setPlaceholderText("Buchungstag u. -monat")
        self._gridLayout.addWidget(self._ddmmBuchung, 1, 1, 1, 1)

        btn = QPushButton(self)
        btn.setMaximumSize(QSize(25, 25))
        btn.setIcon(self._calendarIcon)
        btn.clicked.connect(self._onShowBuchungCalendar)
        self._gridLayout.addWidget(btn, 1, 2, 1, 1)
        self._btnCalendarBuchung = btn

        self._tableView = TableViewExt(self)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(1)
        sizePolicy.setVerticalStretch(0)
        self._tableView.setSizePolicy(sizePolicy)
        self._gridLayout.addWidget(self._tableView, 1, 4, 9, 1)

        self._treeView = TreeView(self)
        self._treeView.setStyleSheet("gridline-color: rgb(94, 94, 94);")
        self._treeView.setObjectName("treeView")
        self._gridLayout.addWidget(self._treeView, 2, 0, 1, 4)

        self._kreditor = QtWidgets.QLineEdit(self)
        self._kreditor.setToolTip(
            "Kreditor: wie im Baum ausgewählt oder freie Eingabe")
        self._kreditor.setPlaceholderText("Kreditor")
        self._gridLayout.addWidget(self._kreditor, 3, 0, 1, 1)

        self._cboMasterobjekt = QtWidgets.QComboBox(self)
        self._cboMasterobjekt.setEditable(True)
        self._cboMasterobjekt.setToolTip(
            "Haus: wie im Baum ausgewählt oder freie Eingabe")
        self._cboMasterobjekt.setPlaceholderText("Haus")
        self._gridLayout.addWidget(self._cboMasterobjekt, 3, 1, 1, 1)

        self._cboMietobjekt = QtWidgets.QComboBox(self)
        self._cboMietobjekt.setEditable(True)
        self._cboMietobjekt.setToolTip(
            "Wohnung: wie im Baum ausgewählt oder freie Eingabe")
        self._cboMietobjekt.setPlaceholderText("Wohnung")
        self._gridLayout.addWidget(self._cboMietobjekt, 3, 2, 1, 1)

        self._rgnr = QtWidgets.QLineEdit(self)
        self._rgnr.setPlaceholderText("Rechnungsnummer")
        self._gridLayout.addWidget(self._rgnr, 4, 0, 1, 1)

        self._ddmmRechnung = QtWidgets.QLineEdit(self)
        self._ddmmRechnung.setToolTip(
            "Rechnungstag und -monat. Tag und Monat mit \',\' oder \'.\' trennen."
        )
        self._ddmmRechnung.setPlaceholderText("Rechnungstag u. -monat")
        self._gridLayout.addWidget(self._ddmmRechnung, 4, 1, 1, 1)

        #self._cboRechnungsjahr = QtWidgets.QComboBox( self )
        #self._gridLayout.addWidget( self._cboRechnungsjahr, 4, 2, 1, 1 )

        btn = QPushButton(self)
        btn.setMaximumSize(QSize(25, 25))
        btn.setIcon(self._calendarIcon)
        btn.clicked.connect(self._onShowRechnungCalendar)
        self._gridLayout.addWidget(btn, 4, 2, 1, 1)
        self._btnCalendarRechnung = btn

        cb = QCheckBox(self)
        cb.setText("umlegbar")
        self._gridLayout.addWidget(cb, 5, 0, 1, 1)
        self._cbUmlegbar = cb

        cb = QCheckBox(self)
        cb.setText("werterhaltend")
        self._gridLayout.addWidget(cb, 5, 1, 1, 1)
        self._cbWerterhaltend = cb

        self._betrag = QtWidgets.QLineEdit(self)
        font = QtGui.QFont()
        font.setPointSize(11)
        font.setBold(True)
        font.setWeight(75)
        self._betrag.setFont(font)
        self._betrag.setPlaceholderText("Betrag")
        self._betrag.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                  | Qt.AlignVCenter)
        self._betrag.setValidator(QDoubleValidator(0, 9999, 2, self))
        self._gridLayout.addWidget(self._betrag, 7, 0, 1, 1)

        self._bemerkung = QtWidgets.QTextEdit(self)
        self._bemerkung.setMaximumSize(QtCore.QSize(16777215, 50))
        self._bemerkung.setPlaceholderText(
            "Erläuterungen zur Rechnung oder Abgabe")
        self._gridLayout.addWidget(self._bemerkung, 8, 0, 1, 4)

        self._btnUebernehmen = QtWidgets.QPushButton(self)
        self._btnUebernehmen.setDefault(True)
        self._btnUebernehmen.setText("Übernehmen")
        self._gridLayout.addWidget(self._btnUebernehmen, 9, 0, 1, 1)

        self._btnReset = QtWidgets.QPushButton(self)
        self._btnReset.setText("Felder leeren")
        self._gridLayout.addWidget(self._btnReset, 9, 1, 1, 1)

        self._buchungsjahrChangedCallback = None
        #self._rechnungsjahrChangedCallback = None

        self._ddmmBuchung.setFocus()

    def onSave(self):
        pass

    def setBuchungsjahrChangedCallback(self, cbfnc):
        """
        Die callback-Funktion muss als Argument das neu eingestellte Jahr als integer akzeptieren
        :param cbfnc:
        :return:
        """
        self._buchungsjahrChangedCallback = cbfnc

    def _buchungsjahrChanged(self, newindex):
        if self._buchungsjahrChangedCallback:
            jahr = int(self._cboBuchungsjahr.currentText())
            self._buchungsjahrChangedCallback(jahr)

    def _onShowBuchungCalendar(self, event):
        cal = CalendarDialog(self)
        cal.setCallback(self.onBuchungsdatumSelected)
        cal.show()

    def onBuchungsdatumSelected(self, date: QDate):
        self._ddmmBuchung.setText(date.toString("yyyy-MM-dd"))

    def _onShowRechnungCalendar(self):
        cal = CalendarDialog(self)
        cal.setCallback(self.onRechnungsdatumSelected)
        cal.show()

    def onRechnungsdatumSelected(self, date: QDate):
        self._ddmmRechnung.setText(date.toString("yyyy-MM-dd"))

    def setJahre(self, jahre: List[int]):
        """
        setzt die Liste der auswählbaren Jahre für die Buchungsjahr- und die Rechnungsjahr-Combobox
        :param jahre:
        :return:
        """
        for jahr in jahre:
            self._cboBuchungsjahr.addItem(str(jahr))
            # self._cboRechnungsjahr.addItem( str( jahr ) )

    def setBuchungsjahr(self, jahr: int) -> None:
        """
        setzt das Jahr, das in der Buchungsjahr-Combobox anzuzeigen ist
        :param jahr:
        :return:
        """
        self._cboBuchungsjahr.setCurrentText(str(jahr))

    # def setRechnungsjahr( self, jahr:int ) -> None:
    #     """
    #     setzt das Jahr, das in der Rechnungsjahr-Combobox anzuzeigen ist
    #     :param jahr:
    #     :return:
    #     """
    #     self._cboRechnungsjahr.setCurrentText( str( jahr ) )

    def setServiceTreeModel(self, treemodel: ServiceTreeModel):
        self._treeView.setModel(treemodel)
Esempio n. 18
0
    def __init__(self, event_handler) :
        super(MainDialog, self).__init__(parent = None,
                                         id = wx.NewId(),
                                         size = (840, 570),
                                         title = APP_NAME)
        self.event_handler = event_handler
        self.event_handler.gui = self

        self.SetMinSize((840, 570))
        self.SetSize((840, 570))
        self.Centre()

        self._statusbar = self.CreateStatusBar(3)
        self._statusbar.SetStatusWidths([200, 500, 100])

        menuBar = wx.MenuBar()

        menu1 = wx.Menu()
        menu1.Append(self.ID_SETTING, u"设置a&ccess_key", u"Setting the access_id and secret_access_key")
        menu1.Append(self.ID_SYNC_UP, u"上行同步(&U)", u"Sync the file to OSS.")
        menu1.Append(self.ID_SYNC_DOWN, u"下行同步(&D)", u"Sync the file to local folder.")
        menu1.Append(wx.ID_ABOUT, u"打开同步目录(&P)", u"Open the sync folder on Explorer")
        menu1.AppendSeparator()
        menu1.Append(wx.ID_ABOUT, u"&About", u"About the Application")
        menu1.Append(wx.ID_CLOSE, u"&Exit", u"Exit this Application")
        menuBar.Append(menu1, u"操作(&O)")

        menu2 = wx.Menu()
        menu2.Append(self.ID_VIEW_SYNC, u'同步(&T)', u'同步OSS文件到指定的文件夹', wx.ITEM_RADIO)
        #menu2.Append(self.ID_VIEW_MGR, u'管理(&M)', u'对OSS文件进行管理', wx.ITEM_RADIO)
        menu2.Append(self.ID_VIEW_BROWSE, u'浏览(&L)', u'浏览文件', wx.ITEM_RADIO)
        menuBar.Append(menu2, u"视图(&V)")

        self.SetMenuBar(menuBar)
        self.Bind(wx.EVT_MENU, lambda evt: wx.Exit(), id = wx.ID_CLOSE)

        logo = wx.StaticBitmap(self, -1,
            wx.Bitmap(os.path.join(CURRENT_PATH, 'logo_aliyun.png'),
            wx.BITMAP_TYPE_PNG))

        self._splitter = wx.SplitterWindow(self,
            style = wx.SP_3D | wx.SP_BORDER | wx.SP_LIVE_UPDATE | wx.SP_3DSASH | wx.TAB_TRAVERSAL)
        self._splitter.SetMinimumPaneSize(210)

        # 左边bucket列表
        left = wx.Panel(self._splitter, -1 , style = wx.TAB_TRAVERSAL)
        tbNewBucket = wx.Button(left, self.ID_NEW_BUCKET, u"创建存储空间", (10, 10), (100, 24))
        self._tree = TreeView(left, (0, 40))
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(tbNewBucket, 0, wx.EXPAND | wx.ALL, 5)
        vbox.Add(self._tree, 1, wx.EXPAND | wx.ALL, 0)
        left.SetSizer(vbox)

        # 右边文件列表
        right = wx.Panel(self._splitter, -1 , style = wx.TAB_TRAVERSAL)
        self._bucket_info = BucketInfoPanel(right)
        self._list = FileList(right, wx.DefaultPosition, wx.DefaultSize)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self._bucket_info, 0, wx.EXPAND | wx.ALL, 0)
        vbox.Add(self._list, 1, wx.EXPAND | wx.ALL, 0)
        right.SetSizer(vbox)

        self._splitter.SplitVertically(left, right, 210)

        self.SetBackgroundColour('#FFFFFF')

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(logo, 0, wx.ALIGN_LEFT , 0)
        vbox.Add(self._splitter, 1, wx.EXPAND | wx.ALL, 0)
        self.SetSizer(vbox)
        self.SetAutoLayout(True)
        self.Fit()

        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_bucket_selected, self._tree)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_object_activated, self._list)


        self.Bind(wx.EVT_MENU, self.on_view_clicked, id = self.ID_VIEW_MGR)
        self.Bind(wx.EVT_MENU, self.on_view_clicked, id = self.ID_VIEW_BROWSE)
        self.Bind(wx.EVT_MENU, self.on_view_clicked, id = self.ID_VIEW_SYNC)
        self.Bind(wx.EVT_MENU, self.init, id = self.ID_SETTING)
        self.Bind(wx.EVT_MENU, self.on_delete_bucket, id = TreeView.ID_DELETE_BUCKET)
        self.Bind(wx.EVT_BUTTON, self.on_create_bucket, id = self.ID_NEW_BUCKET)
        self.Bind(wx.EVT_MENU, self.on_head_object, id = FileList.ID_HEAD_OBJECT)

        self.Bind(wx.EVT_BUTTON, self.event_handler.on_button_sync_down,
                  id = BucketInfoPanel.ID_SYNC_DOWN)
        self.Bind(wx.EVT_BUTTON, self.event_handler.on_button_sync_up,
                  id = BucketInfoPanel.ID_SYNC_UP)

        self.set_view(self.ID_VIEW_SYNC)
Esempio n. 19
0
class MainDialog(wx.Frame):
    ID_SETTING = wx.NewId()
    ID_SYNC_UP = wx.NewId()
    ID_SYNC_DOWN = wx.NewId()
    ID_VIEW_MGR = wx.NewId()
    ID_VIEW_BROWSE = wx.NewId()
    ID_VIEW_SYNC = wx.NewId()
    ID_NEW_BUCKET = wx.NewId()

    def __init__(self, event_handler) :
        super(MainDialog, self).__init__(parent = None,
                                         id = wx.NewId(),
                                         size = (840, 570),
                                         title = APP_NAME)
        self.event_handler = event_handler
        self.event_handler.gui = self

        self.SetMinSize((840, 570))
        self.SetSize((840, 570))
        self.Centre()

        self._statusbar = self.CreateStatusBar(3)
        self._statusbar.SetStatusWidths([200, 500, 100])

        menuBar = wx.MenuBar()

        menu1 = wx.Menu()
        menu1.Append(self.ID_SETTING, u"设置a&ccess_key", u"Setting the access_id and secret_access_key")
        menu1.Append(self.ID_SYNC_UP, u"上行同步(&U)", u"Sync the file to OSS.")
        menu1.Append(self.ID_SYNC_DOWN, u"下行同步(&D)", u"Sync the file to local folder.")
        menu1.Append(wx.ID_ABOUT, u"打开同步目录(&P)", u"Open the sync folder on Explorer")
        menu1.AppendSeparator()
        menu1.Append(wx.ID_ABOUT, u"&About", u"About the Application")
        menu1.Append(wx.ID_CLOSE, u"&Exit", u"Exit this Application")
        menuBar.Append(menu1, u"操作(&O)")

        menu2 = wx.Menu()
        menu2.Append(self.ID_VIEW_SYNC, u'同步(&T)', u'同步OSS文件到指定的文件夹', wx.ITEM_RADIO)
        #menu2.Append(self.ID_VIEW_MGR, u'管理(&M)', u'对OSS文件进行管理', wx.ITEM_RADIO)
        menu2.Append(self.ID_VIEW_BROWSE, u'浏览(&L)', u'浏览文件', wx.ITEM_RADIO)
        menuBar.Append(menu2, u"视图(&V)")

        self.SetMenuBar(menuBar)
        self.Bind(wx.EVT_MENU, lambda evt: wx.Exit(), id = wx.ID_CLOSE)

        logo = wx.StaticBitmap(self, -1,
            wx.Bitmap(os.path.join(CURRENT_PATH, 'logo_aliyun.png'),
            wx.BITMAP_TYPE_PNG))

        self._splitter = wx.SplitterWindow(self,
            style = wx.SP_3D | wx.SP_BORDER | wx.SP_LIVE_UPDATE | wx.SP_3DSASH | wx.TAB_TRAVERSAL)
        self._splitter.SetMinimumPaneSize(210)

        # 左边bucket列表
        left = wx.Panel(self._splitter, -1 , style = wx.TAB_TRAVERSAL)
        tbNewBucket = wx.Button(left, self.ID_NEW_BUCKET, u"创建存储空间", (10, 10), (100, 24))
        self._tree = TreeView(left, (0, 40))
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(tbNewBucket, 0, wx.EXPAND | wx.ALL, 5)
        vbox.Add(self._tree, 1, wx.EXPAND | wx.ALL, 0)
        left.SetSizer(vbox)

        # 右边文件列表
        right = wx.Panel(self._splitter, -1 , style = wx.TAB_TRAVERSAL)
        self._bucket_info = BucketInfoPanel(right)
        self._list = FileList(right, wx.DefaultPosition, wx.DefaultSize)
        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(self._bucket_info, 0, wx.EXPAND | wx.ALL, 0)
        vbox.Add(self._list, 1, wx.EXPAND | wx.ALL, 0)
        right.SetSizer(vbox)

        self._splitter.SplitVertically(left, right, 210)

        self.SetBackgroundColour('#FFFFFF')

        vbox = wx.BoxSizer(wx.VERTICAL)
        vbox.Add(logo, 0, wx.ALIGN_LEFT , 0)
        vbox.Add(self._splitter, 1, wx.EXPAND | wx.ALL, 0)
        self.SetSizer(vbox)
        self.SetAutoLayout(True)
        self.Fit()

        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_bucket_selected, self._tree)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_object_activated, self._list)


        self.Bind(wx.EVT_MENU, self.on_view_clicked, id = self.ID_VIEW_MGR)
        self.Bind(wx.EVT_MENU, self.on_view_clicked, id = self.ID_VIEW_BROWSE)
        self.Bind(wx.EVT_MENU, self.on_view_clicked, id = self.ID_VIEW_SYNC)
        self.Bind(wx.EVT_MENU, self.init, id = self.ID_SETTING)
        self.Bind(wx.EVT_MENU, self.on_delete_bucket, id = TreeView.ID_DELETE_BUCKET)
        self.Bind(wx.EVT_BUTTON, self.on_create_bucket, id = self.ID_NEW_BUCKET)
        self.Bind(wx.EVT_MENU, self.on_head_object, id = FileList.ID_HEAD_OBJECT)

        self.Bind(wx.EVT_BUTTON, self.event_handler.on_button_sync_down,
                  id = BucketInfoPanel.ID_SYNC_DOWN)
        self.Bind(wx.EVT_BUTTON, self.event_handler.on_button_sync_up,
                  id = BucketInfoPanel.ID_SYNC_UP)

        self.set_view(self.ID_VIEW_SYNC)

    def on_bucket_selected(self, event):
        current_bucket = self.get_bucket_txt(event.m_itemIndex)
        self.event_handler.select_bucket(current_bucket)

    def on_object_activated(self, event):
        path = self.get_list_obj_txt(event.m_itemIndex)
        self.event_handler.select_object(path)

    def on_head_object(self, event):
        path = self.get_list_obj_txt(self._list.GetFirstSelected())
        if '..' == path:
            logging.warning(".. object no head")
            return
        self.event_handler.head_object(path)

    def init(self, evt = None):
        self._statusbar.SetStatusText('右键可delete Bucket,head object', 0)
        class Obj(object):pass
        writer = Obj()

        writer.write = self.log_handler
        stream_handler = logging.StreamHandler(writer)
        #formatter = logging.Formatter("%(levelname)s - %(levelno)s - %(threadName)s - %(message)s")
        #stream_handler.setFormatter(formatter)
        logging.getLogger().addHandler(stream_handler)

        def call():
            key_entry = KeyEntryDialog(self, -1, "Input Access key", size = (750, 400),
                             style = wx.DEFAULT_DIALOG_STYLE)
            host, access_id, access_key = key_entry.get_Key(evt)
            if host and access_id and access_key:
                self.event_handler.on_init_gui(host, access_id, access_key)
        wx.CallAfter(call)

    def log_handler(self, msg):
        if not isinstance(msg, unicode):
            msg = msg.decode('utf8')
        self._statusbar.SetStatusText(msg, 1)

    def on_create_bucket(self, evt):
        dlg = NewBucketEntryDialog(self,)
        name, attr = dlg.get_Key()
        if name:
            self.event_handler.create_bucket(name, attr)
        dlg.Destroy()

    def on_delete_bucket(self, evt):
        index = self._tree.GetFirstSelected()
        if index < 0:
            return
        bucket_name = self.get_bucket_txt(index)
        self.event_handler.delete_bucket(bucket_name)

    def on_view_clicked(self, evt):
        id = evt.GetId()
        self.set_view(id)

    def set_view(self, id):
        if id == self.ID_VIEW_MGR:
            self._bucket_info.show_mgr_button(True)
            self._bucket_info.show_sync_button(False)
            self._list.set_view(True)
        elif id == self.ID_VIEW_SYNC:
            self._bucket_info.show_sync_button(True)
            self._bucket_info.show_mgr_button(False)
            self._list.set_view(False)
        elif id == self.ID_VIEW_BROWSE:
            self._bucket_info.show_mgr_button(False)
            self._bucket_info.show_sync_button(False)
            self._list.set_view(False)

        self._bucket_info.Layout()
        self._bucket_info.Refresh()

    def get_sync_path(self):
        return self._bucket_info.get_sync_path()

    def get_bucket_txt(self, index):
        return self._tree.GetItemText(index).encode('utf8')

    def get_list_obj_txt(self, index):
        return self._list.GetItemText(index).encode('utf8')

    def set_service(self, service):
        self._tree.DeleteAllItems()
        if service is None:return
        for bucket in service.get_buckets():
            self._tree.add_bucket(bucket)

    def set_bucket(self, bucket, perfix):
        # 选择bucket或双击文件夹,返回数据接口
        self._bucket_info.set_bucket(bucket.name)
        self._bucket_info.set_path(bucket.prefix)
        self._list.set_bucket(bucket, perfix)

    def set_bucket_acl(self, bucket):
        #TODO: 可能不一致
        self._bucket_info.set_grant(bucket.grant)

    def ask_continue(self, msg):
        # TODO:非main线程,xp下会崩溃
        return wx.ID_YES == wx.MessageDialog(self, msg.decode('utf8'),
            u"是否继续?", wx.YES_NO | wx.ICON_QUESTION).ShowModal()

    def show_msg(self, msg):
        # TODO:非main线程,xp下会崩溃
        return wx.MessageDialog(self, msg.decode('utf8'),
            self.GetTitle(), wx.OK | wx.ICON_INFORMATION).ShowModal()

    def show_save_dialog(self, filename):
        '''return abs unicode path'''
        dlg = wx.FileDialog(
            self, message = "Save file as ...", defaultDir = os.getcwd(),
            defaultFile = filename, style = wx.SAVE
            )

        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            if os.path.exists(path) and self.ask_continue("文件已存在,将覆盖已有文件,是否断续?"):
                return path
        return None

    def head_object(self, key, object_head):
        cl = lambda : HeadDialog(self, -1, key.decode('utf8'), object_head.headers).ShowModal()
        wx.CallAfter(cl)
Esempio n. 20
0
    def __init__(self,
                 items,
                 min_width=80,
                 max_width=None,
                 fixed_width=None,
                 min_height=100,
                 max_height=None,
                 shadow_visible=True,
                 shape_frame_function=None,
                 expose_frame_function=None,
                 x_align=ALIGN_START,
                 y_align=ALIGN_START,
                 align_size=0,
                 grab_window=None,
                 window_type=gtk.WINDOW_TOPLEVEL,
                 ):
        '''
        Initialize Poplist class.

        @param items: The item list to initialize.
        @param min_width: The minimum width of poplist, default is 80 pixels.
        @param max_width: The maximum width of poplist, default is None.
        @param fixed_width: The fixed width of poplist, default is None.
        @param min_height: The minimum height of poplist, default is 100 pixels.
        @param max_height: The maximum height of poplist, default is None.
        @param shadow_visible: Set it with True to make shadow visible.
        @param shape_frame_function: The function to shape frame.
        @param expose_frame_function: The function to draw frame.
        @param x_align: The horizontal alignment value, default is ALIGN_START.
        @param y_align: The vertical alignment value, default is ALIGN_START.
        @param align_size: The alignment size, default is 0.
        @param grab_window: Window to handle grab event, default is None that use poplist_grab_window.
        @param window_type: The type of window, default is gtk.WINDOW_TOPLEVEL.
        '''
        # Init.
        Window.__init__(self,
                        shadow_visible=shadow_visible,
                        window_type=window_type,
                        shape_frame_function=shape_frame_function,
                        expose_frame_function=expose_frame_function)
        self.max_height = max_height
        self.min_height = min_height
        self.x_align = x_align
        self.y_align = y_align
        self.min_width = min_width
        self.max_width = max_width
        self.fixed_width = fixed_width
        self.align_size = align_size
        self.window_width = self.window_height = 0
        self.treeview_align = gtk.Alignment()
        self.treeview_align.set(1, 1, 1, 1)
        self.treeview_align.set_padding(self.align_size, self.align_size, self.align_size, self.align_size)
        self.treeview = TreeView(items,
                                 enable_highlight=False,
                                 enable_multiple_select=False,
                                 enable_drag_drop=False)

        # Connect widgets.
        self.treeview_align.add(self.treeview)
        self.window_frame.pack_start(self.treeview_align, True, True)

        self.connect("realize", self.realize_poplist)

        # Wrap self in poup grab window.
        if grab_window:
            wrap_grab_window(grab_window, self)
        else:
            wrap_grab_window(poplist_grab_window, self)
Esempio n. 21
0
class Poplist(Window):
    '''
    Poplist class.

    @undocumented: hide_self
    @undocumented: auto_set_size
    @undocumented: realize_poplist
    '''

    def __init__(self,
                 items,
                 min_width=80,
                 max_width=None,
                 fixed_width=None,
                 min_height=100,
                 max_height=None,
                 shadow_visible=True,
                 shape_frame_function=None,
                 expose_frame_function=None,
                 x_align=ALIGN_START,
                 y_align=ALIGN_START,
                 align_size=0,
                 grab_window=None,
                 window_type=gtk.WINDOW_TOPLEVEL,
                 ):
        '''
        Initialize Poplist class.

        @param items: The item list to initialize.
        @param min_width: The minimum width of poplist, default is 80 pixels.
        @param max_width: The maximum width of poplist, default is None.
        @param fixed_width: The fixed width of poplist, default is None.
        @param min_height: The minimum height of poplist, default is 100 pixels.
        @param max_height: The maximum height of poplist, default is None.
        @param shadow_visible: Set it with True to make shadow visible.
        @param shape_frame_function: The function to shape frame.
        @param expose_frame_function: The function to draw frame.
        @param x_align: The horizontal alignment value, default is ALIGN_START.
        @param y_align: The vertical alignment value, default is ALIGN_START.
        @param align_size: The alignment size, default is 0.
        @param grab_window: Window to handle grab event, default is None that use poplist_grab_window.
        @param window_type: The type of window, default is gtk.WINDOW_TOPLEVEL.
        '''
        # Init.
        Window.__init__(self,
                        shadow_visible=shadow_visible,
                        window_type=window_type,
                        shape_frame_function=shape_frame_function,
                        expose_frame_function=expose_frame_function)
        self.max_height = max_height
        self.min_height = min_height
        self.x_align = x_align
        self.y_align = y_align
        self.min_width = min_width
        self.max_width = max_width
        self.fixed_width = fixed_width
        self.align_size = align_size
        self.window_width = self.window_height = 0
        self.treeview_align = gtk.Alignment()
        self.treeview_align.set(1, 1, 1, 1)
        self.treeview_align.set_padding(self.align_size, self.align_size, self.align_size, self.align_size)
        self.treeview = TreeView(items,
                                 enable_highlight=False,
                                 enable_multiple_select=False,
                                 enable_drag_drop=False)

        # Connect widgets.
        self.treeview_align.add(self.treeview)
        self.window_frame.pack_start(self.treeview_align, True, True)

        self.connect("realize", self.realize_poplist)

        # Wrap self in poup grab window.
        if grab_window:
            wrap_grab_window(grab_window, self)
        else:
            wrap_grab_window(poplist_grab_window, self)

    def get_scrolledwindow(self):
        '''
        Get scrolled window.

        @return: Return the scrolled window.
        '''
        return self.treeview.scrolled_window

    @property
    def items(self):
        return self.treeview.get_items()

    def get_adjust_width(self):
        '''
        Get width of adjustment.

        @return: Return the width of adjustment.
        '''
        if self.fixed_width:
            return self.fixed_width
        if len(self.items) > 0:
            adjust_width = max([item.get_width() for item in self.items])
        else:
            adjust_width = self.min_width

        if self.max_width:
            return min(self.max_width, adjust_width)
        return adjust_width

    def get_adjust_height(self):
        '''
        Get height of adjustment.

        @return: Return the height of adjustment.
        '''
        if len(self.items) > 0:
            adjust_height = sum([item.get_height() for item in self.items])
        else:
            adjust_height = 0

        if self.max_height != None:
            adjust_height = min(adjust_height, self.max_height)

        if adjust_height <= 0:
            adjust_height = self.min_height
        return adjust_height

    def get_adjust_size(self):
        '''
        Get size of adjustment.

        @return: Return the size of adjustment.
        '''
        return (self.get_adjust_width(), self.get_adjust_height())

    def hide_self(self):
        poplist_grab_window.popup_grab_window_focus_out()

    def auto_set_size(self):
        self.set_size(*self.get_adjust_size())

    def set_size(self, width, height):
        '''
        Set size.

        @param width: The width.
        @param height: The height.
        '''
        (shadow_padding_x, shadow_padding_y) = self.get_shadow_size()
        self.window_height = height + self.align_size * 2 + shadow_padding_x * 2 + 1
        self.window_width = width + shadow_padding_x * 2 + 1
        if self.get_realized():
            self.unrealize()

    def realize_poplist(self, widget):
        if self.window_height <= 0 or self.window_height <=0:
            self.auto_set_size()

        self.set_default_size(self.window_width, self.window_height)
        self.set_geometry_hints(
            None,
            self.window_width,       # minimum width
            self.window_height,       # minimum height
            self.window_width,
            self.window_height,
            -1, -1, -1, -1, -1, -1
            )

    def show(self, (expect_x, expect_y), (offset_x, offset_y)=(0, 0)):
Esempio n. 22
0
    def __init__(self):
        QWidget.__init__(self)
        self._calendarIcon = QIcon("../images/calendar25x25.png")
        self.setWindowTitle(
            "Sonstige Ausgaben: Rechnungen, Abgaben, Gebühren etc.")
        self._gridLayout = QtWidgets.QGridLayout(self)
        self._gridLayout.setObjectName("gridLayout")

        #### save button
        btn = QPushButton()
        btn.clicked.connect(self.onSave)
        btn.setFlat(True)
        btn.setEnabled(False)
        btn.setToolTip("Änderungen dieser View speichern")
        icon = QIcon("../images/save_30.png")
        btn.setIcon(icon)
        size = QSize(30, 30)
        btn.setFixedSize(size)
        iconsize = QSize(30, 30)
        btn.setIconSize(iconsize)
        self._gridLayout.addWidget(btn, 0, 0, 1, 1)
        self._btnSave = btn

        self._cboBuchungsjahr = QtWidgets.QComboBox(self)
        font = QtGui.QFont()
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self._cboBuchungsjahr.setFont(font)
        self._cboBuchungsjahr.setToolTip(
            "Das hier eingestellte Jahr bestimmt die Rechnungen, die in der Tabelle angezeigt werden."
        )
        self._cboBuchungsjahr.currentIndexChanged.connect(
            self._buchungsjahrChanged)
        self._gridLayout.addWidget(self._cboBuchungsjahr, 1, 0, 1, 1)

        self._ddmmBuchung = QtWidgets.QLineEdit(self)
        self._ddmmBuchung.setToolTip(
            "Buchungstag und -monat. Tag und Monat mit \',\' oder \'.\' trennen."
        )
        self._ddmmBuchung.setPlaceholderText("Buchungstag u. -monat")
        self._gridLayout.addWidget(self._ddmmBuchung, 1, 1, 1, 1)

        btn = QPushButton(self)
        btn.setMaximumSize(QSize(25, 25))
        btn.setIcon(self._calendarIcon)
        btn.clicked.connect(self._onShowBuchungCalendar)
        self._gridLayout.addWidget(btn, 1, 2, 1, 1)
        self._btnCalendarBuchung = btn

        self._tableView = TableViewExt(self)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(1)
        sizePolicy.setVerticalStretch(0)
        self._tableView.setSizePolicy(sizePolicy)
        self._gridLayout.addWidget(self._tableView, 1, 4, 9, 1)

        self._treeView = TreeView(self)
        self._treeView.setStyleSheet("gridline-color: rgb(94, 94, 94);")
        self._treeView.setObjectName("treeView")
        self._gridLayout.addWidget(self._treeView, 2, 0, 1, 4)

        self._kreditor = QtWidgets.QLineEdit(self)
        self._kreditor.setToolTip(
            "Kreditor: wie im Baum ausgewählt oder freie Eingabe")
        self._kreditor.setPlaceholderText("Kreditor")
        self._gridLayout.addWidget(self._kreditor, 3, 0, 1, 1)

        self._cboMasterobjekt = QtWidgets.QComboBox(self)
        self._cboMasterobjekt.setEditable(True)
        self._cboMasterobjekt.setToolTip(
            "Haus: wie im Baum ausgewählt oder freie Eingabe")
        self._cboMasterobjekt.setPlaceholderText("Haus")
        self._gridLayout.addWidget(self._cboMasterobjekt, 3, 1, 1, 1)

        self._cboMietobjekt = QtWidgets.QComboBox(self)
        self._cboMietobjekt.setEditable(True)
        self._cboMietobjekt.setToolTip(
            "Wohnung: wie im Baum ausgewählt oder freie Eingabe")
        self._cboMietobjekt.setPlaceholderText("Wohnung")
        self._gridLayout.addWidget(self._cboMietobjekt, 3, 2, 1, 1)

        self._rgnr = QtWidgets.QLineEdit(self)
        self._rgnr.setPlaceholderText("Rechnungsnummer")
        self._gridLayout.addWidget(self._rgnr, 4, 0, 1, 1)

        self._ddmmRechnung = QtWidgets.QLineEdit(self)
        self._ddmmRechnung.setToolTip(
            "Rechnungstag und -monat. Tag und Monat mit \',\' oder \'.\' trennen."
        )
        self._ddmmRechnung.setPlaceholderText("Rechnungstag u. -monat")
        self._gridLayout.addWidget(self._ddmmRechnung, 4, 1, 1, 1)

        #self._cboRechnungsjahr = QtWidgets.QComboBox( self )
        #self._gridLayout.addWidget( self._cboRechnungsjahr, 4, 2, 1, 1 )

        btn = QPushButton(self)
        btn.setMaximumSize(QSize(25, 25))
        btn.setIcon(self._calendarIcon)
        btn.clicked.connect(self._onShowRechnungCalendar)
        self._gridLayout.addWidget(btn, 4, 2, 1, 1)
        self._btnCalendarRechnung = btn

        cb = QCheckBox(self)
        cb.setText("umlegbar")
        self._gridLayout.addWidget(cb, 5, 0, 1, 1)
        self._cbUmlegbar = cb

        cb = QCheckBox(self)
        cb.setText("werterhaltend")
        self._gridLayout.addWidget(cb, 5, 1, 1, 1)
        self._cbWerterhaltend = cb

        self._betrag = QtWidgets.QLineEdit(self)
        font = QtGui.QFont()
        font.setPointSize(11)
        font.setBold(True)
        font.setWeight(75)
        self._betrag.setFont(font)
        self._betrag.setPlaceholderText("Betrag")
        self._betrag.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                  | Qt.AlignVCenter)
        self._betrag.setValidator(QDoubleValidator(0, 9999, 2, self))
        self._gridLayout.addWidget(self._betrag, 7, 0, 1, 1)

        self._bemerkung = QtWidgets.QTextEdit(self)
        self._bemerkung.setMaximumSize(QtCore.QSize(16777215, 50))
        self._bemerkung.setPlaceholderText(
            "Erläuterungen zur Rechnung oder Abgabe")
        self._gridLayout.addWidget(self._bemerkung, 8, 0, 1, 4)

        self._btnUebernehmen = QtWidgets.QPushButton(self)
        self._btnUebernehmen.setDefault(True)
        self._btnUebernehmen.setText("Übernehmen")
        self._gridLayout.addWidget(self._btnUebernehmen, 9, 0, 1, 1)

        self._btnReset = QtWidgets.QPushButton(self)
        self._btnReset.setText("Felder leeren")
        self._gridLayout.addWidget(self._btnReset, 9, 1, 1, 1)

        self._buchungsjahrChangedCallback = None
        #self._rechnungsjahrChangedCallback = None

        self._ddmmBuchung.setFocus()
Esempio n. 23
0
class PreferenceDialog(DialogBox):
    '''
    PreferenceDialog class.
    
    @undocumented: button_press_preference_item
    @undocumented: set_item_widget
    @undocumented: draw_treeview_mask
    '''
	
    def __init__(self,
                 default_width=575,
                 default_height=495,
                 ):
        '''
        Initialize PreferenceDialog class.
        
        @param default_width: The default width, default is 575 pixels.
        @param default_height: The default height, default is 495 pixels.
        '''
        DialogBox.__init__(
            self,
            _("Preferences"), 
            default_width,
            default_height,
            mask_type=DIALOG_MASK_MULTIPLE_PAGE,
            close_callback=self.hide_dialog,
            )
        self.set_position(gtk.WIN_POS_CENTER)
        
        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())
        
        # Category bar
        category_bar_width = 132
        self.category_bar = TreeView(
            enable_drag_drop=False, 
            enable_multiple_select=False,
            )
        self.category_bar.set_expand_column(1)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.category_bar.set_size_request(category_bar_width, 516)
        self.category_bar.connect("button-press-item", self.button_press_preference_item)
        
        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(category_bar_width, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)
        
        category_bar_align = gtk.Alignment()
        category_bar_align.set(0, 0, 1, 1,)
        category_bar_align.set_padding(0, 1, 0, 0)
        category_bar_align.add(self.category_bar)
        category_box.pack_start(category_bar_align, True, True)
        
        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 0, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)
        
        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])        
        
    def hide_dialog(self):
        self.hide_all()
        
        return True
        
    def button_press_preference_item(self, treeview, item, column_index, offset_x, offset_y):
        if self.set_item_widget(item):
            self.show_all()
            
    def set_item_widget(self, item):
        if isinstance(item, PreferenceItem):
            container_remove_all(self.right_box)
            self.right_box.pack_start(item.item_widget)
            self.category_bar.select_items([item])
            
            return True
        else:
            return False
            
    def draw_treeview_mask(self, cr, x, y, width, height):
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
        cr.rectangle(x, y, width, height)
        cr.fill()
        
    def set_preference_items(self, preference_items):
        '''
        Set preference items.
        
        @param preference_items: The list of preference item, item format is:
         - (item_name, item_widget)
         - Item list support recursively add.
        '''
        items = []
        for (item_name, item_content) in preference_items:
            if isinstance(item_content, gtk.Widget):
                items.append(PreferenceItem(item_name, item_content))
            elif isinstance(item_content, list):
                expand_item = ExpandPreferenceItem(item_name)
                items.append(expand_item)
                
                child_items = []
                for (child_item_name, child_item_content) in item_content:
                    child_items.append(PreferenceItem(child_item_name, child_item_content))
                    
                expand_item.add_items(child_items)
            
        self.category_bar.add_items(items)
        
        for item in items:
            if self.set_item_widget(item):
                break
Esempio n. 24
0
    def __init__(self,
                 default_width=575,
                 default_height=495,
                 ):
        '''
        Initialize PreferenceDialog class.

        @param default_width: The default width, default is 575 pixels.
        @param default_height: The default height, default is 495 pixels.
        '''
        DialogBox.__init__(
            self,
            _("Preferences"),
            default_width,
            default_height,
            mask_type=DIALOG_MASK_MULTIPLE_PAGE,
            close_callback=self.hide_dialog,
            )
        self.set_position(gtk.WIN_POS_CENTER)

        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())

        # Category bar
        category_bar_width = 132
        self.category_bar = TreeView(
            enable_drag_drop=False,
            enable_multiple_select=False,
            )
        self.category_bar.set_expand_column(1)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.category_bar.set_size_request(category_bar_width, 516)
        self.category_bar.connect("button-press-item", self.button_press_preference_item)

        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(category_bar_width, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)

        category_bar_align = gtk.Alignment()
        category_bar_align.set(0, 0, 1, 1,)
        category_bar_align.set_padding(0, 1, 0, 0)
        category_bar_align.add(self.category_bar)
        category_box.pack_start(category_bar_align, True, True)

        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 0, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)

        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])
Esempio n. 25
0
    def __init__(
        self,
        items,
        min_width=80,
        max_width=None,
        fixed_width=None,
        min_height=100,
        max_height=None,
        shadow_visible=True,
        shape_frame_function=None,
        expose_frame_function=None,
        x_align=ALIGN_START,
        y_align=ALIGN_START,
        align_size=0,
        grab_window=None,
        window_type=gtk.WINDOW_TOPLEVEL,
    ):
        '''
        Initialize Poplist class.

        @param items: The item list to initialize.
        @param min_width: The minimum width of poplist, default is 80 pixels.
        @param max_width: The maximum width of poplist, default is None.
        @param fixed_width: The fixed width of poplist, default is None.
        @param min_height: The minimum height of poplist, default is 100 pixels.
        @param max_height: The maximum height of poplist, default is None.
        @param shadow_visible: Set it with True to make shadow visible.
        @param shape_frame_function: The function to shape frame.
        @param expose_frame_function: The function to draw frame.
        @param x_align: The horizontal alignment value, default is ALIGN_START.
        @param y_align: The vertical alignment value, default is ALIGN_START.
        @param align_size: The alignment size, default is 0.
        @param grab_window: Window to handle grab event, default is None that use poplist_grab_window.
        @param window_type: The type of window, default is gtk.WINDOW_TOPLEVEL.
        '''
        # Init.
        Window.__init__(self,
                        shadow_visible=shadow_visible,
                        window_type=window_type,
                        shape_frame_function=shape_frame_function,
                        expose_frame_function=expose_frame_function)
        self.max_height = max_height
        self.min_height = min_height
        self.x_align = x_align
        self.y_align = y_align
        self.min_width = min_width
        self.max_width = max_width
        self.fixed_width = fixed_width
        self.align_size = align_size
        self.window_width = self.window_height = 0
        self.treeview_align = gtk.Alignment()
        self.treeview_align.set(1, 1, 1, 1)
        self.treeview_align.set_padding(self.align_size, self.align_size,
                                        self.align_size, self.align_size)
        self.treeview = TreeView(items,
                                 enable_highlight=False,
                                 enable_multiple_select=False,
                                 enable_drag_drop=False)

        # Connect widgets.
        self.treeview_align.add(self.treeview)
        self.window_frame.pack_start(self.treeview_align, True, True)

        self.connect("realize", self.realize_poplist)

        # Wrap self in poup grab window.
        if grab_window:
            wrap_grab_window(grab_window, self)
        else:
            wrap_grab_window(poplist_grab_window, self)
Esempio n. 26
0
class Poplist(Window):
    '''
    Poplist class.

    @undocumented: hide_self
    @undocumented: auto_set_size
    @undocumented: realize_poplist
    '''
    def __init__(
        self,
        items,
        min_width=80,
        max_width=None,
        fixed_width=None,
        min_height=100,
        max_height=None,
        shadow_visible=True,
        shape_frame_function=None,
        expose_frame_function=None,
        x_align=ALIGN_START,
        y_align=ALIGN_START,
        align_size=0,
        grab_window=None,
        window_type=gtk.WINDOW_TOPLEVEL,
    ):
        '''
        Initialize Poplist class.

        @param items: The item list to initialize.
        @param min_width: The minimum width of poplist, default is 80 pixels.
        @param max_width: The maximum width of poplist, default is None.
        @param fixed_width: The fixed width of poplist, default is None.
        @param min_height: The minimum height of poplist, default is 100 pixels.
        @param max_height: The maximum height of poplist, default is None.
        @param shadow_visible: Set it with True to make shadow visible.
        @param shape_frame_function: The function to shape frame.
        @param expose_frame_function: The function to draw frame.
        @param x_align: The horizontal alignment value, default is ALIGN_START.
        @param y_align: The vertical alignment value, default is ALIGN_START.
        @param align_size: The alignment size, default is 0.
        @param grab_window: Window to handle grab event, default is None that use poplist_grab_window.
        @param window_type: The type of window, default is gtk.WINDOW_TOPLEVEL.
        '''
        # Init.
        Window.__init__(self,
                        shadow_visible=shadow_visible,
                        window_type=window_type,
                        shape_frame_function=shape_frame_function,
                        expose_frame_function=expose_frame_function)
        self.max_height = max_height
        self.min_height = min_height
        self.x_align = x_align
        self.y_align = y_align
        self.min_width = min_width
        self.max_width = max_width
        self.fixed_width = fixed_width
        self.align_size = align_size
        self.window_width = self.window_height = 0
        self.treeview_align = gtk.Alignment()
        self.treeview_align.set(1, 1, 1, 1)
        self.treeview_align.set_padding(self.align_size, self.align_size,
                                        self.align_size, self.align_size)
        self.treeview = TreeView(items,
                                 enable_highlight=False,
                                 enable_multiple_select=False,
                                 enable_drag_drop=False)

        # Connect widgets.
        self.treeview_align.add(self.treeview)
        self.window_frame.pack_start(self.treeview_align, True, True)

        self.connect("realize", self.realize_poplist)

        # Wrap self in poup grab window.
        if grab_window:
            wrap_grab_window(grab_window, self)
        else:
            wrap_grab_window(poplist_grab_window, self)

    def get_scrolledwindow(self):
        '''
        Get scrolled window.

        @return: Return the scrolled window.
        '''
        return self.treeview.scrolled_window

    @property
    def items(self):
        return self.treeview.get_items()

    def get_adjust_width(self):
        '''
        Get width of adjustment.

        @return: Return the width of adjustment.
        '''
        if self.fixed_width:
            return self.fixed_width
        if len(self.items) > 0:
            adjust_width = max([item.get_width() for item in self.items])
        else:
            adjust_width = self.min_width

        if self.max_width:
            return min(self.max_width, adjust_width)
        return adjust_width

    def get_adjust_height(self):
        '''
        Get height of adjustment.

        @return: Return the height of adjustment.
        '''
        if len(self.items) > 0:
            adjust_height = sum([item.get_height() for item in self.items])
        else:
            adjust_height = 0

        if self.max_height != None:
            adjust_height = min(adjust_height, self.max_height)

        if adjust_height <= 0:
            adjust_height = self.min_height
        return adjust_height

    def get_adjust_size(self):
        '''
        Get size of adjustment.

        @return: Return the size of adjustment.
        '''
        return (self.get_adjust_width(), self.get_adjust_height())

    def hide_self(self):
        poplist_grab_window.popup_grab_window_focus_out()

    def auto_set_size(self):
        self.set_size(*self.get_adjust_size())

    def set_size(self, width, height):
        '''
        Set size.

        @param width: The width.
        @param height: The height.
        '''
        (shadow_padding_x, shadow_padding_y) = self.get_shadow_size()
        self.window_height = height + self.align_size * 2 + shadow_padding_x * 2 + 1
        self.window_width = width + shadow_padding_x * 2 + 1
        if self.get_realized():
            self.unrealize()

    def realize_poplist(self, widget):
        if self.window_height <= 0 or self.window_height <= 0:
            self.auto_set_size()

        self.set_default_size(self.window_width, self.window_height)
        self.set_geometry_hints(
            None,
            self.window_width,  # minimum width
            self.window_height,  # minimum height
            self.window_width,
            self.window_height,
            -1,
            -1,
            -1,
            -1,
            -1,
            -1)

    def show(self, (expect_x, expect_y), (offset_x, offset_y)=(0, 0)):
Esempio n. 27
0
import sys
from PyQt5.QtWidgets import QApplication
from model import TreeModel
from treeview import TreeView
import config

app = QApplication(sys.argv)

model = TreeModel()
view = TreeView(model)
view.setGeometry(300, 200, 500, 500)
view.setWindowTitle(config.windowTitle)
view.show()
app.exec_()
Esempio n. 28
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        widget = QWidget()
        self.setCentralWidget(widget)

        fileMenu = self.menuBar().addMenu("File")
        newRepository = fileMenu.addAction("New Repository")
        openRepository = fileMenu.addAction("Open Repository")
        rollbackRepository = fileMenu.addAction("Discard last commit")

        newRepository.triggered.connect(self.create_new_repository)
        openRepository.triggered.connect(self.open_repository)
        rollbackRepository.triggered.connect(self.discard_last_commit)

        self.button = QPushButton("hello there")

        container = QVBoxLayout()
        menuContainer = QHBoxLayout()
        topContainer = QHBoxLayout()
        bottomContainer = QHBoxLayout()
        self.console = Console(bottomContainer)
        self.tree = TreeView(topContainer)

        container.addLayout(menuContainer, 0)
        container.addLayout(topContainer, 5)
        container.addLayout(bottomContainer, 3)
        self.tabs = TabView(topContainer)

        widget.setLayout(container)

    def set_favorites(self, favoritesRoot):
        self.tabs.clear()
        self.tree.set_favorites(favoritesRoot)

    def get_logger(self):
        return self.console

    def create_new_repository(self):
        directory = QFileDialog.getExistingDirectory()
        new_repository(directory)
        self.currentRepository = directory

    def open_repository(self):
        directory = QFileDialog.getExistingDirectory()
        open_repository(directory)
        self.currentRepository = directory

    def discard_last_commit(self):
        if (
            QMessageBox.warning(
                self,
                "Discard last commit?",
                "this will do a hard reset to the previous commit, so the current one will be lost",
                QMessageBox.Yes,
                QMessageBox.No,
            )
            == QMessageBox.Yes
        ):
            rollback()
Esempio n. 29
0
class PreferenceDialog(DialogBox):
    '''
    PreferenceDialog class.

    @undocumented: button_press_preference_item
    @undocumented: set_item_widget
    @undocumented: draw_treeview_mask
    '''

    def __init__(self,
                 default_width=575,
                 default_height=495,
                 ):
        '''
        Initialize PreferenceDialog class.

        @param default_width: The default width, default is 575 pixels.
        @param default_height: The default height, default is 495 pixels.
        '''
        DialogBox.__init__(
            self,
            _("Preferences"),
            default_width,
            default_height,
            mask_type=DIALOG_MASK_MULTIPLE_PAGE,
            close_callback=self.hide_dialog,
            )
        self.set_position(gtk.WIN_POS_CENTER)

        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())

        # Category bar
        category_bar_width = 132
        self.category_bar = TreeView(
            enable_drag_drop=False,
            enable_multiple_select=False,
            )
        self.category_bar.set_expand_column(1)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.category_bar.set_size_request(category_bar_width, 516)
        self.category_bar.connect("button-press-item", self.button_press_preference_item)

        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(category_bar_width, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)

        category_bar_align = gtk.Alignment()
        category_bar_align.set(0, 0, 1, 1,)
        category_bar_align.set_padding(0, 1, 0, 0)
        category_bar_align.add(self.category_bar)
        category_box.pack_start(category_bar_align, True, True)

        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 0, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)

        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])

    def hide_dialog(self):
        self.hide_all()

        return True

    def button_press_preference_item(self, treeview, item, column_index, offset_x, offset_y):
        if self.set_item_widget(item):
            self.show_all()

    def set_item_widget(self, item):
        if isinstance(item, PreferenceItem):
            container_remove_all(self.right_box)
            self.right_box.pack_start(item.item_widget)
            self.category_bar.select_items([item])

            return True
        else:
            return False

    def draw_treeview_mask(self, cr, x, y, width, height):
        cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9)))
        cr.rectangle(x, y, width, height)
        cr.fill()

    def set_preference_items(self, preference_items):
        '''
        Set preference items.

        @param preference_items: The list of preference item, item format is:
         - (item_name, item_widget)
         - Item list support recursively add.
        '''
        items = []
        for (item_name, item_content) in preference_items:
            if isinstance(item_content, gtk.Widget):
                items.append(PreferenceItem(item_name, item_content))
            elif isinstance(item_content, list):
                expand_item = ExpandPreferenceItem(item_name)
                items.append(expand_item)

                child_items = []
                for (child_item_name, child_item_content) in item_content:
                    child_items.append(PreferenceItem(child_item_name, child_item_content))

                expand_item.add_items(child_items)

        self.category_bar.add_items(items)

        for item in items:
            if self.set_item_widget(item):
                break
Esempio n. 30
0
    def __init__(self,
                 default_width=575,
                 default_height=495,
                 ):
        '''
        Initialize PreferenceDialog class.
        
        @param default_width: The default width, default is 575 pixels.
        @param default_height: The default height, default is 495 pixels.
        '''
        DialogBox.__init__(
            self,
            _("Preferences"), 
            default_width,
            default_height,
            mask_type=DIALOG_MASK_MULTIPLE_PAGE,
            close_callback=self.hide_dialog,
            )
        self.set_position(gtk.WIN_POS_CENTER)
        
        self.main_box = gtk.VBox()
        close_button = Button(_("Close"))
        close_button.connect("clicked", lambda w: self.hide_all())
        
        # Category bar
        category_bar_width = 132
        self.category_bar = TreeView(
            enable_drag_drop=False, 
            enable_multiple_select=False,
            )
        self.category_bar.set_expand_column(1)
        self.category_bar.draw_mask = self.draw_treeview_mask
        self.category_bar.set_size_request(category_bar_width, 516)
        self.category_bar.connect("button-press-item", self.button_press_preference_item)
        
        category_box = gtk.VBox()
        background_box = BackgroundBox()
        background_box.set_size_request(category_bar_width, 11)
        background_box.draw_mask = self.draw_treeview_mask
        category_box.pack_start(background_box, False, False)
        
        category_bar_align = gtk.Alignment()
        category_bar_align.set(0, 0, 1, 1,)
        category_bar_align.set_padding(0, 1, 0, 0)
        category_bar_align.add(self.category_bar)
        category_box.pack_start(category_bar_align, True, True)
        
        # Pack widget.
        left_box = gtk.VBox()
        self.right_box = gtk.VBox()
        left_box.add(category_box)
        right_align = gtk.Alignment()
        right_align.set_padding(0, 0, 0, 0)
        right_align.add(self.right_box)

        body_box = gtk.HBox()
        body_box.pack_start(left_box, False, False)
        body_box.pack_start(right_align, False, False)
        self.main_box.add(body_box)
        
        # DialogBox code.
        self.body_box.pack_start(self.main_box, True, True)
        self.right_button_box.set_buttons([close_button])