Пример #1
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)
Пример #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)
Пример #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()
Пример #4
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
Пример #5
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)
Пример #6
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
Пример #7
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))
Пример #8
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)
Пример #9
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()
Пример #10
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)
Пример #11
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)
Пример #12
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_()
Пример #13
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])
Пример #14
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()